Created
August 11, 2023 12:16
-
-
Save Ellpeck/e0f04417b5827a377749425bc89903c4 to your computer and use it in GitHub Desktop.
Quick and dirty python script to download all attachments from a Discord data package download
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 glob | |
import re | |
import requests | |
regex = r"https://cdn\.[^\s]*/attachments/[^\s]*" | |
source = "." | |
destination = "./media" | |
for file in glob.iglob(f"{source}/**/*.csv", recursive=True): | |
print(file) | |
with open(file, encoding="UTF-8") as csv: | |
for url in re.findall(regex, csv.read()): | |
print(url) | |
spliturl = url.split("/") | |
filename = f"{spliturl[-2]}-{spliturl[-1]}" | |
with requests.get(url) as req: | |
with open(f"{destination}/{filename}", "wb") as handler: | |
handler.write(req.content) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment