@ -24,16 +24,15 @@ def jsonload (url):
def load_padinfo ( p ) :
with open ( p ) as f :
info = json . load ( f )
info [ ' api ' ] = " {0[protocol]} :// {0[hostname]} : {0[port]} {0[apiurl]} {0[apiversion]} / " . format ( info )
return info
def main ( args ) :
p = ArgumentParser ( " Check for pads that have changed since last sync (according to .meta.json) " )
p . add_argument ( " padid " , nargs = " * " , default = [ ] )
p . add_argument ( " --padinfo " , default = " padinfo .json" , help = " padinfo, default: padinfo .json" )
p . add_argument ( " --padinfo " , default = " .etherdump/settings .json" , help = " settings, default: .etherdump/settings .json" )
p . add_argument ( " --zerorevs " , default = False , action = " store_true " , help = " include pads with zero revisions, default: False (i.e. pads with no revisions are skipped) " )
p . add_argument ( " --pub " , default = " pub " , help = " folder to store files for public pads, default: pub " )
p . add_argument ( " --pub " , default = " . " , help = " folder to store files for public pads, default: pub " )
p . add_argument ( " --group " , default = " g " , help = " folder to store files for group pads, default: g " )
p . add_argument ( " --skip " , default = None , type = int , help = " skip this many items, default: None " )
p . add_argument ( " --meta " , default = False , action = " store_true " , help = " download meta to PADID.meta.json, default: False " )
@ -50,7 +49,7 @@ def main (args):
if args . padid :
padids = args . padid
else :
padids = jsonload ( info [ ' api ' ] + ' listAllPads? ' + urlencode ( data ) ) [ ' data ' ] [ ' padIDs ' ]
padids = jsonload ( info [ ' apiurl ' ] + ' listAllPads? ' + urlencode ( data ) ) [ ' data ' ] [ ' padIDs ' ]
padids . sort ( )
numpads = len ( padids )
# maxmsglen = 0
@ -80,14 +79,14 @@ def main (args):
if os . path . exists ( metapath ) :
with open ( metapath ) as f :
meta = json . load ( f )
revisions = jsonload ( info [ ' api ' ] + ' getRevisionsCount? ' + urlencode ( data ) ) [ ' data ' ] [ ' revisions ' ]
revisions = jsonload ( info [ ' apiurl ' ] + ' getRevisionsCount? ' + urlencode ( data ) ) [ ' data ' ] [ ' revisions ' ]
if meta [ ' revisions ' ] == revisions :
skip = True
break
meta = { ' padid ' : padid . encode ( " utf-8 " ) }
if revisions == None :
meta [ ' revisions ' ] = jsonload ( info [ ' api ' ] + ' getRevisionsCount? ' + urlencode ( data ) ) [ ' data ' ] [ ' revisions ' ]
meta [ ' revisions ' ] = jsonload ( info [ ' apiurl ' ] + ' getRevisionsCount? ' + urlencode ( data ) ) [ ' data ' ] [ ' revisions ' ]
else :
meta [ ' revisions ' ] = revisions
@ -99,9 +98,9 @@ def main (args):
# todo: load more metadata!
meta [ ' pad ' ] , meta [ ' group ' ] = splitpadname ( padid )
meta [ ' pathbase ' ] = p
meta [ ' lastedited_raw ' ] = int ( jsonload ( info [ ' api ' ] + ' getLastEdited? ' + urlencode ( data ) ) [ ' data ' ] [ ' lastEdited ' ] )
meta [ ' lastedited_raw ' ] = int ( jsonload ( info [ ' apiurl ' ] + ' getLastEdited? ' + urlencode ( data ) ) [ ' data ' ] [ ' lastEdited ' ] )
meta [ ' lastedited_iso ' ] = datetime . fromtimestamp ( int ( meta [ ' lastedited_raw ' ] ) / 1000 ) . isoformat ( )
meta [ ' author_ids ' ] = jsonload ( info [ ' api ' ] + ' listAuthorsOfPad? ' + urlencode ( data ) ) [ ' data ' ] [ ' authorIDs ' ]
meta [ ' author_ids ' ] = jsonload ( info [ ' apiurl ' ] + ' listAuthorsOfPad? ' + urlencode ( data ) ) [ ' data ' ] [ ' authorIDs ' ]
break
except HTTPError as e :
tries + = 1
@ -129,20 +128,20 @@ def main (args):
# Process text, html, dhtml, all options
if args . all or args . text :
text = jsonload ( info [ ' api ' ] + ' getText? ' + urlencode ( data ) )
text = jsonload ( info [ ' apiurl ' ] + ' getText? ' + urlencode ( data ) )
text = text [ ' data ' ] [ ' text ' ]
with open ( p + " .txt " , " w " ) as f :
f . write ( text . encode ( " utf-8 " ) )
if args . all or args . html :
html = jsonload ( info [ ' api ' ] + ' getHTML? ' + urlencode ( data ) )
html = jsonload ( info [ ' apiurl ' ] + ' getHTML? ' + urlencode ( data ) )
html = html [ ' data ' ] [ ' html ' ]
with open ( p + " .html " , " w " ) as f :
f . write ( html . encode ( " utf-8 " ) )
if args . all or args . dhtml :
data [ ' startRev ' ] = " 0 "
html = jsonload ( info [ ' api ' ] + ' createDiffHTML? ' + urlencode ( data ) )
html = jsonload ( info [ ' apiurl ' ] + ' createDiffHTML? ' + urlencode ( data ) )
html = html [ ' data ' ] [ ' html ' ]
with open ( p + " .diff.html " , " w " ) as f :
f . write ( html . encode ( " utf-8 " ) )