-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathmongodb_gen.py
75 lines (61 loc) · 1.6 KB
/
mongodb_gen.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
import pymongo
from pymongo import MongoClient
import datetime
from random import *
import string
import time
location = [
"selangor",
"kedah",
"kuala lumpur",
"perlis",
"sabah",
"sarawak",
"negeri sembilan",
"pahang",
"perak",
"kelantan",
"terrengganu",
"penang",
"melaka",
"johor",
]
min_char = 8
max_char = 12
allchar = string.ascii_letters + string.digits
domain = [
"@gmail.com",
"@ymail.com",
"@yahoo.com",
]
name = [ "".join(choice(allchar) for x in range(randint(min_char, max_char))) ]
for i in range(999):
name.append("".join(choice(allchar) for x in range(randint(min_char, max_char))))
client = MongoClient('mongodb://localhost:27017/',username='',password='')
db = client['testdb']
collection = db['purchase']
import random
while True:
item_array=[]
product_type = [
10000,
10001,
10002,
10003,
10004,
10005,
10006,
]
for z in range(0,random.randint(1,4)):
item={}
product= product_type.pop(random.randint(0,6-z))
item.update(type = product )
item.update(quantity = random.randint(1,2))
item_array.append(item)
post = {"email": string.lower(name[random.randint(0,999)])+ domain[random.randint(0,2)],
"state": location[random.randint(0,13)],
"timestamp": datetime.datetime.utcnow().strftime('%s'),
"items": item_array }
post_id = collection.insert(post)
print(post)
time.sleep(1)