-
Notifications
You must be signed in to change notification settings - Fork 6
Expand file tree
/
Copy pathutils_build_user_api.py
More file actions
37 lines (28 loc) · 950 Bytes
/
utils_build_user_api.py
File metadata and controls
37 lines (28 loc) · 950 Bytes
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
#!/usr/bin/env python
# -*- coding: utf-8 -*-
import sys
import os
import csv
from lib.users import UserAPI
#config stuff
# if "TOPOGRAM_RAW_DATA_PATH" in os.environ:
# raw_path=os.environ.get('TOPOGRAM_RAW_DATA_PATH')
# else: raise Exception("TOPOGRAM_RAW_DATA_PATH is not defined !")
def create_user_api(userdata_file):
api=UserAPI()
with open(userdata_file, 'rb') as csvfile:
i=0
user_data=csv.reader(csvfile)
csvfile.next() #skip csv header
print "Storing users in MongDB... Please Wait."
for row in user_data:
api.create_user(row)
i+=1
# number of lines : 14,388,386 users
print "%d users saved"%i
if __name__ == "__main__":
if os.path.isfile(sys.argv[1]) :
# and sys.argv[1][0:len("userdata.csv")] == "userdata.csv":
create_user_api(sys.argv[1])
else :
raise ValueError("File name should be userdata.csv")