Last active
January 11, 2024 08:11
-
-
Save fangeugene/deadce57948ce0e9e4a57160f8c5b8a1 to your computer and use it in GitHub Desktop.
For downloading chats from Nightbot
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import json | |
import urlfetch | |
url_format = 'https://api.nightbot.tv/1/logs?columns%5B0%5D%5Bdata%5D=createdAt&columns%5B0%5D%5Bname%5D=&columns%5B0%5D%5Bsearchable%5D=true&columns%5B0%5D%5Borderable%5D=true&columns%5B0%5D%5Bsearch%5D%5Bvalue%5D=&columns%5B0%5D%5Bsearch%5D%5Bregex%5D=false&columns%5B1%5D%5Bdata%5D=user.displayName&columns%5B1%5D%5Bname%5D=&columns%5B1%5D%5Bsearchable%5D=true&columns%5B1%5D%5Borderable%5D=false&columns%5B1%5D%5Bsearch%5D%5Bvalue%5D=&columns%5B1%5D%5Bsearch%5D%5Bregex%5D=false&columns%5B2%5D%5Bdata%5D=message&columns%5B2%5D%5Bname%5D=&columns%5B2%5D%5Bsearchable%5D=true&columns%5B2%5D%5Borderable%5D=false&columns%5B2%5D%5Bsearch%5D%5Bvalue%5D=&columns%5B2%5D%5Bsearch%5D%5Bregex%5D=false&order%5B0%5D%5Bcolumn%5D=0&order%5B0%5D%5Bdir%5D=desc&start={}&length=100&search%5Bvalue%5D=&search%5Bregex%5D=false' | |
offset = 0 | |
all_messages = [] | |
while True: | |
response = urlfetch.get( | |
url_format.format(offset), | |
headers={ | |
'authorization': '', | |
'cookie': '', | |
'nightbot-channel': '', | |
}) | |
messages = json.loads(response.content.decode('utf-8')).get('messages') | |
if not messages: | |
break | |
print("Got {} messages with offset {}".format(len(messages), offset)) | |
all_messages += messages | |
offset += 100 | |
with open('chat.txt', 'w') as outfile: | |
json.dump(all_messages, outfile, indent=2) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment