support compressed file list

This commit is contained in:
Damien Elmes 2010-12-27 03:01:01 +09:00
parent 38aac3d4ab
commit ee8bda08bb

View file

@ -4,11 +4,14 @@
from PyQt4.QtGui import * from PyQt4.QtGui import *
from PyQt4.QtCore import * from PyQt4.QtCore import *
import ankiqt, simplejson, time, cStringIO, zipfile, tempfile, os, re import ankiqt, simplejson, time, cStringIO, zipfile, tempfile, os, re, gzip
import traceback, urllib2, socket, cgi import traceback, urllib2, socket, cgi
from ankiqt.ui.utils import saveGeom, restoreGeom, showInfo from ankiqt.ui.utils import saveGeom, restoreGeom, showInfo
from anki.utils import fmtTimeSpan from anki.utils import fmtTimeSpan
URL = "http://ankiweb.net/file/"
#URL = "http://localhost:8001/file/"
R_ID = 0 R_ID = 0
R_USERNAME = 1 R_USERNAME = 1
R_TITLE = 2 R_TITLE = 2
@ -61,8 +64,10 @@ Error was:<pre>%s</pre>""")
socket.setdefaulttimeout(30) socket.setdefaulttimeout(30)
try: try:
sock = urllib2.urlopen( sock = urllib2.urlopen(
"http://anki.ichi2.net/file/search?t=%d" % self.type) URL + "search?t=%d&c=1" % self.type)
self.allList = simplejson.loads(unicode(sock.read())) data = sock.read()
data = gzip.GzipFile(fileobj=cStringIO.StringIO(data)).read()
self.allList = simplejson.loads(unicode(data))
except: except:
showInfo(self.conErrMsg % cgi.escape(unicode( showInfo(self.conErrMsg % cgi.escape(unicode(
traceback.format_exc(), "utf-8", "replace"))) traceback.format_exc(), "utf-8", "replace")))
@ -175,7 +180,7 @@ Error was:<pre>%s</pre>""")
self.parent.updateProgress() self.parent.updateProgress()
try: try:
sock = urllib2.urlopen( sock = urllib2.urlopen(
"http://anki.ichi2.net/file/get?id=%d" % URL + "get?id=%d" %
self.curRow[R_ID]) self.curRow[R_ID])
while 1: while 1:
data = sock.read(32768) data = sock.read(32768)