Created
August 12, 2020 19:54
-
-
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
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 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