-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgenerate_fake_data.sh
71 lines (52 loc) · 1.59 KB
/
generate_fake_data.sh
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
#!/usr/bin/env python3
import json
from dateutil.tz import tzlocal
from faker import Faker
from random import randint, choice
def build_user(fake):
user_id = fake.uuid4()
return {
'id': user_id,
'first_name': fake.first_name(),
'last_name': fake.last_name(),
'avatar_url': f'https://i.pravatar.cc/150?u={user_id}'
}
def take_created_at(element):
return element.get('created_at')
fake = Faker('de_CH')
current_user = build_user(fake)
f = open('./data/current_user.json', 'w')
f.write(json.dumps(current_user))
users = []
conversations = []
messages = {}
for i in range(0, 10):
user = build_user(fake)
users.append(user)
for i in range(0, 10):
conversation_id = fake.uuid4()
conversation = {
'id': conversation_id,
'participants': [
current_user,
users[i]
],
'messages_url': f'https://conversation-echo-api.tamedia-origami.ch/conversations/{conversation_id}/messages'
}
conversations.append(conversation)
f = open('./data/conversations.json', 'w')
f.write(json.dumps(conversations))
for conversation in conversations:
conversation_messages = []
for i in range(2, randint(5, 10)):
message = {
'id': fake.uuid4(),
'created_at': fake.date_time_this_month().replace(tzinfo=tzlocal()).isoformat(),
'participant': choice(conversation.get('participants')),
'content': fake.sentences(nb=1)[0]
}
conversation_messages.append(message)
conversation_messages.sort(key=take_created_at)
messages[conversation.get('id')] = conversation_messages
f = open('./data/messages.json', 'w')
f.write(json.dumps(messages))