-
Notifications
You must be signed in to change notification settings - Fork 10
/
Copy pathpopulate.py
45 lines (43 loc) · 1.54 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
import regex as re
import requests
from user.models import User
class Populate:
def populate(batches):
r = requests.get("https://search.pclub.in/api/students")
students = r.json()
try:
for student in students:
cnt = student["i"]
for key in student:
if student[key] == "":
student[key] = str(cnt)
regex = "^[Y]"
if re.search(regex, student["i"]):
batch = student["i"][:2]
else:
batch = "Y" + student["i"][:2]
if batch not in batches:
continue
try:
q = User.objects.get(username=student["u"])
q.name = student["n"]
q.username = student["u"]
q.roll = student["i"]
q.batch = batch
q.program = student["p"]
q.department = student["d"]
q.email = student["u"] + "@iitk.ac.in"
except:
q = User(
name=student["n"],
username=student["u"],
roll=student["i"],
batch=batch,
program=student["p"],
department=student["d"],
email=student["u"] + "@iitk.ac.in",
)
q.save()
print("Done")
except:
print("Error")