-
-
Notifications
You must be signed in to change notification settings - Fork 4
/
populate.py
69 lines (52 loc) · 1.9 KB
/
populate.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
import csv
import os
from django.conf import settings
import django
from cloudinary.uploader import upload_image
import cloudinary
import sys
settings_type = sys.argv[1]
departments = [] + sys.argv[2:]
# settings.configure()
os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'petroly.settings.'+settings_type)
print(os.environ.get('DJANGO_SETTINGS_MODULE'))
django.setup()
from evaluation.models import Instructor
def populate(name, dep, url):
new_obj = Instructor.objects.get_or_create(name=name, department=dep)
if url != 'https://i.pinimg.com/originals/0c/3b/3a/0c3b3adb1a7530892e55ef36d3be6cb8.png' and url != '' and url != None:
profile_pic = upload_image(
url,
folder='instructors/profile_pics',
public_id=name,
overwrite=True,
invalidate=True,
transformation=[
{'width': 200, 'crop': "thumb"}
],
format='jpg'
)
new_obj[0].profile_pic = profile_pic
new_obj[0].save()
print(new_obj)
deps = departments if departments else [
# 'AE', 'ARC', 'ARE', 'CE', 'CEM', 'CHE',
# 'CHEM', 'COE',
# 'CRP', 'EE', 'GS', 'ICS', 'ISOM',
# 'LS', 'MATH', 'ME', 'MGT', 'PE', 'PHYS', 'SE', 'IAS'
'ELD'
]
for dep in deps:
print('\n>>>>>>>>>>>>>>>>>>>>>>>> ' + dep)
with open('data/'+dep+'.csv', 'r') as file:
reader = csv.DictReader(file, delimiter=';')
for row in reader:
try:
populate(row['name'], dep, row['url'])
except cloudinary.exceptions.Error as e:
populate(row['name'], dep, None)
print(e)
except Exception as e:
print(e)
exit(-1)
continue