-
Notifications
You must be signed in to change notification settings - Fork 0
/
insert_random.py
executable file
·48 lines (34 loc) · 1.02 KB
/
insert_random.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
#!/usr/bin/env python
# Gera inserts randomicos
# Para testar sharding e shard-key
# Christiano Anderson
import pymongo
import random
import datetime
#cli.pybr.authenticate('user','pass')
def gera_nome():
alphabet = "abcdefghijklmnopqrstuvwxyz"
pw_length = 16
mypw = ""
for i in range(pw_length):
next_index = random.randrange(len(alphabet))
mypw = mypw + alphabet[next_index]
return(mypw)
ufs = ['AC','AP','AM','RO','PI','PE','CE','DF','RJ','SP','SC','RS','GO']
#ufs = ['PR']
while True:
cli = pymongo.MongoClient('mongodb://endor.pybr.net:30011,endor.pybr.net:30012,endor.pybr.net:30013/?replicaSet=rs1')
db = cli.escola
#cli.escola.authenticate('escola','teste')
cod = random.randint(1,9999999)
nome = gera_nome()
email = nome + "@email.fake"
agora = datetime.datetime.now()
db.cadastro.insert({
'cod': cod,
'nome': nome,
'email': email,
'uf': random.choice(ufs),
'data_cadastro': agora})
print nome
cli.close()