-
Notifications
You must be signed in to change notification settings - Fork 1
/
convert_projects.py
48 lines (40 loc) · 1.77 KB
/
convert_projects.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
import argparse
import os
import sys
import django
if __name__=="__main__":
parser = argparse.ArgumentParser(description="import es projects")
parser.add_argument('--mode', nargs='?', const=1, type=str, default='debug', help='debug/production')
MODE = parser.parse_args().mode
if MODE not in ["debug", "production"]:
print("Please use --mode debug or --mode production")
sys.exit(1)
if MODE == 'debug':
os.environ['DJANGO_SETTINGS_MODULE'] = 'MasterMarketplace.settings_development'
elif MODE == 'production':
os.environ['DJANGO_SETTINGS_MODULE'] = 'MasterMarketplace.settings'
django.setup()
from registration.CourseBrowser import CourseBrowser
from registration.utils import pack_header
from projects.models import Project
from studyguide.models import MainCourse
from timeline.utils import get_year
api = CourseBrowser()
for proj in Project.objects.all():
l = proj.RequiredCourses.all()
print('proj {} (id:{})'.format(proj, proj.pk))
for course in l:
code = course.Code.upper()
courseheader = api.get_course_data(code)
if courseheader is None:
print("skipped code {}".format(code))
continue
courseheader = pack_header(courseheader)
if not proj.RecommendedCourses.filter(Code=code).exists():
c = MainCourse.objects.get(Code=code, Year=get_year())
proj.RecommendedCourses.add(c)
proj.save()
print('Added {}'.format(c))
else:
print('was already planned, skipped {}'.format(courseheader['code']))
print("{} Courses imported for {}".format(l.count(), proj))