forked from ghewgill/ljdump
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path20170401.patch
More file actions
52 lines (46 loc) · 1.9 KB
/
20170401.patch
File metadata and controls
52 lines (46 loc) · 1.9 KB
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
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
--- ljdump.py 2010-12-28 18:14:40.000000000 -0500
+++ ljdump.py.new 2017-01-04 06:56:31.000000000 -0500
@@ -24,7 +24,7 @@
#
# Copyright (c) 2005-2010 Greg Hewgill and contributors
-import codecs, os, pickle, pprint, re, shutil, sys, urllib2, xml.dom.minidom, xmlrpclib
+import codecs, os, pickle, pprint, re, shutil, sys, urllib2, xml.dom.minidom, xmlrpclib, time
from xml.sax import saxutils
MimeExtensions = {
@@ -39,6 +39,12 @@
import md5 as _md5
md5 = _md5.new
+def minid(metacache, old_max):
+ try:
+ return min(x for x in metacache.keys() if x > old_max)
+ except:
+ return old_max
+
def calcchallenge(challenge, password):
return md5(challenge+md5(password).hexdigest()).hexdigest()
@@ -197,6 +203,7 @@
print "Error getting item: %s" % item['item']
pprint.pprint(x)
errors += 1
+ time.sleep(4);
lastsync = item['time']
writelast(Journal, lastsync, lastmaxid)
@@ -277,6 +284,10 @@
newmaxid = maxid
maxid = lastmaxid
while True:
+ maxid = minid(metacache, maxid) - 1 # has to be minus one because the rest assumes plus one
+ if maxid == lastmaxid:
+ break #no more ids in the metacache
+
try:
try:
r = urllib2.urlopen(urllib2.Request(Server+"/export_comments.bml?get=comment_body&startid=%d%s" % (maxid+1, authas), headers = {'Cookie': "ljsession="+ljsession}))
@@ -312,6 +323,7 @@
if found:
print "Warning: downloaded duplicate comment id %d in jitemid %s" % (id, jitemid)
else:
+ print "Writing comment id %d from %s" % (id, comment['date'])
entry.documentElement.appendChild(createxml(entry, "comment", comment))
f = codecs.open("%s/C-%s" % (Journal, jitemid), "w", "UTF-8")
entry.writexml(f)