roll_wangqiu.py 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294
  1. import datetime
  2. import pymongo
  3. import time
  4. import logging
  5. import json
  6. from .ball_func import fuhao
  7. from ..utils.helper import Helper
  8. from .ball_func import get_pcode, new_time, out_time
  9. from concurrent.futures import ThreadPoolExecutor
  10. from requests_futures.sessions import FuturesSession
  11. class Roll_Wangqiupipeline(object):
  12. def open_spider(self, spider):
  13. self.mongo = pymongo.MongoClient(host="192.168.2.200", username="kaiyou", password="kaiyou", port=27017)
  14. self.db = self.mongo['kaiyou']
  15. self.session = FuturesSession(executor=ThreadPoolExecutor(max_workers=10))
  16. def process_item(self, item, spider):
  17. url = 'http://admin.5gogo.com'
  18. logger = logging.getLogger(__name__)
  19. # 联赛id
  20. league_id = item['league_id']
  21. # 联赛名
  22. league_name = item['league_name']
  23. # result = item['result']
  24. # 比赛id
  25. match_id = item['game_id']
  26. # 球队1
  27. team_home = item['team_home']
  28. # 球队2
  29. team_guest = item['team_guest']
  30. # 数量(97>)
  31. tag_number = item['number']
  32. # 比赛状态
  33. zhuangtai = item['zhuangtai']
  34. # 日期
  35. # data_game = item['data_game']
  36. try:
  37. data_game = item['data_game'].split("/")
  38. month = str(data_game[1].strip())
  39. day = str(data_game[0])
  40. except Exception as e:
  41. logger.warning(e)
  42. data_game = item['data_game'].split(" ")
  43. months = str(data_game[1].strip())
  44. month_dict = {'Jan': '01', 'Feb': '02', 'Mar': '03', 'Apr': '04', 'May': '05', 'Jun': '06', 'Jul': '07',
  45. 'Aug': '08', 'Sep': '09', 'Oct': '10', 'Nov': '11', 'Dec': '12'}
  46. month = month_dict[months]
  47. day = str(data_game[0])
  48. # 比赛时间
  49. time_game = str(item['time_game'])
  50. # 比赛时间,时间戳
  51. ctime = "2019" + "-" + month + "-" + day + "" + time_game + ":00"
  52. r_ctime = "2019" + "-" + month + "-" + day
  53. # 现在时间,时间戳
  54. utime = time.strftime("%Y-%m-%d %H:%M:%S", time.localtime())
  55. # 队1分数
  56. score_home = item['score_home']
  57. # 队2分数
  58. score_guest = item['score_guest']
  59. # 第几节
  60. jijie = item['jijie']
  61. # 球队得分
  62. qiudui = item['qiudui']
  63. pt = 4
  64. # 取不到 暂时注掉
  65. # match_date, match_time = new_times(ctime)
  66. # 每局比分
  67. score_dict = item['score_dict']
  68. # 让盘
  69. concedes_dict = item['concedes_dict']
  70. concedes_dict_rule = item['concedes_dict_rule']
  71. # 冠军 独赢
  72. kemps_dict = item['kemps_dict']
  73. # 让局
  74. bureaus_dict = item['bureaus_dict']
  75. bureaus_dict_rule = item['bureaus_dict_rule']
  76. # 总局数大小
  77. total_number_dict = item['total_number_dict']
  78. total_number_dict_rule = item['total_number_dict_rule']
  79. # 总局数单双
  80. odd_evens_dict = item['odd_evens_dict']
  81. odd_evens_dict_rule = item['odd_evens_dict_rule']
  82. sq_dict = item['sq_dict']
  83. new_sq_dict = json.dumps(sq_dict)
  84. uuid = Helper.genearte_MD5(league_name + 'hg3535')
  85. """联赛"""
  86. # last_time = '2019-12-31 23:59:59'
  87. # league_dict = {"game_code": "wq", "title": "league", "source": "hg3535"}
  88. # league_list = []
  89. #
  90. # league_key = ["name_chinese", "kind", "match_mode", "if_stop", "last_time", "lg_id", "source", "uuid"]
  91. # league_value = [league_name, "1", "1", "0", last_time, league_id, "hg3535", uuid]
  92. # league_data = dict(zip(league_key, league_value))
  93. # league_list.append(league_data)
  94. # league_dict['data'] = league_list
  95. # if self.db.hg3535_wq_league.find({'lg_id': league_id}).count() < 1:
  96. # res = Helper.async_post(url + '/setLeague', league_dict)
  97. # print(res)
  98. # self.db.hg3535_wq_league.insert(league_list)
  99. """赛事"""
  100. # competition = self.db.hg3535_wq_competition.find_one({"match_id": match_id})
  101. # match_list = []
  102. # if competition:
  103. # print('网球赛事已存在,修改网球赛事四状态')
  104. # is_morningplate = competition['is_morningplate']
  105. # is_rollball = competition['is_rollball']
  106. # is_stringscene = competition['is_stringscene']
  107. # is_today = competition['is_today']
  108. # status = competition['status']
  109. # match_date = competition['match_date']
  110. # match_time = competition['match_time']
  111. # us_time = competition['us_time']
  112. # if is_rollball != 1 or status != 1:
  113. # match_dict = {"game_code": "wq", "title": "match", "source": "hg3535"}
  114. # match_key = ["home_team", "guest_team", "lg_id", "status", "match_id", "match_date", "match_time",
  115. # "tag", "source", "is_rollball", "is_morningplate", "is_stringscene", "us_time", "uuid",
  116. # "half_match_id", "is_today", 'rule']
  117. # match_value = [team_home, team_guest, league_id, 1, match_id, match_date, match_time, tag_number,
  118. # "hg3535", 1, is_morningplate, is_stringscene, us_time, uuid, 0, is_today, '']
  119. # match_data = dict(zip(match_key, match_value))
  120. # match_list.append(match_data)
  121. # match_dict['data'] = match_list
  122. # res = Helper.async_post(url + '/setMatch', match_dict)
  123. # print(res)
  124. # self.db.hg3535_wq_competition.insert(match_list)
  125. # self.db.hg3535_wq_competition.update({'match_id': str(match_id)},
  126. # {"$set": {"is_rollball": 1, "status": 1}},
  127. # upsert=True)
  128. # else:
  129. # print("网球赛事已存在,网球赛事状态时间未改变,不做修改")
  130. # else:
  131. # is_rollball = 1
  132. # is_today = 0
  133. # is_morningplate = 0
  134. # is_stringscene = 0
  135. # match_dict = {"game_code": "wq", "title": "match", "source": "hg3535"}
  136. # match_key = ["home_team", "guest_team", "lg_id", "status", "match_id", "match_date", "match_time",
  137. # "tag", "source", "is_rollball", "is_morningplate", "is_stringscene", "us_time", "uuid",
  138. # "half_match_id", "is_today", 'rule']
  139. # match_value = [team_home, team_guest, league_id, 1, match_id, r_ctime, "00:00", tag_number,
  140. # "hg3535", is_rollball, is_morningplate, is_stringscene, utime, uuid, 0, is_today, '']
  141. # match_data = dict(zip(match_key, match_value))
  142. # match_list.append(match_data)
  143. # match_dict['data'] = match_list
  144. # res = Helper.async_post(url + '/setMatch', match_dict)
  145. # print(res)
  146. # self.db.hg3535_wq_competition.insert(match_list)
  147. """赔率"""
  148. try:
  149. res = self.db.hg3535_wq_odds.find_one({'match_id': str(match_id), 'pt': pt})
  150. odds_only_list = res['odds_only']
  151. except:
  152. res = ''
  153. odds_only_list = []
  154. data_list = []
  155. odds_onlys = []
  156. # 滚球独赢
  157. if kemps_dict:
  158. for key, value in kemps_dict.items():
  159. if value:
  160. sole_str = 'kemps' + 'key' + '0' + str(match_id) + 'hg3535'
  161. sole = Helper.genearte_MD5(sole_str)
  162. odds_str = 'kemps' + str(key) + '0' + '0' + str(value) + 'hg3535' + str(match_id)
  163. odds_only = Helper.genearte_MD5(odds_str)
  164. kemps_key = ["match_id", "lg_id", "odds_code", "status", "sort", "p_code", "odds",
  165. "condition", "odds_only", "sole", "source", "type", "team"]
  166. kemps_value = [match_id, league_id, key, "0", 0, 'kemps', value, '',
  167. odds_only, sole, "hg3535", "0", ""]
  168. kemps_data = dict(zip(kemps_key, kemps_value))
  169. odds_onlys.append(odds_only)
  170. if odds_only not in odds_only_list:
  171. data_list.append(kemps_data)
  172. # 滚球让盘
  173. if concedes_dict:
  174. for key, value in concedes_dict.items():
  175. if value:
  176. sole_str = 'concedes' + 'key' + '0' + str(match_id) + 'hg3535'
  177. sole = Helper.genearte_MD5(sole_str)
  178. odds_str = 'concedes' + str(key) + '0' + str(concedes_dict_rule[key]) + str(
  179. value) + 'hg3535' + str(match_id)
  180. odds_only = Helper.genearte_MD5(odds_str)
  181. condition = fuhao(concedes_dict_rule[key])
  182. concedes_key = ["match_id", "lg_id", "odds_code", "status", "sort", "p_code", "odds",
  183. "condition", "odds_only", "sole", "source", "type", "team"]
  184. concedes_value = [match_id, league_id, key, "0", 0, 'concede', value, condition,
  185. odds_only, sole, "hg3535", "0", ""]
  186. concedes_data = dict(zip(concedes_key, concedes_value))
  187. odds_onlys.append(odds_only)
  188. if odds_only not in odds_only_list:
  189. data_list.append(concedes_data)
  190. # 滚球让局
  191. if bureaus_dict:
  192. for key, value in bureaus_dict.items():
  193. if value:
  194. sole_str = 'bureaus' + 'key' + '0' + str(match_id) + 'hg3535'
  195. sole = Helper.genearte_MD5(sole_str)
  196. odds_str = 'bureaus' + str(key) + '0' + str(bureaus_dict_rule[key]) + str(
  197. value) + 'hg3535' + str(match_id)
  198. odds_only = Helper.genearte_MD5(odds_str)
  199. condition = fuhao(bureaus_dict_rule[key])
  200. bureaus_key = ["match_id", "lg_id", "odds_code", "status", "sort", "p_code", "odds",
  201. "condition", "odds_only", "sole", "source", "type", "team"]
  202. bureaus_value = [match_id, league_id, key, "0", 0, 'bureaus', value, condition,
  203. odds_only, sole, "hg3535", "0", ""]
  204. bureaus_data = dict(zip(bureaus_key, bureaus_value))
  205. odds_onlys.append(odds_only)
  206. if odds_only not in odds_only_list:
  207. data_list.append(bureaus_data)
  208. # 滚球总局数大小
  209. if total_number_dict:
  210. for key, value in total_number_dict.items():
  211. if value:
  212. sole_str = 'total_number' + 'key' + '0' + str(match_id) + 'hg3535'
  213. sole = Helper.genearte_MD5(sole_str)
  214. odds_str = 'total_number' + str(key) + '0' + str(
  215. total_number_dict_rule[key]) + str(value) + 'hg3535' + str(match_id)
  216. odds_only = Helper.genearte_MD5(odds_str)
  217. condition = fuhao(total_number_dict_rule[key])
  218. total_number_key = ["match_id", "lg_id", "odds_code", "status", "sort", "p_code", "odds",
  219. "condition", "odds_only", "sole", "source", "type", "team"]
  220. total_number_value = [match_id, league_id, key, "0", 0, 'bureaus', value,
  221. condition, odds_only, sole, "hg3535", "0", ""]
  222. total_number_data = dict(zip(total_number_key, total_number_value))
  223. odds_onlys.append(odds_only)
  224. if odds_only not in odds_only_list:
  225. data_list.append(total_number_data)
  226. # 滚球总局数单双
  227. if odd_evens_dict:
  228. for key, value in odd_evens_dict.items():
  229. if value:
  230. condition = odd_evens_dict_rule[key]
  231. odds_str = "odd_evens" + key + '0' + str(odd_evens_dict_rule[key]) + str(
  232. value) + "hg3535" + str(match_id)
  233. sole_str = "odd_evens" + "key" + '0' + str(match_id) + "hg3535"
  234. odds_only = Helper.genearte_MD5(odds_str)
  235. sole = Helper.genearte_MD5(sole_str)
  236. odds_onlys.append(odds_only)
  237. odd_evens_key = ["match_id", "lg_id", "odds_code", "status", "sort", "p_code", "odds",
  238. "condition", "odds_only", "sole", "source", "type", "team"]
  239. odd_evens_value = [match_id, league_id, key, "0", 0, 'odd_evens', value,
  240. condition, odds_only, sole, "hg3535", "0", ""]
  241. odd_evens_data = dict(zip(odd_evens_key, odd_evens_value))
  242. if odds_only not in odds_only_list:
  243. data_list.append(odd_evens_data)
  244. odds_key = ["game_code", "title", "match_id", "lg_id", "data", "source", "odds_only", "tag", "uuid",
  245. "is_stringscene", "utime", "pt"]
  246. odds_value = ["wq", "odds", match_id, league_id, data_list, "hg3535", odds_onlys, tag_number, uuid,
  247. 0, utime, pt]
  248. odds_dict = dict(zip(odds_key, odds_value))
  249. # print(odds_dict)
  250. if data_list:
  251. res_data = Helper.async_post(url + '/setOdds', odds_dict)
  252. print(res_data)
  253. if "成功" in res_data:
  254. if res:
  255. self.db.hg3535_wq_odds.update({'match_id': match_id, 'pt': pt}, {
  256. '$set': {"data": data_list, "odds_only": odds_onlys, "utime": utime}}, upsert=True)
  257. else:
  258. self.db.hg3535_wq_odds.insert(odds_dict)
  259. # 赛事结果
  260. da_list = []
  261. wq_rball = {"lg_id": league_id, "home_player_name": team_home, "guest_player_name": team_guest,
  262. "home_player_let_plate": '', "guest_player_let_plate": '', "home_player_let_inning": "",
  263. "guest_player_let_inning": "", "all_inning": "", "home_player_score": score_home,
  264. "guest_player_score": score_guest,
  265. "status": 1, "first_score_player": "", "last_score_player": "",
  266. "first_inning_score": score_dict['one_score'],
  267. "second_inning_score": score_dict['second_score'], "third_inning_score": score_dict['third_score'],
  268. "match_winer_player": "", "update_time": "",
  269. "match_time": time_game, "match_process": jijie, "tag": tag_number, "match_id": match_id,
  270. "source": "hg3535",
  271. "match_score": score_dict['current_point_home_guest'], "ctime": ctime, "inning": "",
  272. "strat_time": "", "uuid": uuid, "result_mark": score_dict
  273. }
  274. da_list.append(wq_rball)
  275. r_data_dict = {
  276. "game_code": "wq",
  277. "title": "match_result_r",
  278. "source": "hg3535",
  279. "data": da_list
  280. }
  281. if da_list:
  282. try:
  283. res = Helper.async_post(url + '/setMatchResult', r_data_dict)
  284. print(res)
  285. except Exception as e:
  286. logger.warning('滚球接口数据异常, 提交失败')
  287. logger.warning(e)