-
Notifications
You must be signed in to change notification settings - Fork 0
/
generator.py
85 lines (81 loc) · 2.83 KB
/
generator.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
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
import json, requests, urllib2, random
from werkzeug.security import generate_password_hash
from loremipsum import generate_paragraph
import datetime
from bson import json_util
import json
import time
print '---------------------------------fetching users-----------------------'
url = 'http://127.0.0.1:8000/api/people'
randomuser = urllib2.urlopen('http://api.randomuser.me/?results=10&seed='+str(random.randrange(0, 101, 2)))
results = json.loads(randomuser.read())
users=results['results']
processed_users = []
headers = {'content-type': 'application/json'}
dt = str(datetime.datetime.now())
ts = int(time.time())
for raw_user in users:
user = raw_user['user']
user.pop('sha1')
user.pop('sha256')
user.pop('registered')
user.pop('md5')
user.pop('salt')
user.pop('SSN')
user.pop('cell')
user.pop('version')
user.pop('nationality')
user['born'] = user.pop('dob')
user['email_confirmed'] = True
user['lastmessageseen'] = ts
user['interests'] = []
user['study'] = {
'intermediate':"",
'graduate':""
}
user['password'] = {
'password':generate_password_hash('111'),
'password_test': '111',
'password_updated':dt
}
user['movies'] = []
user['send_add_requests'] = []
user['token'] = ''
user['friends'] = []
user['notifications'] = []
user['conversations'] = []
user['role'] = "test"
user['questions']=[]
user['study'] = {"school": "my school",
"graduate":"Engineering"
}
print '----------------------------user-------------------------'
print user
r = requests.post(url, data=json.dumps(user, default=json_util.default), headers=headers)
print '====================================================='
print r.content
resp = json.loads(r.content)
processed_users.append({'id': resp['_id'], 'etag': resp['_etag']})
print '---------------------------------Adding friends to users-----------------------'
print processed_users
uids = [x['id'] for x in processed_users]
for user in processed_users:
friends=set(random.sample(uids,int(random.random()*10)))
friends-set([user['id']])
headers['If-Match'] = user['etag']
friends_dict = {}
#friends_dict['friends'] = []
print friends_dict
print headers
#r = requests.patch(url + '/' + user['id'], data=json.dumps(friends_dict), headers=headers)
print r.content
print '---------------------------------Adding posts to users-----------------------'
for user in processed_users:
for _ in range(20):
post={}
post['type'] = 'text'
post['author'] = user['id']
post['content'] = generate_paragraph()[2]
post['interestedPeople'] = []
r = requests.post(url + '/' + user['id'] + '/posts', data=json.dumps(post), headers={'content-type': 'application/json'})
print r.content