-
Notifications
You must be signed in to change notification settings - Fork 18
/
create-offline-messages.py
executable file
·82 lines (76 loc) · 2.42 KB
/
create-offline-messages.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
75
76
77
78
79
80
81
82
#!/usr/bin/env python
from datetime import datetime, timedelta
import json
import requests
import random
import sys
import uuid
num_to_create = int(sys.argv[1])
visitor_template = """
{{
"display_name": "gen_visitor {visitor_uuid}",
"email": "[email protected]",
"notes": "whatever"
}}
"""
chat_template = """
{{
"visitor": {{
"id": "{visitor_id}",
"notes": "i guess this is necessary",
"email": "",
"name": "Visitor 18685359"
}},
"message":"Hi there this is message {message_num}!",
"type":"offline_msg",
"timestamp": {start_timestamp},
"end_timestamp": {end_timestamp},
"session": {{
"browser": "Safari",
"city": "Orlando",
"country_code": "US",
"country_name": "United States",
"end_date": "{end_str}",
"ip": "67.32.299.96",
"platform": "Mac OS",
"region": "Florida",
"start_date": "{start_str}",
"user_agent": "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_10) AppleWebKit/600.1.25 (KHTML, like Gecko) Version/8.0 Safari/600.1.25",
"does_this_accept_anything": "we will see",
"even_integers?": 234
}}
}}
"""
with open("config.json") as f:
token = json.loads(f.read())["access_token"]
headers = {"Authorization": "Bearer " + token}
payload = visitor_template.format(**dict(
visitor_uuid=uuid.uuid4().hex,
))
response = requests.post("https://www.zopim.com/api/v2/visitors",
headers=headers,
data=payload)
response.raise_for_status()
visitor_id = response.json()["id"]
print("created visitor", visitor_id)
for x in range(num_to_create):
delta = timedelta(seconds=random.randint(0, 60*60*24*5))
start = datetime.utcnow() - delta
end = start + timedelta(minutes=5)
payload = chat_template.format(**dict(
visitor_id = visitor_id,
email_num = x % 10,
message_num = x,
start = start,
start_timestamp = int(start.timestamp()),
start_str = start.isoformat(),
end = end,
end_timestamp = int(end.timestamp()),
end_str = end.isoformat(),
))
response = requests.post("https://www.zopim.com/api/v2/chats",
headers=headers,
data=payload)
response.raise_for_status()
chat_id = response.json()["id"]
print("created chat", chat_id)