Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import httplib
- import json
- import re
- import sys
- def main():
- if len(sys.argv) < 2:
- print 'Please pass thread url in commandline'
- return
- url = sys.argv[1]
- if url[len(url) - 4:] == 'html':
- url = url.replace('html', 'json')
- else:
- url += '.json' # this could fail hard
- header = {'User-Agent': 'Opera 9.20'}
- conn = httplib.HTTPConnection('www.2ch.hk', 80, header)
- conn.request('GET', url)
- response = conn.getresponse()
- if 300 <= response.status < 200:
- print response.status + '\n' + response.reason
- return
- thread = response.read()
- conn.close()
- decoded = json.loads(thread)
- trips = {}
- hohols = 0
- regexp = re.compile('.+postertripid\">([\w\d\+/-]{8}).+src=\"/flags/([a-zA-Z]+)\.png')
- for i in decoded['thread']:
- field = i[0][u'name']
- t, c = regexp.match(field).groups()
- if not t in trips:
- if c == u'ua':
- hohols += 1
- trips[t] = 1
- print hohols
- return
- if __name__ == '__main__':
- main()
Advertisement
Add Comment
Please, Sign In to add comment