forked from ruanbekker/scripts
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathgenerate-random-data-dynamodb.py
More file actions
45 lines (39 loc) · 1.16 KB
/
Copy pathgenerate-random-data-dynamodb.py
File metadata and controls
45 lines (39 loc) · 1.16 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
import boto.dynamodb2
from boto.dynamodb2.table import Table
from boto.dynamodb2.fields import HashKey
from boto.regioninfo import RegionInfo
from boto.dynamodb2.layer1 import DynamoDBConnection
from faker import Factory
import uuid
import time
try:
sessions = Table(
table_name='usertable',
schema=[HashKey('id')],
connection=DynamoDBConnection(
region=RegionInfo(name='eu-west-1',
endpoint='dynamodb.eu-west-1.amazonaws.com')
))
except:
print("Dynamo can't connect")
def create_session():
id = str(uuid.uuid4())
timestamp = time.strftime("%Y%m%d%H%M%S")
ipv4 = Factory.create().ipv4()
users_id = Factory.create().slug()
users_name = Factory.create().first_name()
users_surname = Factory.create().last_name()
res = sessions.put_item(data={
'username': id,
'data': {
'user_id': users_id,
'name' : users_name,
'surname' : users_surname,
'ip': str(ipv4),
'datetime': timestamp
}
})
print('Created: ' + str(res))
if __name__ == '__main__':
for x in range(20):
create_session()