Skip to content

Instantly share code, notes, and snippets.

@edenman
Created December 9, 2021 01:22
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save edenman/66e8f82c20ce9243a475a71d5cdd7448 to your computer and use it in GitHub Desktop.
Save edenman/66e8f82c20ce9243a475a71d5cdd7448 to your computer and use it in GitHub Desktop.
Script for downloading all files from a Quill team export
# Run this script to download all of the files that were uploaded to public channels in your Team.
# Usage: cd my-files-dir && python download-files-from-export.py -f /Users/myusername/Downloads/export-filename.zip
import zipfile
import getopt
import sys
import re
import json
import os.path
import os
opts, unparsedArgs = getopt.getopt(sys.argv[1:], "f:")
zipFileName = None
for o, a in opts:
if o == "-f":
zipFileName = a
if zipFileName == None:
print("The `-f exportFile.zip` argument is required")
sys.exit(2)
zf = zipfile.ZipFile(zipFileName)
files = zf.namelist()
lines = []
threadChannelNameToThreadID = {}
for file in files:
matched = re.match("(.*)-thread-messages-[0-9]*.json", file)
if matched:
with zf.open(file) as f:
jsonMessages = json.loads(f.read().decode("utf-8"))["messages"]
while jsonMessages:
jsonMessage = jsonMessages.pop(0)
file = jsonMessage.get("file")
if file:
link = file.get("link")
if link:
filename = os.path.basename(link).split('?')[0]
print("Downloading " + link + " to filename " + filename)
os.system("wget \"" + link + "\" -O " + filename)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment