forked from devclub-iitd/Yearbook
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathaddPolls.py
46 lines (40 loc) · 1.08 KB
/
addPolls.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
import django
import csv
django.setup()
from myapp.models import *
poll_filename = "./Scrape/polls.csv"
depts = [
("chemical", "Chemical Engineering"),
("civil", "Civil Engineering"),
("cse", "CS"),
("ee", "Electrical Engineering"),
("maths", "Maths"),
("mech", "Mechanical Engineering"),
("physics", "Engineering Physics"),
("textile", "Textile engineering"),
("dbeb", "Biotechnology"),
]
def addPoll(poll_quest,dept):
u = Poll(poll=poll_quest, department=dept)
u.save()
print(poll_quest,"------>",dept)
return
with open(poll_filename, "rU") as file:
reader = csv.reader(file, delimiter=';')
for col in reader:
poll_quest = col[1]
if(col[0]=="all"):
for dept in depts:
addPoll(poll_quest,dept[0])
elif(col[0]=="var"):
for dept in depts:
poll_quest_dept = poll_quest.replace("$DEPT$",dept[1])
addPoll(poll_quest_dept,dept[0])
elif(col[0][0]=="!"):
for dept in depts:
if(dept[0]!=col[0][1:]):
addPoll(poll_quest,dept[0])
else:
for dept in depts:
if(dept[0]==col[0]):
addPoll(poll_quest,dept[0])