Skip to content

Instantly share code, notes, and snippets.

@Ellpeck
Last active October 18, 2024 12:06
Show Gist options
  • Save Ellpeck/e0f04417b5827a377749425bc89903c4 to your computer and use it in GitHub Desktop.
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
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