Skip to content

Instantly share code, notes, and snippets.

@JonasGroeger
Last active December 13, 2015 23:59
Show Gist options
  • Save JonasGroeger/4995403 to your computer and use it in GitHub Desktop.
Save JonasGroeger/4995403 to your computer and use it in GitHub Desktop.
A little script to backup your IOU Potts. Either pass the urls from command line or embed them in code at lines 45+. I made an example there. Works for iou.de and iou.ch
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
__author__ = 'Jonas Gröger'
import argparse
import urllib.request
from urllib.error import URLError
from time import strftime
import os
from os import path
def download(folder, pott_url, append_to_filename=''):
"""
Downloads the pdf from a pott url to the specified folder.
The filename is a timestamp to which something is eventually added
Returns 1
"""
filename = strftime("%Y.%m.%d-%H:%M:%S") + append_to_filename + '.pdf'
file = path.join(folder, filename)
pott_export_url = pott_url + '/export/pdf/id/1'
with open(file, 'wb') as out_file:
try:
result = urllib.request.urlopen(pott_export_url).read()
except (URLError, ValueError):
print("ERROR: Could not retrieve '" + pott_export_url + "'. Skipping...")
os.remove(file)
return 0
out_file.write(result)
return 1
if __name__ == '__main__':
folder_to_save_pdfs = path.realpath(path.dirname(__file__))
parser = argparse.ArgumentParser()
parser.add_argument('pott', nargs='*', help="A url of type http://www.iou.ch/z6a8u1abc5ef1h")
args = parser.parse_args()
n_backed_up = 0
if args.pott:
for pott_url in args.pott:
n_backed_up += download(folder_to_save_pdfs, pott_url)
else:
n_backed_up += download(folder_to_save_pdfs, 'YOUR IOU POTT URL', '_POTT_NAME')
# n_backed_up += download(folder_to_save_pdfs, 'YOUR IOU POTT URL', '_POTT_NAME')
# ...
print('Finished backing up ' + str(n_backed_up) + ' potts.')
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment