Created
August 27, 2016 07:30
-
-
Save zhangyoufu/baed53d0bc10ac60e8bf3cc8c582c18d to your computer and use it in GitHub Desktop.
小米移动选号辅助
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| # coding: utf-8 | |
| import sys | |
| reload(sys) | |
| sys.setdefaultencoding('utf-8') | |
| import json | |
| import requests | |
| import time | |
| def get( *args, **kwargs ): | |
| kwargs.setdefault( 'allow_redirects', False ) | |
| kwargs.setdefault( 'headers', {} )['Referer'] = '.mi.com' | |
| for i in xrange(5): | |
| try: | |
| resp = requests.get( *args, **kwargs ) | |
| assert resp.status_code == 200 | |
| return json.loads( resp.text.split('(',1)[1].rsplit(')',1)[0] ) | |
| except Exception as e: | |
| print >>sys.stderr, e, 'retry...' | |
| time.sleep(0.5) | |
| continue | |
| else: | |
| raise e | |
| def dump( obj ): | |
| return json.dumps( obj, indent=4, ensure_ascii=False ) | |
| regions = get( 'http://contract.shopapi.xiaomi.com/vno/getProvinceCityList.json?callback=getRegions&operators=cu' ) | |
| for province in regions['province']: | |
| for city in regions['city'][province['pid']]: | |
| if city['city_name'] not in u'上海市 北京市 杭州市'.split(): continue | |
| geo_location = '%s%s' % ( province['province_name'], city['city_name'] ) | |
| print >>sys.stderr, geo_location | |
| number_pool = set() | |
| last = 0 | |
| repeat = 0 | |
| while repeat < 20: | |
| numbers = get( 'http://contract.shopapi.xiaomi.com/vno/getPhoneList.json?callback=getNumbers&grad=-1&love=-1&search=&operators=cu', params={'cid':city['cid']} ) | |
| for number in numbers: | |
| number_pool.add( number['p'] ) | |
| curr = len( number_pool ) | |
| if curr == last: | |
| repeat += 1 | |
| else: | |
| last = curr | |
| repeat = 0 | |
| time.sleep(0.3) | |
| for p in sorted( number_pool ): | |
| print geo_location, p | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment