Compare commits

..

No commits in common. "626811a49f7cce93254c169fa8b9529d2cd83a9b" and "5ab08f0f0b341fd495a5c39634251cc54076782d" have entirely different histories.

2 changed files with 15 additions and 21 deletions

View file

@ -3,9 +3,9 @@
import sys import sys
import os import os
from configparser import ConfigParser from configparser import ConfigParser
import requests
import json import json
import urllib.parse import urllib.parse
import urllib.request
sys.path.insert(1, os.path.join(os.path.dirname(__file__), "..", "script-resources")) sys.path.insert(1, os.path.join(os.path.dirname(__file__), "..", "script-resources"))
@ -48,8 +48,9 @@ def emote_downloader_and_iterator():
with open(registry_dump_file, "r") as f: with open(registry_dump_file, "r") as f:
emote_registry_data = json.load(f) emote_registry_data = json.load(f)
except FileNotFoundError: except FileNotFoundError:
with urllib.request.urlopen(registry_dump_url, timeout=10) as response: response = requests.get(registry_dump_url, timeout=10)
emote_registry_data = json.load(response) response.raise_for_status()
emote_registry_data = response.json()
assert emote_registry_data["version"] == 1 assert emote_registry_data["version"] == 1

View file

@ -6,13 +6,10 @@
import sys import sys
import os import os
import urllib.request import requests
import urllib.error
import colorama import colorama
import time import time
import argparse import argparse
import json
import typing
DISCORD_EPOCH = 1420070400000 # milliseconds DISCORD_EPOCH = 1420070400000 # milliseconds
@ -55,23 +52,19 @@ if not (image_size is None or (image_size > 0 and image_size & (image_size - 1))
parser.error("image_size must be greater than zero and a power of two") parser.error("image_size must be greater than zero and a power of two")
try: # no timeout here, sadly, due to this genius: <https://github.com/psf/requests/issues/3099#issuecomment-215522806>
opener = urllib.request.build_opener() response = requests.get(
# Don't send the User-Agent header, Discord blocks the default one "https://discordapp.com/api/users/{}".format(user_snowflake),
opener.addheaders = []
with opener.open(
urllib.request.Request(
"http://discord.com/api/users/{}".format(user_snowflake),
headers={"Authorization": "Bot {}".format(bot_token)}, headers={"Authorization": "Bot {}".format(bot_token)},
), timeout=3,
timeout=10, )
) as response: try:
raw_data = json.load(response) response.raise_for_status()
except urllib.error.HTTPError as err: except requests.HTTPError as err:
print(err, file=sys.stderr) print(response.json(), file=sys.stderr)
print(err.read(), file=sys.stderr)
raise err raise err
raw_data = response.json()
data = {} data = {}
data["ID"] = raw_data["id"] data["ID"] = raw_data["id"]