gnopaste

Sorry for this ugly message. We are searching for some translators.
Please take a look here
Thanks to all translators, you're doing a great job!

Name
Anonymous
Scriptlanguage
Plain Text
Tabwidth
4
Date
08/23/2008 01:43:01 am
IP
89.113.222.208

The user was too lazy to give a description

  1. #!/usr/bin/python
  2. import sys, httplib, re, urllib
  3.  
  4. HOST='konachan.com'
  5. URL='/post/index.xml'
  6. LIMIT=1000
  7.  
  8. if len( sys.argv ) < 2:
  9.     sys.stderr.write( "Usage: %s tag" % sys.argv[0] )
  10.     exit( 1 )
  11.  
  12. hc = httplib.HTTPConnection( HOST )
  13.  
  14. def fetch_index( limit, page ):
  15.         global hc
  16.         args = urllib.urlencode( { 'tags': sys.argv[1], 'limit': limit, 'page': page } )
  17.         hc.request( 'GET', URL + '?' + args )
  18.         res = hc.getresponse()
  19.  
  20.         if res.status != 200:
  21.                 sys.stderr.write( 'Unable to fetch index: HTTP%d' % res.status )
  22.                 exit( 1 )
  23.  
  24.         return res.read()
  25.  
  26. data = fetch_index( LIMIT, 1 )
  27.  
  28. # Hack since I'm too lazy to look up the doc for MatchObjects
  29. try:    count = int( re.findall( '<posts count="([0-9]+)"', data )[0] )
  30. except:
  31.         sys.stderr.write( 'Could not locate number of posts which match this tag.' )
  32.         exit( 1 )
  33.  
  34. if count > LIMIT:
  35.         for page in range(2, count / LIMIT + 2):
  36.                 data += fetch_index( LIMIT, page )
  37.  
  38. # Should parse the XML here, but fuck it use a regex instead
  39. imgs = re.findall( 'file_url="([^"]+)"', data )
  40.  
  41. for img in imgs:
  42.     print img
  43.  
submitter » gnopaster | imprint « imprint     
» Terms of use «


Donate via Bitcoin:
1KCq5UvwuTMwgSAHUsd7eqkBWTHZau1ydN