Skip to content

Instantly share code, notes, and snippets.

@Ellpeck
Created August 11, 2023 12:16
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 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
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