sports.py 6.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170
  1. # -*- coding: utf-8 -*-
  2. import copy
  3. import datetime
  4. import time
  5. import scrapy
  6. import lxml.etree
  7. import pycomm
  8. import json
  9. from collectSports.biz import getMongo
  10. from collectSports.items import Odds
  11. from collectSports.spiders.setdata import hash_func
  12. class SportsSpider(scrapy.Spider):
  13. name = 'sports'
  14. allowed_domains = ['hg0088.com']
  15. # start_urls = ['http://hg0088.com/']
  16. custom_settings = {
  17. "Accept": "text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,*/*;q=0.8",
  18. "Accept-Encoding": "gzip, deflate",
  19. "Accept-Language": "zh-CN,zh;q=0.8",
  20. "Cache-Control": "max-age=0",
  21. "Connection": "keep-alive",
  22. # "Cookie": "OddType@21627573=H; protocolstr=http; gamePoint_21627573=2019-05-10%2A0%2A0; _ga=GA1.4.601418716.1557495256; _gid=GA1.4.1118061739.1557495256",
  23. # "Cookie": "OddType@21627573=H; _ga=GA1.4.773413111.1560825258; _gid=GA1.4.1960743904.1560825258; protocolstr=https; gamePoint_21627573=2019-06-18%2A2%2A0; _gat_UA-75448111-1=1",
  24. # "Host": "205.201.4.177",
  25. # "Origin": "https://205.201.4.177",
  26. # "USER_AGENT": "Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/55.0.2883.87 UBrowser/6.2.4098.3 Safari/537.36",
  27. # "ITEM_PIPELINES": {
  28. # "collectSports.pipelines.sports.SportsPipeline": 200,
  29. # }
  30. "Cookie": "OddType@21627573=H; _ga=GA1.4.773413111.1560825258; _gid=GA1.4.1960743904.1560825258; protocolstr=https; gamePoint_21627573=2019-06-18%2A2%2A",
  31. "Host": "205.201.4.177",
  32. "USER_AGENT": "Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/55.0.2883.87 UBrowser/6.2.4098.3 Safari/537.36",
  33. # "ITEM_PIPELINES": {
  34. # "collectSports.pipelines.sports.SportsPipeline": 200,
  35. # }
  36. }
  37. start_url = 'https://205.201.4.177/app/member/get_game_allbets.php'
  38. def start_requests(self):
  39. url = self.start_url
  40. mongo = getMongo()
  41. zq_competitions = mongo.changeSet('zq_competition').find()
  42. for zq_competition in zq_competitions:
  43. match_id = str(zq_competition['match_id'])
  44. # uuid = zq_competition['uuid']
  45. form_data = {
  46. "uid": "jjdpzpc07m21627573l376834",
  47. }
  48. current_time = datetime.datetime.now()
  49. mongo.changeSet('zq_competition').update({}, {'$set': {'current_time': current_time}}, upsert=True)
  50. # mongo.collection.update({}, {$set: {update_time: ""}}, {multi: 1})
  51. # mongo.changeSet('zq_league').insert(dict(zq_league))
  52. # mongo.changeSet({"name":"zhangsan"}, {"$set":{"age":"25"}})
  53. uuid = zq_competition['uuid']
  54. form_data = {
  55. "uid": "iobou83m21627573l357852",
  56. "langx": "zh-cn",
  57. "gtype": "FT",
  58. "showtype": "FT",
  59. "gid": match_id,
  60. "ltype": "4",
  61. "date": pycomm.gmdate()
  62. }
  63. request = scrapy.FormRequest(url, formdata=form_data, callback=self.parse, dont_filter=True,
  64. meta={'match_id': match_id, 'uuid': uuid})
  65. yield request
  66. def parse(self, response):
  67. game_list = []
  68. games = response.xpath('/serverresponse/game')
  69. match_id = response.meta['match_id']
  70. uid_list = []
  71. uuid = response.meta['uuid']
  72. for game in games:
  73. game_odds = {}
  74. game = lxml.etree.fromstring(game.extract())
  75. for i in game.getchildren():
  76. game_odds[i.tag] = i.text
  77. game_list.append(game_odds)
  78. with open('../collectSports/conf/hg0088.json', 'r', encoding='utf8') as hg:
  79. hg0088 = json.load(hg)['root']
  80. odd_list = []
  81. for x in hg0088:
  82. try:
  83. enabled = game_list[0][x['prodds']]
  84. if enabled == 'Y':
  85. x['enabled'] = 1
  86. else:
  87. x['enabled'] = 0
  88. except:
  89. x['enabled'] = 0
  90. items = x['items']
  91. new_items = []
  92. for y in items:
  93. try:
  94. y['oddsv'] = game_list[0][y['rodds']]
  95. except:
  96. y['oddsv'] = 0
  97. try:
  98. y['ratio'] = game_list[0][y['ratio_name']]
  99. except:
  100. y['ratio'] = ""
  101. uid = hash_func(y['lodds'], y['rodds'], y['ratio'], y['ratio_name'], y['oddsv'])
  102. y['uid'] = uid
  103. uid_list.append(uid)
  104. new_items.append(y)
  105. n_i = copy.deepcopy(x)
  106. n_i['items'] = new_items
  107. odd_list.append(n_i)
  108. if game_list:
  109. gidm = game_list[0].get('gidm', '')
  110. else:
  111. gidm = ''
  112. # print(response.text)
  113. item = Odds()
  114. item['match_id'] = match_id
  115. item['uuid'] = uid_list
  116. item['source'] = "hg0088"
  117. item['updata'] = time.strftime("%Y-%m-%d %H:%M:%S", time.localtime())
  118. item['content'] = odd_list
  119. item['gidm'] = gidm
  120. print(game_list)
  121. with open('../collectSports/conf/hg0088.json', 'r', encoding='utf8') as hg:
  122. hg0088 = json.load(hg)['root']
  123. print(111)
  124. odd_list = []
  125. for x in hg0088:
  126. try:
  127. x['enabled'] = game_list[0][x['prodds']]
  128. except:
  129. pass
  130. items = x['items']
  131. new_items = []
  132. for item in items:
  133. try:
  134. item['oddsv'] = game_list[0][item['rodds']]
  135. except:
  136. item['oddsv'] = 0
  137. try:
  138. item['ratio'] = game_list[0][item['ratio_name']]
  139. except:
  140. item['ratio'] = ""
  141. new_items.append(item)
  142. n_i = copy.deepcopy(x)
  143. n_i['items'] = new_items
  144. odd_list.append(n_i)
  145. item = Odds()
  146. item['match_id'] = match_id
  147. item['uuid'] = uuid
  148. item['source'] = "hg0088"
  149. item['updata'] = time.strftime("%Y-%m-%d %H:%M:%S", time.localtime())
  150. item['content'] = odd_list
  151. yield item