yunyichongTel.py 2.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  1. # -*- coding: utf-8 -*-
  2. # !/usr/bin/env python
  3. import os, sys,time,datetime
  4. import urllib
  5. import requests
  6. from mongoengine import register_connection, PointField, DynamicDocument, StringField
  7. import simplejson as json
  8. from django.db.models.fields import DateTimeField
  9. PROJECT_ROOT = os.path.join(os.path.abspath(os.path.split(os.path.realpath(__file__))[0] + "/.."), '..')
  10. sys.path.insert(0, PROJECT_ROOT)
  11. os.environ.setdefault("DJANGO_SETTINGS_MODULE", "configs.testing")
  12. from script.base import init_env
  13. init_env(interactive = False)
  14. from apps.web.core.db import Searchable
  15. register_connection(alias = 'spider',
  16. name = 'spider',
  17. host = '116.62.228.194',
  18. port = 27017,
  19. username = 'dba',
  20. password = 'dayuan@2020..',
  21. authentication_source = 'admin')
  22. class Goverment(Searchable):
  23. province = StringField(default = "")
  24. city = StringField(default = "")
  25. name = StringField(default = '')
  26. lat = StringField(default = '')
  27. lng = StringField(default = '')
  28. meta = {
  29. 'collection': 'Goverment',
  30. 'db_alias': 'spider',
  31. 'unique_together': {'lat', 'lng'}
  32. }
  33. class yunyichongDevice(Searchable):
  34. uuid = StringField(default = '')
  35. meta = {
  36. 'collection': 'yunyichong_device',
  37. 'db_alias': 'spider',
  38. 'unique_together': {'uuid'}
  39. }
  40. # 根据二维码编号,获取设备更详细的信息
  41. url = 'https://wx-yyc.dianxiaomei.com.cn/ui/portlist?uuid=%s'
  42. cookie1 = 'PHPSESSID=0vcenbi6pgu6stup1brlelmo42; yyc_auth_v3=HNfsUaXyxVUL68umVR23r1JDNJd%2BwEEMXCH1oSMEbg%2FE08uwJGjseQE%2F7QigXiBx;'
  43. devs = yunyichongDevice.get_collection().find()
  44. ii = 0
  45. for dev in devs:
  46. try:
  47. ii += 1
  48. print ii
  49. url1 = url % (dev['uuid'])
  50. tempCookie = 'uid=%s;' % dev['uuid']
  51. cookies = cookie1 + tempCookie
  52. strhtml = str(requests.get(url1,verify=False,headers = {'Cookie':cookies}).text)
  53. startIndex = strhtml.find('tel:')
  54. endIndex = strhtml.find('"',startIndex)
  55. if not startIndex or not endIndex:
  56. continue
  57. tel = strhtml[startIndex+4:endIndex]
  58. yunyichongDevice.get_collection().update({'uuid':dev['uuid']},{'$set':{'tel':tel}})
  59. except Exception,e:
  60. continue
  61. print('OK')