-
Notifications
You must be signed in to change notification settings - Fork 2
/
user_xp_chimera_re_create.py
73 lines (56 loc) · 2.02 KB
/
user_xp_chimera_re_create.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
import os
os.environ.setdefault("DJANGO_SETTINGS_MODULE",
"ActiveTeachingServer.settings")
from django.core.wsgi import get_wsgi_application
application = get_wsgi_application()
import datetime
from pytz import timezone
from user.authentication import sign_up
from user.models.user import User
def main():
while True:
try:
previous_email = input("previous_name:")
previous_email = f"{previous_email}@aalto.fi"
previous_u = User.objects.get(email=previous_email)
break
except Exception as e:
print(f"encountered error '{e}', please retry!")
while True:
try:
new_time = input("new time (YYYY-MM-DD HH:MM):")
new_time = timezone("Europe/Helsinki") \
.localize(datetime.datetime.fromisoformat(new_time)) \
.astimezone(timezone('UTC'))
break
except Exception as e:
print(f"encountered error '{e}', please retry!")
password = input("password:")
print("Re creating user...")
condition = previous_u.condition
experiment_name = previous_u.experiment_name
is_item_specific = previous_u.psychologist_set.first().is_item_specific
begin_with_active = \
previous_u.session_set.order_by("available_time").first()\
.teaching_engine.leitner is None
intermediary_email = previous_email.replace("aalto", "replace")
user = sign_up(
email=intermediary_email,
password=password,
condition=condition,
first_session=new_time,
begin_with_active=begin_with_active,
is_item_specific=is_item_specific,
previous_email=previous_email,
experiment_name=experiment_name)
if user is not None:
print("Success!")
else:
raise ValueError("Error! User already exist!")
print("Renaming")
User.objects.filter(email=previous_email).delete()
user.email = previous_email
user.save()
print("Done")
if __name__ == "__main__":
main()