roll_zuqiu.py 34 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582
  1. # import datetime
  2. import datetime
  3. import pymongo
  4. import time
  5. import logging
  6. from twisted.internet import defer, reactor
  7. from ..utils.helper import Helper
  8. from ..settings import M_HOST, M_USER, M_PASSWORD, M_POST, M_DB, LEAGUE_URL, ODDS_URL, MATCH_URL, MATCH_RESULT
  9. # 滚球足球 插入
  10. class Roll_Zuqiupipeline(object):
  11. def open_spider(self, spider):
  12. self.mongo = pymongo.MongoClient(host=M_HOST, username=M_USER, password=M_PASSWORD, port=M_POST)
  13. self.db = self.mongo[M_DB]
  14. @defer.inlineCallbacks
  15. def process_item(self, item, spider):
  16. out = defer.Deferred()
  17. reactor.callInThread(self._do_calculation, item, out)
  18. yield out
  19. # defer.returnValue(item)
  20. # def process_item(self, item, spider):
  21. def _do_calculation(self, item, out):
  22. logger = logging.getLogger(__name__)
  23. pt = 4
  24. # 比赛时间
  25. time_game = str(item['time_game'])
  26. # 现在时间,时间戳
  27. utime = time.strftime("%Y-%m-%d %H:%M:%S", time.localtime(time.time() - 43200))
  28. cdate = datetime.datetime.now().strftime("%Y-%m-%d %H:%M:%S")
  29. match_date = cdate.split(' ')[0]
  30. match_time = cdate.split(' ')[1]
  31. # 比赛id
  32. match_id = item['game_id']
  33. # 联赛id
  34. league_id = item['league_id']
  35. # 联赛name
  36. league_name = item['league_name']
  37. # 主队
  38. team_home = item['team_home']
  39. # 客队
  40. team_guest = item['team_guest']
  41. # number
  42. number = item['number']
  43. score_home = item['score_home']
  44. score_guest = item['score_guest']
  45. all_goal = int(score_home) + int(score_guest)
  46. half_way = item['half_way']
  47. match_score = "{}:{}".format(score_home, score_guest)
  48. last_time = '{}-12-31 23:59:59'.format(datetime.datetime.now().year)
  49. league_list = []
  50. uuid = Helper.genearte_uuid(league_name)
  51. # horn_team = item['horn_team']
  52. if self.db.zq_league35.find({'lg_id': league_id}).count() < 1:
  53. league_dict = {"game_code": "zq", "title": "league", "source": "hg3535"}
  54. league_key = ["name_chinese", "kind", "match_mode", "if_stop", "last_time", "lg_id", "source", "uuid"]
  55. league_value = [league_name, "1", "1", "0", last_time, league_id, "hg3535", uuid]
  56. league_data = dict(zip(league_key, league_value))
  57. league_list.append(league_data)
  58. league_dict['data'] = league_list
  59. res = Helper.async_post(LEAGUE_URL, league_dict)
  60. if res:
  61. if res.get('status') == 1:
  62. self.db.zq_league35.insert(league_data)
  63. logger.info('足球滚球联赛提交成功, {}'.format(res))
  64. logger.info(league_dict)
  65. else:
  66. logger.warning('足球滚球联赛提交失败, {}'.format(res))
  67. logger.warning(league_dict)
  68. else:
  69. logger.warning('足球滚球联赛接口异常提交失败, {}'.format(res))
  70. logger.warning(league_dict)
  71. else:
  72. logger.info('足球滚球联赛已存在, 不存在')
  73. match_identity = Helper.genearte_uuid(team_home + team_guest + match_date)
  74. if self.db.zq_competition35.find({"match_id": match_id, 'is_rollball': 1}).count() < 1:
  75. match_list = []
  76. match_dict = {"game_code": "zq", "title": "match", "source": "hg3535"}
  77. match_kay = ["home_team", "guest_team", "lg_id", "status", "match_id", "match_date", "match_time",
  78. "tag", "source", "is_rollball", "is_morningplate", "is_stringscene", "us_time", "uuid",
  79. "half_match_id", "is_today", "is_horn", 'match_identity']
  80. match_value = [team_home, team_guest, league_id, 1, match_id, match_date, match_time, number,
  81. "hg3535", 1, 0, 0, utime, uuid, 0, 0, 0, match_identity]
  82. match_data = dict(zip(match_kay, match_value))
  83. match_list.append(match_data)
  84. match_dict['data'] = match_list
  85. res = Helper.async_post(MATCH_URL, match_dict)
  86. if res:
  87. if res.get('status') == 1:
  88. self.db.zq_competition35.insert(match_data)
  89. logger.info('足球滚球赛事提交成功, {}'.format(res))
  90. # logger.info(match_data)
  91. else:
  92. logger.warning('足球滚球赛事,提交失败, {}'.format(res))
  93. # logger.warning(match_data)
  94. else:
  95. logger.warning('足球滚球赛事接口异常提交失败, {}'.format(res))
  96. # logger.warning(match_data)
  97. else:
  98. logger.info('足球滚球赛事已存在, 不提交')
  99. p_code = "GS"
  100. # 构建唯一索引
  101. half_size_guest = item["half_size_guest"]
  102. half_size_guest_rule = item["half_size_guest_rule"]
  103. half_size_home = item["half_size_home"]
  104. half_size_home_rule = item["half_size_home_rule"]
  105. data_list = []
  106. odds_onlys = []
  107. # half_size_guest
  108. for index, value in enumerate(half_size_guest):
  109. hash_str = p_code + "gss_h" + str(index) + str(half_size_guest_rule[index]) + str(
  110. value) + "hg3535" + str(match_id)
  111. sole_str = p_code + "gss_h" + str(index) + str(match_id) + "hg3535"
  112. odds_only = Helper.genearte_MD5(hash_str, pt)
  113. sole = Helper.genearte_MD5(sole_str, pt)
  114. half_size_guest_key = ["match_id", "lg_id", "odds_code", "status", "sort", "p_code", "odds", "condition",
  115. "odds_only", "sole", "source", "type", "team"]
  116. condition = half_size_guest_rule[index]
  117. half_size_guest_value = [match_id, league_id, "gss_h", "0", index, p_code, value, condition,
  118. odds_only, sole, "hg3535", "0", ""]
  119. half_size_guest_data = dict(zip(half_size_guest_key, half_size_guest_value))
  120. data_list.append(half_size_guest_data)
  121. # half_size_home
  122. for index, value in enumerate(half_size_home):
  123. hash_str = p_code + "gsb_h" + str(index) + str(half_size_home_rule[index]) + str(
  124. value) + "hg3535" + str(match_id)
  125. sole_str = p_code + "gsb_h" + str(index) + str(match_id) + "hg3535"
  126. odds_only = Helper.genearte_MD5(hash_str, pt)
  127. sole = Helper.genearte_MD5(sole_str, pt)
  128. half_size_home_key = ["match_id", "lg_id", "odds_code", "status", "sort", "p_code", "odds", "condition",
  129. "odds_only", "sole", "source", "type", "team"]
  130. condition = half_size_home_rule[index]
  131. half_size_home_value = [match_id, league_id, "gsb_h", "0", index, p_code, value, condition,
  132. odds_only, sole, "hg3535", "0", ""]
  133. half_size_home_data = dict(zip(half_size_home_key, half_size_home_value))
  134. data_list.append(half_size_home_data)
  135. # 全场场大小
  136. size_guest = item["size_guest"]
  137. size_guest_rule = item["size_guest_rule"]
  138. size_home = item["size_home"]
  139. size_home_rule = item["size_home_rule"]
  140. # size_home
  141. for index, value in enumerate(size_home):
  142. hash_str = p_code + "gsb" + str(index) + str(size_home_rule[index]) + str(value) + "hg3535" + str(
  143. match_id)
  144. sole_str = p_code + "gsb" + str(index) + str(match_id) + "hg3535"
  145. odds_only = Helper.genearte_MD5(hash_str, pt)
  146. sole = Helper.genearte_MD5(sole_str, pt)
  147. size_home_key = ["match_id", "lg_id", "odds_code", "status", "sort", "p_code", "odds", "condition",
  148. "odds_only", "sole", "source", "type", "team"]
  149. condition = size_home_rule[index]
  150. size_home_value = [match_id, league_id, "gsb", "0", index, p_code, value, condition, odds_only,
  151. sole, "hg3535", "0", ""]
  152. size_home_data = dict(zip(size_home_key, size_home_value))
  153. data_list.append(size_home_data)
  154. # size_guest
  155. for index, value in enumerate(size_guest):
  156. hash_str = p_code + "gss" + str(index) + str(size_guest_rule[index]) + str(value) + "hg3535" + str(
  157. match_id)
  158. sole_str = p_code + "gss" + str(index) + str(match_id) + "hg3535"
  159. odds_only = Helper.genearte_MD5(hash_str, pt)
  160. sole = Helper.genearte_MD5(sole_str, pt)
  161. size_guest_key = ["match_id", "lg_id", "odds_code", "status", "sort", "p_code", "odds", "condition",
  162. "odds_only", "sole", "source", "type", "team"]
  163. condition = size_guest_rule[index]
  164. size_guest_value = [match_id, league_id, "gss", "0", index, p_code, value, condition, odds_only,
  165. sole, "hg3535", "0", ""]
  166. size_home_data = dict(zip(size_guest_key, size_guest_value))
  167. data_list.append(size_home_data)
  168. p_code = 'CO'
  169. half_concede_home_rule = item["half_concede_home_rule"]
  170. half_concede_home = item["half_concede_home"]
  171. half_concede_guest_rule = item["half_concede_guest_rule"]
  172. half_concede_guest = item["half_concede_guest"]
  173. # half_concede_home
  174. for index, value in enumerate(half_concede_guest):
  175. hash_str = p_code + "cog_h" + str(index) + str(half_concede_guest_rule[index]) + str(
  176. value) + "hg3535" + str(match_id)
  177. sole_str = p_code + "cog_h" + str(index) + str(match_id) + "hg3535"
  178. odds_only = Helper.genearte_MD5(hash_str, pt)
  179. sole = Helper.genearte_MD5(sole_str, pt)
  180. half_concede_guest_key = ["match_id", "lg_id", "odds_code", "status", "sort", "p_code", "odds", "condition",
  181. "odds_only", "sole", "source", "type", "team"]
  182. condition = half_concede_guest_rule[index]
  183. half_concede_guest_value = [match_id, league_id, "cog_h", "0", index, p_code, value, condition,
  184. odds_only, sole, "hg3535", "0", ""]
  185. half_concede_guest_data = dict(zip(half_concede_guest_key, half_concede_guest_value))
  186. data_list.append(half_concede_guest_data)
  187. # half_concede_home
  188. for index, value in enumerate(half_concede_home):
  189. hash_str = p_code + "coh_h" + str(index) + str(half_concede_home_rule[index]) + str(
  190. value) + "hg3535" + str(match_id)
  191. sole_str = p_code + "coh_h" + str(index) + str(match_id) + "hg3535"
  192. odds_only = Helper.genearte_MD5(hash_str, pt)
  193. sole = Helper.genearte_MD5(sole_str, pt)
  194. half_concede_home_key = ["match_id", "lg_id", "odds_code", "status", "sort", "p_code", "odds", "condition",
  195. "odds_only", "sole", "source", "type", "team"]
  196. condition = half_concede_home_rule[index]
  197. half_concede_home_value = [match_id, league_id, "coh_h", "0", index, p_code, value, condition,
  198. odds_only, sole, "hg3535", "0", ""]
  199. half_concede_home_data = dict(zip(half_concede_home_key, half_concede_home_value))
  200. data_list.append(half_concede_home_data)
  201. concede_guest = item["concede_guest"]
  202. concede_guest_rule = item["concede_guest_rule"]
  203. concede_home = item["concede_home"]
  204. concede_home_rule = item["concede_home_rule"]
  205. # concede_guest
  206. for index, value in enumerate(concede_guest):
  207. hash_str = p_code + "cog" + str(index) + str(concede_guest_rule[index]) + str(
  208. value) + "hg3535" + str(match_id)
  209. sole_str = p_code + "cog" + str(index) + str(match_id) + "hg3535"
  210. odds_only = Helper.genearte_MD5(hash_str, pt)
  211. sole = Helper.genearte_MD5(sole_str, pt)
  212. concede_guest_key = ["match_id", "lg_id", "odds_code", "status", "sort", "p_code", "odds", "condition",
  213. "odds_only", "sole", "source", "type", "team"]
  214. condition = concede_guest_rule[index]
  215. concede_guest_value = [match_id, league_id, "cog", "0", index, p_code, value, condition,
  216. odds_only, sole, "hg3535", "0", ""]
  217. concede_guest_data = dict(zip(concede_guest_key, concede_guest_value))
  218. data_list.append(concede_guest_data)
  219. # concede_home
  220. for index, value in enumerate(concede_home):
  221. hash_str = p_code + "coh" + str(index) + str(concede_home_rule[index]) + str(
  222. value) + "hg3535" + str(match_id)
  223. sole_str = p_code + "coh" + str(index) + str(match_id) + "hg3535"
  224. odds_only = Helper.genearte_MD5(hash_str, pt)
  225. sole = Helper.genearte_MD5(sole_str, pt)
  226. concede_home_key = ["match_id", "lg_id", "odds_code", "status", "sort", "p_code", "odds", "condition",
  227. "odds_only", "sole", "source", "type", "team"]
  228. condition = concede_home_rule[index]
  229. concede_home_value = [match_id, league_id, "coh", "0", index, p_code, value, condition, odds_only,
  230. sole, "hg3535", "0", ""]
  231. concede_guest_data = dict(zip(concede_home_key, concede_home_value))
  232. data_list.append(concede_guest_data)
  233. # 独赢-------------------------------------------------------------------------------------------------------
  234. p_code = 'C'
  235. half_capot_home = item["half_capot_home"]
  236. half_capot_guest = item["half_capot_guest"]
  237. half_capot_dogfall = item["half_capot_dogfall"]
  238. capot_home = item["capot_home"]
  239. capot_guest = item["capot_guest"]
  240. capot_dogfall = item["capot_dogfall"]
  241. # half_capot_home
  242. hash_str = p_code + "ch_h" + '0' + '1' + str(half_capot_home) + "hg3535" + str(match_id)
  243. sole_str = p_code + "ch_h" + '0' + str(match_id) + "hg3535"
  244. odds_only = Helper.genearte_MD5(hash_str, pt)
  245. sole = Helper.genearte_MD5(sole_str, pt)
  246. half_capot_home_key = ["match_id", "lg_id", "odds_code", "status", "sort", "p_code", "odds", "condition",
  247. "odds_only", "sole", "source", "type", "team"]
  248. half_capot_home_value = [match_id, league_id, "ch_h", "0", 0, p_code, half_capot_home, '1',
  249. odds_only, sole, "hg3535", "0", ""]
  250. half_capot_homet_data = dict(zip(half_capot_home_key, half_capot_home_value))
  251. data_list.append(half_capot_homet_data)
  252. # half_capot_guest
  253. hash_str = p_code + "cg_h" + '0' + '2' + str(half_capot_guest) + "hg3535" + str(match_id)
  254. sole_str = p_code + "cg_h" + '0' + str(match_id) + "hg3535"
  255. odds_only = Helper.genearte_MD5(hash_str, pt)
  256. sole = Helper.genearte_MD5(sole_str, pt)
  257. half_capot_guest_key = ["match_id", "lg_id", "odds_code", "status", "sort", "p_code", "odds", "condition",
  258. "odds_only", "sole", "source", "type", "team"]
  259. half_capot_guest_value = [match_id, league_id, "cg_h", "0", 0, p_code, half_capot_guest, '2',
  260. odds_only, sole, "hg3535", "0", ""]
  261. half_capot_guest_data = dict(zip(half_capot_guest_key, half_capot_guest_value))
  262. data_list.append(half_capot_guest_data)
  263. # half_capot_dogfall
  264. hash_str = p_code + "cd_h" + '0' + 'X' + str(half_capot_dogfall) + "hg3535" + str(match_id)
  265. sole_str = p_code + "cd_h" + '0' + str(match_id) + "hg3535"
  266. odds_only = Helper.genearte_MD5(hash_str, pt)
  267. sole = Helper.genearte_MD5(sole_str, pt)
  268. half_capot_dogfall_key = ["match_id", "lg_id", "odds_code", "status", "sort", "p_code", "odds", "condition",
  269. "odds_only", "sole", "source", "type", "team"]
  270. half_capot_dogfall_value = [match_id, league_id, "cd_h", "0", 0, p_code, half_capot_dogfall, 'X',
  271. odds_only, sole, "hg3535", "0", ""]
  272. half_capot_dogfall_data = dict(zip(half_capot_dogfall_key, half_capot_dogfall_value))
  273. data_list.append(half_capot_dogfall_data)
  274. # capot_dogfall
  275. hash_str = p_code + "cd" + '0' + 'X' + str(capot_dogfall) + "hg3535" + str(match_id)
  276. sole_str = p_code + "cd" + '0' + str(match_id) + "hg3535"
  277. odds_only = Helper.genearte_MD5(hash_str, pt)
  278. sole = Helper.genearte_MD5(sole_str, pt)
  279. capot_dogfall_key = ["match_id", "lg_id", "odds_code", "status", "sort", "p_code", "odds", "condition",
  280. "odds_only", "sole", "source", "type", "team"]
  281. capot_dogfall_value = [match_id, league_id, "cd", "0", 0, p_code, capot_dogfall, 'X', odds_only,
  282. sole, "hg3535", "0", ""]
  283. capot_dogfall_data = dict(zip(capot_dogfall_key, capot_dogfall_value))
  284. data_list.append(capot_dogfall_data)
  285. # capot_home
  286. hash_str = p_code + "ch" + '0' + '1' + str(capot_home) + "hg3535" + str(match_id)
  287. sole_str = p_code + "ch" + '0' + str(match_id) + "hg3535"
  288. odds_only = Helper.genearte_MD5(hash_str, pt)
  289. sole = Helper.genearte_MD5(sole_str, pt)
  290. capot_home_key = ["match_id", "lg_id", "odds_code", "status", "sort", "p_code", "odds", "condition",
  291. "odds_only", "sole", "source", "type", "team"]
  292. capot_home_value = [match_id, league_id, "ch", "0", 0, p_code, capot_home, '1',
  293. odds_only, sole, "hg3535", "0", ""]
  294. capot_homet_data = dict(zip(capot_home_key, capot_home_value))
  295. data_list.append(capot_homet_data)
  296. # capot_guest
  297. hash_str = p_code + "cg" + '0' + '2' + str(capot_guest) + "hg3535" + str(match_id)
  298. sole_str = p_code + "cg" + '0' + str(match_id) + "hg3535"
  299. odds_only = Helper.genearte_MD5(hash_str, pt)
  300. sole = Helper.genearte_MD5(sole_str, pt)
  301. capot_guest_key = ["match_id", "lg_id", "odds_code", "status", "sort", "p_code", "odds", "condition",
  302. "odds_only", "sole", "source", "type", "team"]
  303. capot_guest_value = [match_id, league_id, "cg", "0", 0, p_code, capot_guest, '2',
  304. odds_only, sole, "hg3535", "0", ""]
  305. capot_guest_data = dict(zip(capot_guest_key, capot_guest_value))
  306. data_list.append(capot_guest_data)
  307. # 入球数单双--------------------------------------------------------------------------------------------------
  308. p_code = 'TS'
  309. odd_even_odd = item["odd_even_odd"]
  310. odd_even_even = item["odd_even_even"]
  311. half_odd_even_odd = item["half_odd_even_odd"]
  312. half_odd_even_even = item["half_odd_even_even"]
  313. # odd_even_odd
  314. hash_str = p_code + "tss" + '0' + '单' + str(odd_even_odd) + "hg3535" + str(match_id)
  315. sole_str = p_code + "tss" + '0' + str(match_id) + "hg3535"
  316. odds_only = Helper.genearte_MD5(hash_str, pt)
  317. sole = Helper.genearte_MD5(sole_str, pt)
  318. single_key = ["match_id", "lg_id", "odds_code", "status", "sort", "p_code", "odds", "condition",
  319. "odds_only", "sole", "source", "type", "team"]
  320. single_value = [match_id, league_id, "tss", "0", 0, p_code, odd_even_odd, '单',
  321. odds_only, sole, "hg3535", "0", ""]
  322. single_data = dict(zip(single_key, single_value))
  323. data_list.append(single_data)
  324. # odd_even_even
  325. hash_str = p_code + "tsd" + '0' + '双' + str(odd_even_even) + "hg3535" + str(match_id)
  326. sole_str = p_code + "tsd" + '0' + str(match_id) + "hg3535"
  327. odds_only = Helper.genearte_MD5(hash_str, pt)
  328. sole = Helper.genearte_MD5(sole_str, pt)
  329. double_key = ["match_id", "lg_id", "odds_code", "status", "sort", "p_code", "odds", "condition",
  330. "odds_only", "sole", "source", "type", "team"]
  331. double_value = [match_id, league_id, "tsd", "0", 0, p_code, odd_even_even, '双',
  332. odds_only, sole, "hg3535", "0", ""]
  333. double_data = dict(zip(double_key, double_value))
  334. data_list.append(double_data)
  335. # half_odd_even_even
  336. hash_str = p_code + "tsd_h" + '0' + '双' + str(half_odd_even_even) + "hg3535" + str(match_id)
  337. sole_str = p_code + "tsd_h" + '0' + str(match_id) + "hg3535"
  338. odds_only = Helper.genearte_MD5(hash_str, pt)
  339. sole = Helper.genearte_MD5(sole_str, pt)
  340. half_double_key = ["match_id", "lg_id", "odds_code", "status", "sort", "p_code", "odds", "condition",
  341. "odds_only", "sole", "source", "type", "team"]
  342. half_double_value = [match_id, league_id, "tsd_h", "0", 0, p_code, half_odd_even_even, '双',
  343. odds_only, sole, "hg3535", "0", ""]
  344. half_double_data = dict(zip(half_double_key, half_double_value))
  345. data_list.append(half_double_data)
  346. # half_odd_even_odd
  347. hash_str = p_code + "tss_h" + '0' + '单' + str(half_odd_even_odd) + "hg3535" + str(match_id)
  348. sole_str = p_code + "tss_h" + '0' + str(match_id) + "hg3535"
  349. odds_only = Helper.genearte_MD5(hash_str, pt)
  350. sole = Helper.genearte_MD5(sole_str, pt)
  351. half_single_key = ["match_id", "lg_id", "odds_code", "status", "sort", "p_code", "odds", "condition",
  352. "odds_only", "sole", "source", "type", "team"]
  353. half_single_value = [match_id, league_id, "tss_h", "0", 0, p_code, half_odd_even_odd, '单', odds_only,
  354. sole, "hg3535", "0", ""]
  355. half_single_data = dict(zip(half_single_key, half_single_value))
  356. data_list.append(half_single_data)
  357. p_code = 'TG'
  358. # 总入球数 ---------------------------------------------------------------------------------------------------
  359. total_goals = item['total_goal']
  360. total_dict = {'tg0': '0-1', 'tg1': '2-3', 'tg2': '4-6', 'tg3': '7或以上', 'tg0_h': '0', "tg1_h": '1',
  361. "tg2_h": '2', "tg3_h": '3或以上'}
  362. # 全场入球数 单双
  363. for key, value in total_goals.items():
  364. hash_str = p_code + key + '0' + total_dict[key] + str(value) + "hg3535" + str(match_id)
  365. sole_str = p_code + key + '0' + str(match_id) + "hg3535"
  366. odds_only = Helper.genearte_MD5(hash_str, pt)
  367. sole = Helper.genearte_MD5(sole_str, pt)
  368. total_goals_key = ["match_id", "lg_id", "odds_code", "status", "sort", "p_code", "odds", "condition",
  369. "odds_only", "sole", "source", "type", "team"]
  370. total_goals_value = [match_id, league_id, key, "0", 0, p_code, value, total_dict[key], odds_only,
  371. sole, "hg3535", "0", ""]
  372. total_goals_data = dict(zip(total_goals_key, total_goals_value))
  373. data_list.append(total_goals_data)
  374. # 全场半场 ---------------------------------------------------------------------------------------------------
  375. half_fulls = item['half_full']
  376. # p_code, p_id = get_pcode(corner_ball, 'half_full')
  377. p_code = 'HF'
  378. full_dict = {"hfhh": "主主", "hfhd": "主和", "hfhg": "主客", "hfdh": "和主",
  379. "hfdd": "和和", "hfdg": "和客", "hfgh": "客主", "hfgd": "客和", "hfgg": "客客"}
  380. if half_fulls:
  381. for key, value in half_fulls.items():
  382. hash_str = p_code + key + '0' + full_dict[key] + str(value) + "hg3535" + str(match_id)
  383. sole_str = p_code + key + '0' + str(match_id) + "hg3535"
  384. odds_only = Helper.genearte_MD5(hash_str, pt)
  385. sole = Helper.genearte_MD5(sole_str, pt)
  386. half_fulls_key = ["match_id", "lg_id", "odds_code", "status", "sort", "p_code", "odds", "condition",
  387. "odds_only", "sole", "source", "type", "team"]
  388. half_fulls_value = [match_id, league_id, key, "0", 0, p_code, value, full_dict[key], odds_only,
  389. sole, "hg3535", "0", ""]
  390. half_fulls_data = dict(zip(half_fulls_key, half_fulls_value))
  391. data_list.append(half_fulls_data)
  392. # 波胆-------------------------------------------------------------------------------------------------------
  393. p_code = 'B'
  394. bodan_datas = item['bodan_data']
  395. # p_code, p_id = get_pcode(corner_ball, 'bodan')
  396. bodan_dict = {"b10": "1-0", "b20": "2-0", "b21": "2-1", "b30": "3-0", "b31": "3-1", "b32": "3-2",
  397. "b40": "4-0", "b41": "4-1", "b42": "4-2", "b43": "4-3", "b01": "0-1", "b02": "0-2",
  398. "b12": "1-2", "b03": "0-3", "b13": "1-3", "b23": "2-3", "b04": "0-4", "b14": "1-4",
  399. "b24": "2-4", "b34": "3-4", "b00": "0-0", "b11": "1-1", "b22": "2-2", "b33": "3-3",
  400. "b44": "4-4", "bo": "其他", "b10_h": "1-0", "b20_h": "2-0", "b21_h": "2-1", "b30_h": "3-0",
  401. "b31_h": "3-1", "b32_h": "3-2", "b01_h": "0-1", "b02_h": "0-2", "b12_h": "1-2", "b03_h": "0-3",
  402. "b13_h": "1-3", "b23_h": "2-3", "b00_h": "0-0", "b11_h": "1-1", "b22_h": "2-2", "b33_h": "3-3",
  403. "bo_h": "其他"}
  404. if bodan_datas:
  405. for key, value in bodan_datas.items():
  406. hash_str = p_code + key + '0' + bodan_dict[key] + str(value) + "hg3535" + str(match_id)
  407. sole_str = p_code + key + '0' + str(match_id) + "hg3535"
  408. odds_only = Helper.genearte_MD5(hash_str, pt)
  409. sole = Helper.genearte_MD5(sole_str, pt)
  410. bodan_dict_key = ["match_id", "lg_id", "odds_code", "status", "sort", "p_code", "odds", "condition",
  411. "odds_only", "sole", "source", "type", "team"]
  412. bodan_dict_value = [match_id, league_id, key, "0", 0, p_code, value, bodan_dict[key], odds_only,
  413. sole, "hg3535", "0", ""]
  414. bodan_dict_data = dict(zip(bodan_dict_key, bodan_dict_value))
  415. data_list.append(bodan_dict_data)
  416. # 最先进球/最后进球 -------------------------------------------------------------------------------------------
  417. first_last_balls = item['first_last_ball']
  418. p_code = 'FLB'
  419. first_last_dict = {"flbfh": "最先进球", "flbfg": "最先进球", "flblh": "最后进球", "flblg": "最后进球", "flbn": "没有进球"}
  420. if first_last_balls:
  421. for key, value in first_last_balls.items():
  422. hash_str = p_code + key + '0' + first_last_dict[key] + str(value) + "hg3535" + str(match_id)
  423. sole_str = p_code + key + '0' + str(match_id) + "hg3535"
  424. odds_only = Helper.genearte_MD5(hash_str, pt)
  425. sole = Helper.genearte_MD5(sole_str, pt)
  426. first_last_balls_key = ["match_id", "lg_id", "odds_code", "status", "sort", "p_code", "odds",
  427. "condition",
  428. "odds_only", "sole", "source", "type", "team"]
  429. first_last_balls_value = [match_id, league_id, key, "0", 0, p_code, value, first_last_dict[key],
  430. odds_only,
  431. sole, "hg3535", "0", ""]
  432. first_last_balls_data = dict(zip(first_last_balls_key, first_last_balls_value))
  433. data_list.append(first_last_balls_data)
  434. p_code = 'TB'
  435. # 球队得分全场,上半场
  436. full_dicts = item['full_data']
  437. half_dicts = item['half_data']
  438. full_dict_rules = item['full_data_rule']
  439. half_dict_rules = item['half_data_rule']
  440. if full_dicts:
  441. for key, value in full_dicts.items():
  442. hash_str = p_code + key + '0' + full_dict_rules[key] + str(value) + "hg3535" + str(match_id)
  443. sole_str = p_code + key + '0' + str(match_id) + "hg3535"
  444. odds_only = Helper.genearte_MD5(hash_str, pt)
  445. sole = Helper.genearte_MD5(sole_str, pt)
  446. full_dict_rules_key = ["match_id", "lg_id", "odds_code", "status", "sort", "p_code", "odds",
  447. "condition", "odds_only", "sole", "source", "type", "team"]
  448. full_dict_rules_value = [match_id, league_id, key, "0", 0, p_code, value, full_dict_rules[key],
  449. odds_only, sole, "hg3535", "0", ""]
  450. full_dict_rules_data = dict(zip(full_dict_rules_key, full_dict_rules_value))
  451. data_list.append(full_dict_rules_data)
  452. if half_dicts:
  453. for key, value in half_dicts.items():
  454. hash_str = p_code + key + '0' + half_dict_rules[key] + str(value) + "hg3535" + str(match_id)
  455. sole_str = p_code + key + '0' + str(match_id) + "hg3535"
  456. odds_only = Helper.genearte_MD5(hash_str, pt)
  457. sole = Helper.genearte_MD5(sole_str, pt)
  458. half_dicts_key = ["match_id", "lg_id", "odds_code", "status", "sort", "p_code", "odds",
  459. "condition", "odds_only", "sole", "source", "type", "team"]
  460. half_dicts_value = [match_id, league_id, key, "0", 0, p_code, value, half_dict_rules[key],
  461. odds_only, sole, "hg3535", "0", ""]
  462. half_dicts_data = dict(zip(half_dicts_key, half_dicts_value))
  463. data_list.append(half_dicts_data)
  464. p_code = 'CB'
  465. # 球队得分全场,上半场
  466. horn_ou_dict = item['horn_ou_dict']
  467. horn_ou_dict_rule = item['horn_ou_dict_rule']
  468. horn_oe_dict = item['horn_oe_dict']
  469. horn_oe_dict_rule = item['horn_oe_dict_rule']
  470. if horn_ou_dict:
  471. for key, value in horn_ou_dict.items():
  472. hash_str = p_code + key + '0' + horn_ou_dict_rule[key] + str(value) + "hg3535" + str(match_id)
  473. sole_str = p_code + key + '0' + str(match_id) + "hg3535"
  474. odds_only = Helper.genearte_MD5(hash_str, pt)
  475. sole = Helper.genearte_MD5(sole_str, pt)
  476. horn_ou_key = ["match_id", "lg_id", "odds_code", "status", "sort", "p_code", "odds",
  477. "condition", "odds_only", "sole", "source", "type", "team"]
  478. horn_ou_value = [match_id, league_id, key, "0", 0, p_code, value, horn_ou_dict_rule[key],
  479. odds_only, sole, "hg3535", "0", ""]
  480. horn_ou_data = dict(zip(horn_ou_key, horn_ou_value))
  481. data_list.append(horn_ou_data)
  482. if horn_oe_dict:
  483. for key, value in horn_oe_dict.items():
  484. hash_str = p_code + key + '0' + horn_oe_dict_rule[key] + str(value) + "hg3535" + str(match_id)
  485. sole_str = p_code + key + '0' + str(match_id) + "hg3535"
  486. odds_only = Helper.genearte_MD5(hash_str, pt)
  487. sole = Helper.genearte_MD5(sole_str, pt)
  488. horn_oe_key = ["match_id", "lg_id", "odds_code", "status", "sort", "p_code", "odds",
  489. "condition", "odds_only", "sole", "source", "type", "team"]
  490. horn_oe_value = [match_id, league_id, key, "0", 0, p_code, value, horn_oe_dict_rule[key],
  491. odds_only, sole, "hg3535", "0", ""]
  492. horn_oe_data = dict(zip(horn_oe_key, horn_oe_value))
  493. data_list.append(horn_oe_data)
  494. odds_key = ["game_code", "title", "match_id", "lg_id", "data", "source", "odds_only", "tag", "uuid",
  495. "is_stringscene", "utime", "pt", 'match_identity']
  496. odds_value = ["zq", "odds", match_id, league_id, data_list, "hg3535", odds_onlys, number, uuid,
  497. 0, cdate, pt, match_identity]
  498. odds_dict = dict(zip(odds_key, odds_value))
  499. if data_list:
  500. res = Helper.async_post(ODDS_URL, odds_dict)
  501. if res:
  502. if res.get('status') == 1:
  503. logger.info('足球滚球详细赔率提交成功, {}'.format(res))
  504. # logger.info(odds_dict)
  505. else:
  506. logger.warning('足球滚球详细赔率提交失败, {}'.format(res))
  507. # logger.warning(odds_dict)
  508. else:
  509. logger.warning('足球滚球详细赔率接口异常,提交失败, {}'.format(res))
  510. # logger.warning(odds_dict)
  511. else:
  512. logger.info('足球滚球详细赔率列表为空')
  513. data_list = []
  514. zq_rball = {"home_team": team_home, "guest_team": team_guest,
  515. "lg_id": league_id, "home_rate": 0,
  516. "guest_rate": 0, "home_score": score_home,
  517. "guest_score": score_guest, "all_goal": all_goal, "status": 1,
  518. "first_score": "", "last_score": "", "match_score": match_score, "uuid": uuid,
  519. "match_winer": "", "match_time": time_game, 'match_identity': match_identity,
  520. "match_process": half_way, "tag": number,
  521. "match_id": match_id, "p_code": ""}
  522. data_list.append(zq_rball)
  523. r_data_dict = {
  524. "game_code": "zq",
  525. "title": "match_result_r",
  526. "source": "hg3535",
  527. "data": data_list
  528. }
  529. if data_list:
  530. try:
  531. res = Helper.async_post(MATCH_RESULT, r_data_dict)
  532. if res:
  533. if res.get('status') == 1:
  534. logger.info('足球滚球结果记录提交成功, {}'.format(res))
  535. self.db.zq_match_result35.insert(zq_rball)
  536. # logger.info(r_data_dict)
  537. else:
  538. logger.warning('足球滚球结果记录提交失败, {}'.format(res))
  539. # logger.warning(r_data_dict)
  540. else:
  541. logger.warning('足球滚球结果记录接口异常,提交失败, {}'.format(res))
  542. # logger.warning(r_data_dict)
  543. except Exception as e:
  544. logger.warning('滚球数据接口异常,提交失败, {}'.format(e))
  545. reactor.callFromThread(out.callback, item)