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 os
from configparser import ConfigParser
import requests
import json
import urllib.parse
import urllib.request
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:
emote_registry_data = json.load(f)
except FileNotFoundError:
with urllib.request.urlopen(registry_dump_url, timeout=10) as response:
emote_registry_data = json.load(response)
response = requests.get(registry_dump_url, timeout=10)
response.raise_for_status()
emote_registry_data = response.json()
assert emote_registry_data["version"] == 1

View file

@ -6,13 +6,10 @@
import sys
import os
import urllib.request
import urllib.error
import requests
import colorama
import time
import argparse
import json
import typing
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")
# no timeout here, sadly, due to this genius: <https://github.com/psf/requests/issues/3099#issuecomment-215522806>
response = requests.get(
"https://discordapp.com/api/users/{}".format(user_snowflake),
headers={"Authorization": "Bot {}".format(bot_token)},
timeout=3,
)
try:
opener = urllib.request.build_opener()
# Don't send the User-Agent header, Discord blocks the default one
opener.addheaders = []
with opener.open(
urllib.request.Request(
"http://discord.com/api/users/{}".format(user_snowflake),
headers={"Authorization": "Bot {}".format(bot_token)},
),
timeout=10,
) as response:
raw_data = json.load(response)
except urllib.error.HTTPError as err:
print(err, file=sys.stderr)
print(err.read(), file=sys.stderr)
response.raise_for_status()
except requests.HTTPError as err:
print(response.json(), file=sys.stderr)
raise err
raw_data = response.json()
data = {}
data["ID"] = raw_data["id"]