Skip to content

Instantly share code, notes, and snippets.

@Roxxers
Created August 12, 2020 19:54
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Roxxers/7905d6f25bc375cb3adc9f6691540695 to your computer and use it in GitHub Desktop.
Save Roxxers/7905d6f25bc375cb3adc9f6691540695 to your computer and use it in GitHub Desktop.
Takes list of images and downloads them from discord, converting ID to UTC time for the filename
import requests
import datetime
import os
def snowflake_time(id):
return datetime.datetime.utcfromtimestamp(
((id >> 22) + 1420070400000) / 1000)
with open("urls", "r") as fp:
for line in fp:
line = line.strip("\n")
time = snowflake_time(int(line.split("/")[-2]))
file = "images/{}.{}".format(time.strftime("%Y-%m-%d %H:%M:%S"),
line.split(".")[-1])
if os.path.isfile(file):
name = file.split(".")
name[0] += "(1)"
file = "".join(name)
with open(file, "wb") as img:
img.write(requests.get(line).content)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment