-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathinitial_run.py
More file actions
55 lines (36 loc) · 1.38 KB
/
initial_run.py
File metadata and controls
55 lines (36 loc) · 1.38 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
52
53
54
import datetime
import json
from datetime import datetime
import random
import time
import unicodedata
from common.mongo_db_connect import connect_to_database
db = connect_to_database()
employee = db.employee
customer = db.customer
# from unicode import unicode
def random_date():
# random.seed(seed)
d = random.randint(1577811600, int(time.time()))
return datetime.fromtimestamp(d).strftime('%Y-%m-%d %H:%M:%S')
def normalize_name(name):
text = unicodedata.normalize('NFD', name).encode('ascii', 'ignore').decode("utf-8")
return str(text)
def random_email(name):
return '_'.join(i for i in normalize_name(name).lower().split()) + '@bc.com'
def get_employee(name):
respond = employee.find_one({'Name': name})
return respond['email'], respond['phone_number']
def get_customer(name):
respond = customer.find_one({'Name': name})
return respond['Phone number']
path = 'C:\git\Topic-Proposal\sample_data\Transactions.json'
with open(path, 'r', encoding='utf8') as f:
data = json.loads(f.read())
for i in data:
i['employee_email'], i['employee_phone'] = get_employee(i['employee_name'])
i['customer_phone'] = get_customer(i['customer_name'])
write_path = 'C:\git\Topic-Proposal\sample_data\Transactions2.json'
with open(write_path, 'w', encoding='utf8') as f_out:
f_out.write(json.dumps(data, ensure_ascii=False, indent=4))
# pprint(data[0][''])