-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathpush_users.py
More file actions
executable file
·51 lines (38 loc) · 1.21 KB
/
push_users.py
File metadata and controls
executable file
·51 lines (38 loc) · 1.21 KB
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
#!/usr/bin/env python
import json
import requests
from argparse import ArgumentParser
from pymongo import MongoClient
POI_BASE_URL = "http://127.0.0.1:7070/"
if __name__ == '__main__':
parser = ArgumentParser(description = """
user pusher on event server.
""")
parser.add_argument('-t', '--token', help='pio token', required=True)
args = parser.parse_args()
db = MongoClient().navaak
url = POI_BASE_URL + "batch/events.json?accessKey=" + args.token
headers = {"Content-Type": "application/json"}
users = db.users.find({})
data = []
for user in users:
gender = ""
if "gender" in user["profile"]:
gender = user["profile"]["gender"]
data.append({
"event": "$set",
"entityType": "user",
"entityId": str(user["_id"]),
"properties": {
"gender": gender
}
})
if len(data) >= 50:
req = requests.post(url, headers=headers, json=data)
print req.status_code, req.text
print
data = []
if len(data) > 1:
req = requests.post(url, headers=headers, json=data)
print req.status_code, req.text
print