changes from server
This commit is contained in:
parent
d65f9e5385
commit
290a0e3b72
43
etherdump
43
etherdump
@ -68,12 +68,26 @@ class PadServer (object):
|
|||||||
def getPadLastEdited (self, padID):
|
def getPadLastEdited (self, padID):
|
||||||
data = {'apikey': self.apikey, 'padID': padID.encode("utf-8")}
|
data = {'apikey': self.apikey, 'padID': padID.encode("utf-8")}
|
||||||
raw = json.load(urlopen(self.apiurl+'getLastEdited?'+urlencode(data)))['data']['lastEdited']
|
raw = json.load(urlopen(self.apiurl+'getLastEdited?'+urlencode(data)))['data']['lastEdited']
|
||||||
return datetime.fromtimestamp(int(raw)/1000)
|
try:
|
||||||
|
return datetime.fromtimestamp(int(raw)/1000)
|
||||||
|
except TypeError as e:
|
||||||
|
return None
|
||||||
|
|
||||||
def getPadURL (self, padID):
|
def getPadURL (self, padID, groupinfo=None):
|
||||||
group, name = pad_split_group(padID)
|
group, name = pad_split_group(padID)
|
||||||
if group:
|
if group:
|
||||||
return self.protocol+"://"+self.hostname+"/p/"+padID
|
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:
|
else:
|
||||||
return self.protocol+"://"+self.hostname+"/public_pad/"+padID
|
return self.protocol+"://"+self.hostname+"/public_pad/"+padID
|
||||||
|
|
||||||
@ -89,7 +103,7 @@ def get_template_env (tpath=None):
|
|||||||
# template = env.get_template('pad.html')
|
# template = env.get_template('pad.html')
|
||||||
# print template.render(the='variables', go='here').encode("utf-8")
|
# print template.render(the='variables', go='here').encode("utf-8")
|
||||||
|
|
||||||
def dumpPads (padserver, padids, outputpath, pub_path, group_path, sleeptime=0.01, force=False, templates=None):
|
def dumpPads (padserver, padids, outputpath, pub_path, group_path, sleeptime=0.01, force=False, templates=None, groupinfo=None):
|
||||||
template_env = get_template_env(templates)
|
template_env = get_template_env(templates)
|
||||||
pad_template = template_env.get_template("pad.html")
|
pad_template = template_env.get_template("pad.html")
|
||||||
numpads = len(padids)
|
numpads = len(padids)
|
||||||
@ -123,12 +137,16 @@ def dumpPads (padserver, padids, outputpath, pub_path, group_path, sleeptime=0.0
|
|||||||
htmlpath = fp+".html"
|
htmlpath = fp+".html"
|
||||||
metapath = fp+".json"
|
metapath = fp+".json"
|
||||||
|
|
||||||
last_edited = padserver.getPadLastEdited(padid).isoformat()
|
last_edited = padserver.getPadLastEdited(padid)
|
||||||
|
if last_edited:
|
||||||
|
last_edited = last_edited.isoformat()
|
||||||
|
else:
|
||||||
|
last_edited = ''
|
||||||
|
|
||||||
if os.path.exists(metapath):
|
if os.path.exists(metapath):
|
||||||
with open(metapath) as f:
|
with open(metapath) as f:
|
||||||
meta = json.load(f)
|
meta = json.load(f)
|
||||||
if not force and meta.get("last_edited") == last_edited:
|
if not force and meta.get("last_edited") and meta.get("last_edited") == last_edited:
|
||||||
if verbose:
|
if verbose:
|
||||||
print("Up to date, skipping", file=sys.stderr)
|
print("Up to date, skipping", file=sys.stderr)
|
||||||
continue
|
continue
|
||||||
@ -162,7 +180,7 @@ def dumpPads (padserver, padids, outputpath, pub_path, group_path, sleeptime=0.0
|
|||||||
t = html5lib.parse(html, treebuilder="etree", namespaceHTMLElements=False)
|
t = html5lib.parse(html, treebuilder="etree", namespaceHTMLElements=False)
|
||||||
body = t.find(".//body")
|
body = t.find(".//body")
|
||||||
title = padid
|
title = padid
|
||||||
editurl = padserver.getPadURL(padid)
|
editurl = padserver.getPadURL(padid, groupinfo)
|
||||||
meta['url'] = editurl
|
meta['url'] = editurl
|
||||||
json_dump = json.dumps(meta)
|
json_dump = json.dumps(meta)
|
||||||
f.write(pad_template.render(
|
f.write(pad_template.render(
|
||||||
@ -333,6 +351,14 @@ if __name__ == "__main__":
|
|||||||
print(gid)
|
print(gid)
|
||||||
|
|
||||||
elif cmd == "dump":
|
elif cmd == "dump":
|
||||||
|
groupinfo = None
|
||||||
|
if args.groupinfo:
|
||||||
|
with open(args.groupinfo) as gif:
|
||||||
|
groupinfo = json.load(gif)
|
||||||
|
|
||||||
|
if verbose:
|
||||||
|
print ("Using groupinfo", file=sys.stderr)
|
||||||
|
|
||||||
start = time.time()
|
start = time.time()
|
||||||
padids = padserver.listAllPads()
|
padids = padserver.listAllPads()
|
||||||
if args.skip:
|
if args.skip:
|
||||||
@ -347,7 +373,8 @@ if __name__ == "__main__":
|
|||||||
args.pubpath,
|
args.pubpath,
|
||||||
args.grouppath,
|
args.grouppath,
|
||||||
force=args.force,
|
force=args.force,
|
||||||
templates=args.templates)
|
templates=args.templates,
|
||||||
|
groupinfo=groupinfo)
|
||||||
|
|
||||||
if verbose:
|
if verbose:
|
||||||
print ("Completed in {0:0.0f} seconds".format(time.time()-start), file=sys.stderr)
|
print ("Completed in {0:0.0f} seconds".format(time.time()-start), file=sys.stderr)
|
||||||
|
Loading…
Reference in New Issue
Block a user