wangqiu.py 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315
  1. import datetime
  2. import pymongo
  3. import time
  4. import logging
  5. from .ball_func import fuhao
  6. from ..utils.helper import Helper
  7. from .ball_func import get_pcode, new_time, out_time
  8. from concurrent.futures import ThreadPoolExecutor
  9. from requests_futures.sessions import FuturesSession
  10. class Wangqiupipeline(object):
  11. def open_spider(self, spider):
  12. self.mongo = pymongo.MongoClient(host="192.168.2.200", username="kaiyou", password="kaiyou", port=27017)
  13. self.db = self.mongo['kaiyou']
  14. self.session = FuturesSession(executor=ThreadPoolExecutor(max_workers=10))
  15. def process_item(self, item, spider):
  16. wq_odds = []
  17. logger = logging.getLogger(__name__)
  18. url = 'http://admin.5gogo.com'
  19. # logger.warning(query.addErrback(self.handle_error, item, spider))
  20. # 联赛id
  21. league_id = item['league_id']
  22. # 联赛名
  23. league_name = item['league_name']
  24. # result = item['result']
  25. # 比赛id
  26. match_id = item['game_id']
  27. # print(game_id)
  28. # 球队1
  29. team_home = item['team_home']
  30. # 球队2
  31. team_guest = item['team_guest']
  32. # 数量(97>)
  33. tag_number = item['number']
  34. # 比赛状态
  35. zhuangtai = item['zhuangtai']
  36. # 日期
  37. # data_game = item['data_game']
  38. try:
  39. data_game = item['data_game'].split("/")
  40. month = str(data_game[1].strip())
  41. day = str(data_game[0])
  42. except Exception as e:
  43. logger.warning(e)
  44. data_game = item['data_game'].split(" ")
  45. months = str(data_game[1].strip())
  46. month_dict = {'Jan': '01', 'Feb': '02', 'Mar': '03', 'Apr': '04', 'May': '05', 'Jun': '06', 'Jul': '07',
  47. 'Aug': '08', 'Sep': '09', 'Oct': '10', 'Nov': '11', 'Dec': '12'}
  48. month = month_dict[months]
  49. day = str(data_game[0])
  50. # 比赛时间
  51. time_game = str(item['time_game'])
  52. # 比赛时间,时间戳
  53. ctime = "2019" + "-" + month + "-" + day + " " + time_game + ":00"
  54. r_ctime = "2019" + "-" + month + "-" + day
  55. # 现在时间,时间戳
  56. utime = time.strftime("%Y-%m-%d %H:%M:%S", time.localtime())
  57. expire_time = time.strftime("%Y-%m-%d %H:%M:%S", time.localtime(time.time() + 60))
  58. # 队1分数
  59. score_home = item['score_home']
  60. # 队2分数
  61. score_guest = item['score_guest']
  62. # 第几节
  63. jijie = item['jijie']
  64. # 球队得分
  65. qiudui = item['qiudui']
  66. pt = item['pt']
  67. # 让盘
  68. concedes_dict = item['concedes_dict']
  69. concedes_dict_rule = item['concedes_dict_rule']
  70. # 冠军
  71. kemps_dict = item['kemps_dict']
  72. # 让局
  73. bureaus_dict = item['bureaus_dict']
  74. bureaus_dict_rule = item['bureaus_dict_rule']
  75. # 总局数大小
  76. total_number_dict = item['total_number_dict']
  77. total_number_dict_rule = item['total_number_dict_rule']
  78. # 总决赛单双
  79. odd_evens_dict = item['odd_evens_dict']
  80. odd_evens_dict_rule = item['odd_evens_dict_rule']
  81. us_time = ctime
  82. match_date, match_time, time3 = new_time(ctime)
  83. n_time = out_time(time3, 3)
  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. league_key = ["name_chinese", "kind", "match_mode", "if_stop", "last_time", "lg_id", "source", "uuid"]
  90. league_value = [league_name, "1", "1", "0", last_time, league_id, "hg3535", uuid]
  91. league_data = dict(zip(league_key, league_value))
  92. league_list.append(league_data)
  93. league_dict['data'] = league_list
  94. # print(league_list)
  95. # print(league_dict)
  96. if self.db.hg3535_wq_league.find({'lg_id': league_id}).count() < 1:
  97. res = Helper.async_post(url + '/setLeague', league_dict)
  98. print(res)
  99. self.db.hg3535_wq_league.insert(league_list)
  100. """赛事"""
  101. competition = self.db.hg3535_wq_competition.find_one({"match_id": match_id})
  102. match_list = []
  103. if competition:
  104. print('赛事已存在,修改赛事四状态')
  105. is_morningplate = competition['is_morningplate']
  106. is_rollball = competition['is_rollball']
  107. is_stringscene = competition['is_stringscene']
  108. is_today = competition['is_today']
  109. lmtime = competition['match_time']
  110. if pt == 3:
  111. if is_stringscene != 1 or lmtime != match_time:
  112. match_dict = {"game_code": "wq", "title": "match", "source": "hg3535"}
  113. match_key = ["home_team", "guest_team", "lg_id", "status", "match_id", "match_date", "match_time",
  114. "tag", "source", "is_rollball", "is_morningplate", "is_stringscene", "us_time", "uuid",
  115. "half_match_id", "is_today", 'rule']
  116. match_value = [team_home, team_guest, league_id, 0, match_id, match_date, match_time, tag_number,
  117. "hg3535", is_rollball, is_morningplate, 1, us_time, uuid, 0, is_today, '']
  118. match_data = dict(zip(match_key, match_value))
  119. match_list.append(match_data)
  120. match_dict['data'] = match_list
  121. # print(match_list)
  122. # print(match_dict)
  123. res = Helper.async_post(url + '/setMatch', match_dict)
  124. print(res)
  125. self.db.hg3535_wq_competition.update({'match_id': match_id},
  126. {"$set": {"is_stringscene": 1, 'match_time': match_time}},
  127. upsert=True)
  128. if pt == 2:
  129. if is_morningplate != 1 or lmtime != match_time:
  130. match_dict = {"game_code": "wq", "title": "match", "source": "hg3535"}
  131. match_key = ["home_team", "guest_team", "lg_id", "status", "match_id", "match_date", "match_time",
  132. "tag", "source", "is_rollball", "is_morningplate", "is_stringscene", "us_time", "uuid",
  133. "half_match_id", "is_today", 'rule']
  134. match_value = [team_home, team_guest, league_id, 0, match_id, match_date, match_time, tag_number,
  135. "hg3535", is_rollball, 1, is_stringscene, us_time, uuid, 0, is_today, '']
  136. match_data = dict(zip(match_key, match_value))
  137. match_list.append(match_data)
  138. match_dict['data'] = match_list
  139. # print(match_list)
  140. # print(match_dict)
  141. res = Helper.async_post(url + '/setMatch', match_dict)
  142. print(res)
  143. self.db.hg3535_wq_competition.update({'match_id': match_id},
  144. {"$set": {"is_morningplate": 1, 'match_time': match_time}},
  145. upsert=True)
  146. if pt == 1:
  147. if is_today != 1 or lmtime != match_time:
  148. match_dict = {"game_code": "wq", "title": "match", "source": "hg3535"}
  149. match_kay = ["home_team", "guest_team", "lg_id", "status", "match_id", "match_date", "match_time",
  150. "tag", "source", "is_rollball", "is_morningplate", "is_stringscene", "us_time", "uuid",
  151. "half_match_id", "is_today", 'rule']
  152. match_value = [team_home, team_guest, league_id, 0, match_id, match_date, match_time, tag_number,
  153. "hg3535", is_rollball, is_morningplate, is_stringscene, us_time, uuid, 0, 1, '']
  154. match_data = dict(zip(match_kay, match_value))
  155. match_list.append(match_data)
  156. match_dict['data'] = match_list
  157. # print(match_list)
  158. # print(match_dict)
  159. res = Helper.async_post(url + '/setMatch', match_dict)
  160. print(res)
  161. self.db.hg3535_wq_competition.update({'match_id': match_id},
  162. {"$set": {"is_today": 1, 'match_time': match_time}},
  163. upsert=True)
  164. else:
  165. print("赛事已存在,赛事状态时间未改变,不做修改")
  166. else:
  167. if pt == 3:
  168. is_rollball = 0
  169. is_today = 0
  170. is_morningplate = 0
  171. is_stringscene = 1
  172. elif pt == 2:
  173. is_rollball = 0
  174. is_today = 0
  175. is_morningplate = 1
  176. is_stringscene = 0
  177. else:
  178. is_today = 1
  179. is_rollball = 0
  180. is_morningplate = 0
  181. is_stringscene = 0
  182. match_dict = {"game_code": "wq", "title": "match", "source": "hg3535"}
  183. match_kay = ["home_team", "guest_team", "lg_id", "status", "match_id", "match_date", "match_time", "tag",
  184. "source", "is_rollball", "is_morningplate", "is_stringscene", "us_time", "uuid",
  185. "half_match_id", "is_today", 'rule']
  186. match_value = [team_home, team_guest, league_id, 0, match_id, match_date, match_time, tag_number, "hg3535",
  187. is_rollball, is_morningplate, is_stringscene, us_time, uuid, 0, is_today, '']
  188. match_data = dict(zip(match_kay, match_value))
  189. match_list.append(match_data)
  190. match_dict['data'] = match_list
  191. res = Helper.async_post(url + '/setMatch', match_dict)
  192. print(res)
  193. self.db.hg3535_wq_competition.insert(match_list)
  194. """赔率"""
  195. try:
  196. result = self.db.hg3535_wq_odds.find_one({'match_id': match_id, 'pt': pt})
  197. odds_only_list = result['odds_only']
  198. except:
  199. result = ''
  200. odds_only_list = []
  201. wangqiu = item['wangqiu']
  202. data_list = []
  203. odds_onlys = []
  204. # 让盘
  205. if concedes_dict:
  206. for key, value in concedes_dict.items():
  207. sole_str = 'dishes' + 'concedes' + str(key) + str(match_id) + 'hg3535'
  208. sole = Helper.genearte_MD5(sole_str)
  209. odds_str = 'dishes' + 'concedes' + str(key) + str(match_id) + 'hg3535' + str(concedes_dict_rule[key]) + str(
  210. value)
  211. odds_only = Helper.genearte_MD5(odds_str)
  212. condition = fuhao(concedes_dict_rule[key])
  213. concedes_dict_key = ["match_id", "lg_id", "odds_code", "status", "sort", "p_code", "odds", "condition",
  214. "odds_only", "sole", "source", "type", "team"]
  215. concedes_dict_value = [match_id, league_id, key, '0', '0', 'dishes', value, condition,
  216. odds_only, sole, 'hg3535', '0', '']
  217. concedes_dict_data = dict(zip(concedes_dict_key, concedes_dict_value))
  218. odds_onlys.append(odds_only)
  219. if odds_only not in odds_only_list:
  220. data_list.append(concedes_dict_data)
  221. # 让局
  222. if bureaus_dict:
  223. for key, value in bureaus_dict.items():
  224. sole_str = 'bureau' + str(key) + str(match_id) + 'hg3535'
  225. sole = Helper.genearte_MD5(sole_str)
  226. odds_str = 'bureau' + str(key) + str(match_id) + 'hg3535' + str(bureaus_dict_rule[key]) + str(
  227. value)
  228. odds_only = Helper.genearte_MD5(odds_str)
  229. condition = fuhao(bureaus_dict_rule[key])
  230. bureaus_dict_key = ["match_id", "lg_id", "odds_code", "status", "sort", "p_code", "odds", "condition",
  231. "odds_only", "sole", "source", "type", "team"]
  232. bureaus_dict_value = [match_id, league_id, key, '0', '0', 'bureau', value, condition,
  233. odds_only, sole, 'hg3535', '0', '']
  234. bureaus_dict_data = dict(zip(bureaus_dict_key, bureaus_dict_value))
  235. odds_onlys.append(odds_only)
  236. if odds_only not in odds_only_list:
  237. data_list.append(bureaus_dict_data)
  238. # 总局数大小
  239. if total_number_dict:
  240. for key, value in total_number_dict.items():
  241. sole_str = 'total_number' + str(key) + str(match_id) + 'hg3535'
  242. sole = Helper.genearte_MD5(sole_str)
  243. odds_str = 'total_number' + str(key) + str(match_id) + 'hg3535' + str(
  244. total_number_dict_rule[key]) + str(value)
  245. odds_only = Helper.genearte_MD5(odds_str)
  246. condition = fuhao(total_number_dict_rule[key])
  247. total_number_dict_key = ["match_id", "lg_id", "odds_code", "status", "sort", "p_code", "odds",
  248. "condition",
  249. "odds_only", "sole", "source", "type", "team"]
  250. total_number_dict_value = [match_id, league_id, key, '0', '0', 'total_number', value, condition,
  251. odds_only, sole, 'hg3535', '0', '']
  252. total_number_dict_data = dict(zip(total_number_dict_key, total_number_dict_value))
  253. odds_onlys.append(odds_only)
  254. if odds_only not in odds_only_list:
  255. data_list.append(total_number_dict_data)
  256. # 总决赛单双
  257. if odd_evens_dict:
  258. for key, value in odd_evens_dict.items():
  259. sole_str = 'two_game_sides' + str(key) + str(match_id) + 'hg3535'
  260. sole = Helper.genearte_MD5(sole_str)
  261. odds_str = 'two_game_sides' + str(key) + str(match_id) + 'hg3535' + str(odd_evens_dict_rule[key]) + str(
  262. value)
  263. odds_only = Helper.genearte_MD5(odds_str)
  264. condition = fuhao(odd_evens_dict_rule[key])
  265. odd_evens_dict_key = ["match_id", "lg_id", "odds_code", "status", "sort", "p_code", "odds", "condition",
  266. "odds_only", "sole", "source", "type", "team"]
  267. odd_evens_dict_value = [match_id, league_id, key, '0', '0', 'two_game_sides', value, condition,
  268. odds_only, sole, 'hg3535', '0', '']
  269. odd_evens_dict_data = dict(zip(odd_evens_dict_key, odd_evens_dict_value))
  270. odds_onlys.append(odds_only)
  271. if odds_only not in odds_only_list:
  272. data_list.append(odd_evens_dict_data)
  273. # 冠军
  274. if kemps_dict:
  275. for key, value in kemps_dict.items():
  276. sole_str = 'kemp' + str(key) + str(match_id) + 'hg3535'
  277. sole = Helper.genearte_MD5(sole_str)
  278. odds_str = 'kemp' + str(key) + str(match_id) + 'hg3535' + '2' + str(value)
  279. odds_only = Helper.genearte_MD5(odds_str)
  280. kemps_dict_key = ["match_id", "lg_id", "odds_code", "status", "sort", "p_code", "odds", "condition",
  281. "odds_only", "sole", "source", "type", "team"]
  282. kemps_dict_value = [match_id, league_id, key, '0', '0', 'kemp', value, '',
  283. odds_only, sole, 'hg3535', '0', '']
  284. kemps_dict_data = dict(zip(kemps_dict_key, kemps_dict_value))
  285. odds_onlys.append(odds_only)
  286. if odds_only not in odds_only_list:
  287. data_list.append(kemps_dict_data)
  288. if pt == 3:
  289. ris_stringscene = 1
  290. else:
  291. ris_stringscene = 0
  292. odds_key = ["game_code", "title", "match_id", "lg_id", "data", "source", "odds_only", "tag", "uuid",
  293. "is_stringscene", "utime", "pt"]
  294. odds_value = ["wq", "odds", match_id, league_id, data_list, "hg3535", odds_onlys, tag_number, uuid,
  295. ris_stringscene, utime, pt]
  296. odds_dict = dict(zip(odds_key, odds_value))
  297. # print(odds_dict)
  298. # print(123)
  299. if data_list:
  300. res = Helper.async_post(url + '/setOdds', odds_dict)
  301. print(res)
  302. if '成功' in res:
  303. if result:
  304. self.db.hg3535_wq_odds.update({'match_id': match_id, 'pt': pt}, {
  305. '$set': {"data": data_list, "odds_only": odds_onlys, "utime": utime}}, upsert=True)
  306. else:
  307. self.db.hg3535_wq_odds.insert(odds_dict)