doit.py 755 Bytes
Newer Older
alexandre's avatar
alexandre committed
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32
import os
import requests


api_key = "ZEojF6PGrOomABIXDf4igo9XfCdWaZL5"
pad_id = "metahoguet"
base_url = "http://pads.osp.kitchen"
api_url = "{}/api/1/".format(base_url)
params = {"padID": pad_id, "apikey": api_key}
outdir = "/tmp/foobar"
letter = "A"


r = requests.get('{}getRevisionsCount'.format(api_url), params=params)
rev = r.json().get("data").get("revisions")

rev_dir = os.path.join(outdir, "{}_{}".format(rev, letter))

try:
    os.makedirs(os.path.join(rev_dir))
except:
    pass

r = requests.get('{}getText'.format(api_url), params=dict(revision=rev, **params))
text = r.json().get("data").get("text")

fn = os.path.join(rev_dir, "source.mp")
f = open(fn, "w")
f.write(text)


#  metamonday.mp && mpost -interaction=batchmode metamonday.mp