123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596 |
- # -*- coding: utf-8 -*-
- # !/usr/bin/env python
- import os, sys,time,datetime
- import urllib
- import requests
- from mongoengine import register_connection, PointField, DynamicDocument, StringField
- import simplejson as json
- from django.db.models.fields import DateTimeField
- PROJECT_ROOT = os.path.join(os.path.abspath(os.path.split(os.path.realpath(__file__))[0] + "/.."), '..')
- sys.path.insert(0, PROJECT_ROOT)
- os.environ.setdefault("DJANGO_SETTINGS_MODULE", "configs.testing")
- from script.base import init_env
- init_env(interactive = False)
- from apps.web.core.db import Searchable
- register_connection(alias = 'spider',
- name = 'spider',
- host = '211.159.224.10',
- port = 27119,
- username = 'service',
- password = 'oOzjoQcO5DyyiN97AY0NpzJ6vztjNpx5',
- authentication_source = 'admin')
- class Goverment(Searchable):
- province = StringField(default = "")
- city = StringField(default = "")
- name = StringField(default = '')
- lat = StringField(default = '')
- lng = StringField(default = '')
-
- meta = {
- 'collection': 'Goverment',
- 'db_alias': 'spider',
- 'unique_together': {'lat', 'lng'}
- }
-
- class haokuaichongDevice(Searchable):
- meta = {
- 'collection': 'haokuaichong_device',
- 'db_alias': 'spider',
- }
- class haokuaichongOtherDevice(Searchable):
- meta = {
- 'collection': 'haokuaichong_other_device',
- 'db_alias': 'spider',
- }
-
- # 分析公众号
- # url = 'http://ap3202.haokuaichong.cn/quickuser50/charge/info?device=%s&port=FF&cmd=0'
- # cookie = 'JSESSIONID=8E5A27C36409661680FCADD921EF267A;tgw_l7_route=8601cd2f2bac0d2b07a50c969c168416'
- # auth = 'Bearer eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJyb2xlIjoidXNlciIsImVuY3J5SWQiOiJOakEzTXpNMU1RPT0iLCJpc3MiOiJxdWlja191c2VyXzAwMSIsImlhdCI6MTY0OTQwMDIyNiwiYXVkIjoicXVpY2tfdXNlcl9hcGkiLCJleHAiOjE2NDk0MDM4MjYsIm5iZiI6MTY0OTQwMDIyNn0.C1KXB77mjkhsof01NGFoWM_TdSLeZ3OlWVuIiqLZXAw'
- # for ii in range(80,290000): #00,01,02,03
- # logicalId = ('%02xE1A704' % ii).upper()
- # url1 = url % logicalId
- # strhtml = requests.get(url1,headers = {'Cookie':cookie,'Authorization':auth}).text
- # result = json.loads(strhtml)
- # print result
- # if result['msg'] == u'请勿跨公众号使用':
- # print '------------------->',logicalId
-
-
- # 根据二维码编号,获取设备更详细的信息
- url = 'http://ap3202.haokuaichong.cn/quickuser50/charge/info?device=%s&port=00&cmd=1'
- cookie = 'JSESSIONID=8E5A27C36409661680FCADD921EF267A;tgw_l7_route=8601cd2f2bac0d2b07a50c969c168416'
- auth = 'Bearer eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJyb2xlIjoidXNlciIsImVuY3J5SWQiOiJOakUzTVRVMU5nPT0iLCJpc3MiOiJxdWlja191c2VyXzAwMSIsImlhdCI6MTY0OTkwMzI0OSwiYXVkIjoicXVpY2tfdXNlcl9hcGkiLCJleHAiOjE2NDk5MDY4NDksIm5iZiI6MTY0OTkwMzI0OX0.CN-UApjFt7mPChSIxHspf7gQoIM0rd6wZmefVe3_FHo'
- for ii in range(0,390000): #7174
- try:
- logicalId = '11%06d' % ii
- url1 = url % logicalId
- strhtml = requests.get(url1,headers = {'Cookie':cookie,'Authorization':auth}).text
- result = json.loads(strhtml)
- if result['code'] == 500 :
- if result['msg'] == u'请勿跨公众号使用':
- haokuaichongOtherDevice.get_collection().update({'deviceId':logicalId},{'$set':{'deviceId':logicalId}},upsert = True)
- continue
- else:
- continue
- if result['code'] == 70004:
- print ii, 'token 过期'
- break
- dev = result['data']
-
- haokuaichongDevice.get_collection().update({'deviceId':dev['deviceId']},{'$set':dev},upsert = True)
- print ii,'catch new one!!!!'
- except Exception,e:
- print 'ExceptionExceptionExceptionExceptionException',e
- continue
- print('OK')
|