-
Notifications
You must be signed in to change notification settings - Fork 0
/
app.py
90 lines (62 loc) · 2.65 KB
/
app.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
83
84
85
86
87
88
89
90
import requests, datetime, json
people = {}
conversations = {}
unknownIds = []
session = requests.Session()
session.cookies.set(".ROBLOSECURITY", input("enter the value of your .roblosecurity cookie: "))
print("fetching conversations...", flush=True, end="")
page = 1
while True:
resp_json = session.get(f"https://chat.roblox.com/v2/get-user-conversations?pageNumber={page}&pageSize=30").json()
if len(resp_json) == 0:
break
for convo in resp_json:
conversations[convo['id']] = convo
page += 1
conversations = dict(sorted(conversations.items())) #sorted(conversations)
print(f" done! (got {len(conversations)} conversations)", flush=True)
for convoId in conversations.copy():
convo = conversations[convoId]
print(f"fetching chat history for conversation {convoId} ({convo['title']})...", flush=True, end="")
messages = []
lastMessageId = ""
while True:
resp_json = session.get(f"https://chat.roblox.com/v2/get-messages?conversationId={convo['id']}&pageSize=30&exclusiveStartMessageId={lastMessageId}").json()
if len(resp_json) == 0:
break
messages += resp_json
lastMessageId = resp_json[len(resp_json)-1]['id']
count = len(messages)
if count == 0:
del conversations[convoId]
else:
convo['messages'] = messages
for message in messages:
if not message['senderTargetId'] in unknownIds:
unknownIds.append(message['senderTargetId'])
initiatorId = convo['initiator']['targetId']
if not initiatorId in people:
people[initiatorId] = convo['initiator']
convo['initiator'] = initiatorId
participants = convo['participants']
for person in participants:
personId = person['targetId']
if not personId in people:
people[personId] = person
for person in participants.copy():
participants.append(person['targetId'])
participants.remove(person)
print(f" done! (got {count} messages)", flush=True)
for unknownId in unknownIds:
if not unknownId in people:
resp_json = session.get(f"https://users.roblox.com/v1/users/{unknownId}").json()
people[unknownId] = resp_json
resp_json = session.get("https://users.roblox.com/v1/users/authenticated").json()
filename = f"roblox-chat-archive-{resp_json['id']}-{resp_json['name']}-{datetime.datetime.now().strftime('%d-%m-%Y-%H-%M-%S')}.json"
with open(filename, "w") as file:
json.dump({
"userId": resp_json['id'],
"people": people,
"conversations": conversations
}, file, indent=4)
print(f"saved to {filename}")