4 changed files with 132 additions and 38 deletions
@ -0,0 +1,17 @@ |
|||
NOTES |
|||
====== |
|||
|
|||
23 July |
|||
* Add HTML diffing to dump |
|||
* Add indexing |
|||
* Make Constant DUMP public ! |
|||
_ _ _ |
|||
_____ _____ ___| | | ___ _ __ | |_ |
|||
/ _ \ \/ / __/ _ \ | |/ _ \ '_ \| __| |
|||
| __/> < (_| __/ | | __/ | | | |_ |
|||
\___/_/\_\___\___|_|_|\___|_| |_|\__| |
|||
|
|||
* drag and drop directory listing |
|||
* history via git |
|||
* editing in etherpad |
|||
* makefile based publishing scripts (pandoc for html to page / epub ?!) |
@ -1,38 +0,0 @@ |
|||
#!/usr/bin/env python |
|||
from __future__ import print_function |
|||
from argparse import ArgumentParser |
|||
import json, sys |
|||
from urllib import urlencode |
|||
from urllib2 import urlopen, HTTPError, URLError |
|||
|
|||
p = ArgumentParser("") |
|||
p.add_argument("padid", help="the padid") |
|||
p.add_argument("--startrev", type=int, default=2, help="starting revision") |
|||
p.add_argument("--endrev", type=int, default=None, help="ending revision, default: last") |
|||
p.add_argument("--padinfo", default="padinfo.json", help="padinfo, default: padinfo.json") |
|||
p.add_argument("--dir", default="out") |
|||
args = p.parse_args() |
|||
|
|||
with open(args.padinfo) as f: |
|||
info = json.load(f) |
|||
apiurl = "{0[protocol]}://{0[hostname]}:{0[port]}{0[apiurl]}{0[apiversion]}/".format(info) |
|||
data = {} |
|||
data['apikey'] = info['apikey'] |
|||
data['padID'] = args.padid.encode("utf-8") |
|||
|
|||
|
|||
total_revisions = apiurl+'getRevisionsCount?'+urlencode(data) |
|||
total_revisions = json.load(urlopen(total_revisions))['data']['revisions'] |
|||
rev = args.startrev |
|||
print ("Dumping {0} revisions...".format(total_revisions), file=sys.stderr) |
|||
|
|||
data['startRev'] = "1" |
|||
while rev <= total_revisions: |
|||
data['endRev'] = "{0}".format(rev) |
|||
requesturl = apiurl+'createDiffHTML?'+urlencode(data) |
|||
html = json.load(urlopen(requesturl))['data']['html'] |
|||
out = "{0}/{1}_{2:06d}.html".format(args.dir, args.padid, rev) |
|||
print ("writing {0}".format(out), file=sys.stderr) |
|||
with open(out, "w") as f: |
|||
f.write(html.encode("utf-8")) |
|||
rev += 1 |
@ -0,0 +1,32 @@ |
|||
#!/usr/bin/env python |
|||
|
|||
from argparse import ArgumentParser |
|||
import json |
|||
from urllib import urlencode |
|||
from urllib2 import urlopen, HTTPError, URLError |
|||
|
|||
p = ArgumentParser("") |
|||
p.add_argument("padid", help="the padid") |
|||
p.add_argument("--padinfo", default="padinfo.json", help="padinfo, default: padinfo.json") |
|||
p.add_argument("--showurl", default=False, action="store_true") |
|||
p.add_argument("--text", default=False, action="store_true", help="text output (not json)") |
|||
args = p.parse_args() |
|||
|
|||
with open(args.padinfo) as f: |
|||
info = json.load(f) |
|||
apiurl = "{0[protocol]}://{0[hostname]}:{0[port]}{0[apiurl]}{0[apiversion]}/".format(info) |
|||
data = {} |
|||
data['apikey'] = info['apikey'] |
|||
data['padID'] = args.padid.encode("utf-8") |
|||
requesturl = apiurl+'getText?'+urlencode(data) |
|||
if args.showurl: |
|||
print requesturl |
|||
else: |
|||
results = json.load(urlopen(requesturl))['data'] |
|||
if args.text: |
|||
print results['data'].encode("utf-8") |
|||
else: |
|||
print json.dump(results) |
|||
|
|||
# To save to file run: |
|||
# python gettext.py > copy.txt |
@ -0,0 +1,83 @@ |
|||
import json |
|||
from urllib2 import urlopen, HTTPError, URLError |
|||
from urllib import urlencode |
|||
|
|||
class PadServer (object): |
|||
def __init__ (self, hostname, port=9001, apipath="/api/", apiversion="1.2.9", apikey=None, secure=False): |
|||
self.hostname = hostname |
|||
if secure: |
|||
self.protocol = "https" |
|||
else: |
|||
self.protocol = "http" |
|||
|
|||
self.apiurl = self.protocol+"://"+hostname |
|||
if port: |
|||
self.apiurl += ":{0}".format(port) |
|||
self.apiurl += "{0}{1}/".format(apipath, apiversion) |
|||
self.apikey = apikey |
|||
|
|||
def listAllPads (self): |
|||
data = {'apikey': self.apikey} |
|||
url = self.apiurl+'listAllPads?'+urlencode(data) |
|||
return json.load(urlopen(url))['data']['padIDs'] |
|||
|
|||
def listAllGroups (self): |
|||
data = {'apikey': self.apikey} |
|||
url = self.apiurl+'listAllGroups?'+urlencode(data) |
|||
return json.load(urlopen(url))['data']['groupIDs'] |
|||
|
|||
def getPadText (self, padID): |
|||
data = {'apikey': self.apikey, 'padID': padID.encode("utf-8")} |
|||
return json.load(urlopen(self.apiurl+'getText?'+urlencode(data)))['data']['text'] |
|||
|
|||
def getPadHTML (self, padID): |
|||
data = {'apikey': self.apikey, 'padID': padID.encode("utf-8")} |
|||
return json.load(urlopen(self.apiurl+'getHTML?'+urlencode(data)))['data']['html'] |
|||
|
|||
def getPadLastEdited (self, padID): |
|||
data = {'apikey': self.apikey, 'padID': padID.encode("utf-8")} |
|||
raw = json.load(urlopen(self.apiurl+'getLastEdited?'+urlencode(data)))['data']['lastEdited'] |
|||
try: |
|||
return datetime.fromtimestamp(int(raw)/1000) |
|||
except TypeError as e: |
|||
return None |
|||
|
|||
def getPadURL (self, padID, groupinfo=None): |
|||
group, name = pad_split_group(padID) |
|||
if group: |
|||
gid = group |
|||
if gid.startswith("g."): |
|||
gid = gid[2:] |
|||
if groupinfo: |
|||
ginfo = groupinfo.get(gid) |
|||
if ginfo: |
|||
groupID = ginfo.get("id", 0) |
|||
else: |
|||
groupID = 0 |
|||
else: |
|||
groupID = 0 |
|||
return self.protocol+"://"+self.hostname+"/group.html/"+str(groupID)+"/pad.html/"+padID |
|||
else: |
|||
return self.protocol+"://"+self.hostname+"/public_pad/"+padID |
|||
|
|||
def getRevisionsCount (self, padID): |
|||
data = {'apikey': self.apikey, 'padID': padID.encode("utf-8")} |
|||
raw = json.load(urlopen(self.apiurl+'getRevisionsCount?'+urlencode(data)))['data']['revisions'] |
|||
return int(raw) |
|||
|
|||
def listAuthorsOfPad (self, padID): |
|||
data = {'apikey': self.apikey, 'padID': padID.encode("utf-8")} |
|||
raw = json.load(urlopen(self.apiurl+'listAuthorsOfPad?'+urlencode(data)))['data']['authorIDs'] |
|||
return raw |
|||
|
|||
def getRevisionChangeset (self, padID, rev=None): |
|||
data = {'apikey': self.apikey, 'padID': padID.encode("utf-8"), 'rev': "{0}".format(rev)} |
|||
raw = json.load(urlopen(self.apiurl+'getRevisionChangeset?'+urlencode(data))) |
|||
return raw |
|||
|
|||
def createDiffHTML (self, padID, startRev=0, endRev=None): |
|||
if endRev == None: |
|||
endRev = getRevisionsCount(self, padID) |
|||
data = {'apikey': self.apikey, 'padID': padID.encode("utf-8"), 'startRev': "{0}".format(startRev), 'endRev': "{0}".format(endRev)} |
|||
raw = json.load(urlopen(self.apiurl+'createDiffHTML?'+urlencode(data)))['data'] |
|||
return raw |
Loading…
Reference in new issue