All pastes #1050596 Raw Edit

Untitled

public text v1 · immutable
#1050596 ·published 2008-06-18 22:16 UTC
rendered paste body
def fetch(sid, fc, lc, callback=None):
 lst = []
 if fc == lc:
  if callback is not None: callback(sid, fc)
  return [(fc, urllib2.urlopen("http://www.fanfiction.net/s/%s/%s/" % (sid, fc)).read())]
 if lc == 0:
  lst+=fetch(sid, fc, fc, callback)
  if not isValidChapter(lst[-1][1]):
   raise Error, "not a valid chapter"
  lc = parsechapter(lst[-1][1])
  if lc == fc: return lst
  return lst+fetch(sid, fc+1, lc, callback)
#normal - a range of chapters.
 if fc > lc: raise Error, "first chapter cannot be greater than last."
 for i in range(fc, lc+1):
  lst+=fetch(sid, i, i, callback)
 return lst