From 90bdde07bacd1daff7e8d97e0ad7deee64178bcf Mon Sep 17 00:00:00 2001 From: Michael Murtaugh Date: Mon, 17 Oct 2016 15:40:16 +0200 Subject: [PATCH] settext and other tweaks --- README.md | 27 ++++++++---------- etherdump/commands/deletepad.py | 33 ++++++++++++++++++++++ etherdump/commands/gettext.py | 7 +++-- etherdump/commands/pull.py | 2 +- etherdump/commands/settext.py | 49 +++++++++++++++++++++++++++++++++ 5 files changed, 99 insertions(+), 19 deletions(-) create mode 100644 etherdump/commands/deletepad.py create mode 100644 etherdump/commands/settext.py diff --git a/README.md b/README.md index f55d8d9..2e9a632 100644 --- a/README.md +++ b/README.md @@ -7,13 +7,14 @@ Tool to publish [etherpad](http://etherpad.org/) pages to files. Requirements ------------- -python-dateutil, html5lib + * html5lib + * python-datutil, jinja2 (index subcommand) Installation ------------- - pip install python-dateutil html5lib + pip install python-dateutil jinja2 html5lib python setup.py install Example @@ -45,24 +46,20 @@ subcommands * gethtml * creatediffhtml * revisionscount +* index To get help on a subcommand: etherdump revisionscount --help -file sync ----------- -epfs? -pad to file -etherdump init http://localhost:9001/ --path foo -etherdump status - compare state of files to etherpad & report -etherdump pull -etherdump sync - push / pull file contents to pad +Change log / notes +======================= -why -------- -Etherdump is useful as a means of dumping the contents of etherpad to files, as a way of opening up the contents of the service to other services / methods / uses / tools / situations. (Files also of course allow for archival tools / methods) +Originally designed for use at: [constant](http://etherdump.constantvzw.org/). + + +17 Oct 2016 +----------------------------------------------- +Preparations for [Machine Research](https://machineresearch.wordpress.com/) [2](http://constantvzw.org/site/Machine-Research,2646.html) diff --git a/etherdump/commands/deletepad.py b/etherdump/commands/deletepad.py new file mode 100644 index 0000000..6ac878f --- /dev/null +++ b/etherdump/commands/deletepad.py @@ -0,0 +1,33 @@ +#!/usr/bin/env python + +from argparse import ArgumentParser +import json +from urllib import urlencode +from urllib2 import urlopen, HTTPError, URLError + + +def main(args): + p = ArgumentParser("calls the getText API function for the given padid") + p.add_argument("padid", help="the padid") + p.add_argument("--padinfo", default=".etherdump/settings.json", help="settings, default: .etherdump/settings.json") + p.add_argument("--showurl", default=False, action="store_true") + p.add_argument("--format", default="text", help="output format, can be: text, json; default: text") + args = p.parse_args(args) + + with open(args.padinfo) as f: + info = json.load(f) + apiurl = info.get("apiurl") + # apiurl = "{0[protocol]}://{0[hostname]}:{0[port]}{0[apiurl]}{0[apiversion]}/".format(info) + data = {} + data['apikey'] = info['apikey'] + data['padID'] = args.padid # is utf-8 encoded + requesturl = apiurl+'deletePad?'+urlencode(data) + if args.showurl: + print requesturl + else: + results = json.load(urlopen(requesturl)) + if args.format == "json": + print json.dumps(results) + else: + if results['data']: + print results['data']['text'].encode("utf-8") diff --git a/etherdump/commands/gettext.py b/etherdump/commands/gettext.py index 66f75c3..f55d8e8 100644 --- a/etherdump/commands/gettext.py +++ b/etherdump/commands/gettext.py @@ -1,7 +1,7 @@ #!/usr/bin/env python from argparse import ArgumentParser -import json +import json, sys from urllib import urlencode from urllib2 import urlopen, HTTPError, URLError @@ -28,8 +28,9 @@ def main(args): if args.showurl: print requesturl else: - results = json.load(urlopen(requesturl))['data'] + results = json.load(urlopen(requesturl)) if args.format == "json": print json.dumps(results) else: - print results['text'].encode("utf-8") + if results['data']: + sys.stdout.write(results['data']['text'].encode("utf-8")) diff --git a/etherdump/commands/pull.py b/etherdump/commands/pull.py index 8210215..58363fb 100644 --- a/etherdump/commands/pull.py +++ b/etherdump/commands/pull.py @@ -43,7 +43,7 @@ def main (args): p.add_argument("--meta", default=False, action="store_true", help="download meta to PADID.meta.json, default: False") p.add_argument("--text", default=False, action="store_true", help="download text to PADID.txt, default: False") p.add_argument("--html", default=False, action="store_true", help="download html to PADID.html, default: False") - p.add_argument("--dhtml", default=False, action="store_true", help="download dhtml to PADID.dhtml, default: False") + p.add_argument("--dhtml", default=False, action="store_true", help="download dhtml to PADID.diff.html, default: False") p.add_argument("--all", default=False, action="store_true", help="download all files (meta, text, html, dhtml), default: False") p.add_argument("--folder", default=False, action="store_true", help="dump files in a folder named PADID (meta, text, html, dhtml), default: False") p.add_argument("--output", default=False, action="store_true", help="output changed padids on stdout") diff --git a/etherdump/commands/settext.py b/etherdump/commands/settext.py new file mode 100644 index 0000000..79f950f --- /dev/null +++ b/etherdump/commands/settext.py @@ -0,0 +1,49 @@ +#!/usr/bin/env python + +from argparse import ArgumentParser +import json, sys +from urllib import urlencode +from urllib2 import urlopen, HTTPError, URLError + + +def main(args): + p = ArgumentParser("calls the getText API function for the given padid") + p.add_argument("padid", help="the padid") + p.add_argument("--text", default=None, help="text, default: read from stdin") + p.add_argument("--padinfo", default=".etherdump/settings.json", help="settings, default: .etherdump/settings.json") + p.add_argument("--showurl", default=False, action="store_true") + p.add_argument("--format", default="text", help="output format, can be: text, json; default: text") + p.add_argument("--create", default=False, action="store_true", help="flag to create pad if necessary") + args = p.parse_args(args) + + with open(args.padinfo) as f: + info = json.load(f) + apiurl = info.get("apiurl") + # apiurl = "{0[protocol]}://{0[hostname]}:{0[port]}{0[apiurl]}{0[apiversion]}/".format(info) + data = {} + data['apikey'] = info['apikey'] + data['padID'] = args.padid # is utf-8 encoded + + createPad = False + if args.create: + requesturl = apiurl+'getRevisionsCount?'+urlencode(data) + results = json.load(urlopen(requesturl)) + # print json.dumps(results, indent=2) + if results['code'] != 0: + createPad = True + if args.text: + text = args.text + else: + text = sys.stdin.read() + data['text'] = text + + if createPad: + requesturl = apiurl+'createPad?'+urlencode(data) + else: + requesturl = apiurl+'setText?'+urlencode(data) + + if args.showurl: + print requesturl + else: + results = json.load(urlopen(requesturl)) + print json.dumps(results, indent=2)