Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- # -*- coding: utf-8 -*-
- import gevent.monkey
- gevent.monkey.patch_all()
- import urllib, os, json, re, sys,csv
- import csv
- import urllib2
- def get_data(uid):
- url = 'http://webvybory2012.ru/json/voting_stations/%d/%d.json'% (uid / 100, uid)
- raw_data = urllib.urlopen(url).read().decode('utf8')
- try:
- data = json.loads(raw_data)
- return data['name'], data['address']
- except:
- pass
- def get_channels(uid):
- req = urllib2.Request('http://webvybory2012.ru/account/channels?station_id=%d' % uid)
- req.add_header("Cookie", "<Paste your webvybory2012 cookie here>" )
- f = urllib2.urlopen(req)
- return f.read()
- def get_row(uid):
- result = get_data(uid)
- if result:
- cameras = re.findall(r'\x24([^\x00]*?)(?:\x92|\x93)(?:\xae|\xad)(.*?)(?:\xae|\xad)', get_channels(uid))
- row = [uid, result[1], result[0]] + ["%s %s" % (camera[1], camera[0]) for camera in cameras]
- #~ print "Writing ", result[1], result[0]
- return [unicode(item).encode('utf8') for item in row]
- from gevent.pool import Pool
- map_func = Pool(10).map
- writer = csv.writer(open(sys.argv[1], "wt"))
- max_uid = 145000
- step = 500
- for i in xrange(max_uid / step):
- start, end = i * step, (i + 1) * step
- rows = map_func(get_row, xrange(start, end))
- for row in rows:
- if row:
- writer.writerow(row)
- print "Completed %d " % end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement