-
Notifications
You must be signed in to change notification settings - Fork 0
/
populate.py
71 lines (58 loc) · 1.64 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
70
#!/usr/bin/python
#Filename: populate.py
from benjy.models import User, Project
import sqlite3
import re
passwordFile = file('sherlockholmes.txt').read().lower()
words = [word for word in re.split(r'\W+|\d+', passwordFile) if len(word) > 3]
count = 42
def populateUser():
conn = sqlite3.connect('mail.db')
cur = conn.cursor()
cur.execute("select rowid, name, usn, email, project from user")
students = cur.fetchall()[3:] #empty fields
for student in students:
user = User()
user.name = student[1]
user.usn = student[2]
user.email = student[3]
user.project_id = student[4]
flag = True
while flag:
password = user.password = getPassword()
try:
user.save()
flag = False
except: flag = True
cur.execute("update user set password = ? where rowid = ?", (password, student[0]))# for the mail
conn.commit()
def getPassword():
global count
count += 2
return words[count % len(words)] + ' ' + words[(count+1) % len(words)]
def populateProject():
conn = sqlite3.connect("mail.db")
cur = conn.cursor()
cur.execute("select * from projects order by projectId")
projects = cur.fetchall()
for project in projects:
try: user = User.objects.get(name = project[2])
except:
user = User()
user.name = project[2]
user.usn = 'T'
user.isTeacher = True
flag = True
while flag:
password = user.password = getPassword()
try:
user.save()
flag = False
except:
flag = True
cur.execute("insert into user (name, password, usn) values (?, ?, ?)",(user.name, password, user.usn));
projectObj = Project()
projectObj.title = project[1]
projectObj.guide = user
projectObj.save()
conn.commit()