Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
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