Last active
October 18, 2024 12:06
-
-
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 hidden or 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 | |
import os.path | |
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) | |
removeQuery = url.split("?")[0] | |
spliturl = removeQuery.split("/") | |
filename = f"{spliturl[-2]}-{spliturl[-1]}" | |
destfile = f"{destination}/{filename}" | |
if os.path.isfile(destfile): | |
print(f"Already exists") | |
continue | |
with requests.get(url) as req: | |
with open(destfile, "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