roll_zuqiu.py 68 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114
  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())
  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 + 'hg3535')
  51. horn_team = item['horn_team']
  52. if self.db.zq_league35.find({'league_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. # self.db.zq_league35.update({'lg_id': league_id}, {'$set': league_data},
  64. # upsert=True)
  65. logger.info('足球滚球联赛提交成功, {}'.format(res))
  66. logger.info(league_dict)
  67. else:
  68. logger.warning('足球滚球联赛提交失败, {}'.format(res))
  69. logger.warning(league_dict)
  70. else:
  71. logger.warning('足球滚球联赛接口异常提交失败, {}'.format(res))
  72. logger.warning(league_dict)
  73. else:
  74. logger.info('足球滚球联赛已存在, 不存在')
  75. if self.db.zq_competition35.find({"match_id": match_id, 'is_rollball': 1}).count() < 1:
  76. match_list = []
  77. match_dict = {"game_code": "zq", "title": "match", "source": "hg3535"}
  78. match_kay = ["home_team", "guest_team", "lg_id", "status", "match_id", "match_date", "match_time",
  79. "tag", "source", "is_rollball", "is_morningplate", "is_stringscene", "us_time", "uuid",
  80. "half_match_id", "is_today", "is_horn"]
  81. match_value = [team_home, team_guest, league_id, 1, match_id, match_date, match_time, number,
  82. "hg3535", 1, 0, 0, utime, uuid, 0, 0, 0]
  83. match_data = dict(zip(match_kay, match_value))
  84. match_list.append(match_data)
  85. match_dict['data'] = match_list
  86. res = Helper.async_post(MATCH_URL, match_dict)
  87. if res:
  88. if res.get('status') == 1:
  89. self.db.zq_competition35.insert(match_data)
  90. # self.db.zq_competition35.update({'match_id': match_id, 'is_rollball': 1}, {'$set': match_data},
  91. # upsert=True)
  92. logger.info('足球滚球赛事提交成功, {}'.format(res))
  93. logger.info(match_data)
  94. else:
  95. logger.warning('足球滚球赛事,提交失败, {}'.format(res))
  96. logger.warning(match_data)
  97. else:
  98. logger.warning('足球滚球赛事接口异常提交失败, {}'.format(res))
  99. logger.warning(match_data)
  100. else:
  101. logger.info('足球滚球赛事已存在, 不提交')
  102. p_code = "GS"
  103. # 构建唯一索引
  104. half_size_guest = item["half_size_guest"]
  105. half_size_guest_rule = item["half_size_guest_rule"]
  106. half_size_home = item["half_size_home"]
  107. half_size_home_rule = item["half_size_home_rule"]
  108. data_list = []
  109. odds_onlys = []
  110. # half_size_guest
  111. for index, value in enumerate(half_size_guest):
  112. hash_str = p_code + "gss_h" + str(index) + str(half_size_guest_rule[index]) + str(
  113. value) + "hg3535" + str(match_id)
  114. sole_str = p_code + "gss_h" + str(index) + str(match_id) + "hg3535"
  115. odds_only = Helper.genearte_MD5(hash_str, pt)
  116. sole = Helper.genearte_MD5(sole_str, pt)
  117. half_size_guest_key = ["match_id", "lg_id", "odds_code", "status", "sort", "p_code", "odds", "condition",
  118. "odds_only", "sole", "source", "type", "team"]
  119. condition = half_size_guest_rule[index]
  120. half_size_guest_value = [match_id, league_id, "gss_h", "0", index, p_code, value, condition,
  121. odds_only, sole, "hg3535", "0", ""]
  122. half_size_guest_data = dict(zip(half_size_guest_key, half_size_guest_value))
  123. data_list.append(half_size_guest_data)
  124. # half_size_home
  125. for index, value in enumerate(half_size_home):
  126. hash_str = p_code + "gsb_h" + str(index) + str(half_size_home_rule[index]) + str(
  127. value) + "hg3535" + str(match_id)
  128. sole_str = p_code + "gsb_h" + str(index) + str(match_id) + "hg3535"
  129. odds_only = Helper.genearte_MD5(hash_str, pt)
  130. sole = Helper.genearte_MD5(sole_str, pt)
  131. half_size_home_key = ["match_id", "lg_id", "odds_code", "status", "sort", "p_code", "odds", "condition",
  132. "odds_only", "sole", "source", "type", "team"]
  133. condition = half_size_home_rule[index]
  134. half_size_home_value = [match_id, league_id, "gsb_h", "0", index, p_code, value, condition,
  135. odds_only, sole, "hg3535", "0", ""]
  136. half_size_home_data = dict(zip(half_size_home_key, half_size_home_value))
  137. data_list.append(half_size_home_data)
  138. # 全场场大小
  139. size_guest = item["size_guest"]
  140. size_guest_rule = item["size_guest_rule"]
  141. size_home = item["size_home"]
  142. size_home_rule = item["size_home_rule"]
  143. # size_home
  144. for index, value in enumerate(size_home):
  145. hash_str = p_code + "gsb" + str(index) + str(size_home_rule[index]) + str(value) + "hg3535" + str(
  146. match_id)
  147. sole_str = p_code + "gsb" + str(index) + str(match_id) + "hg3535"
  148. odds_only = Helper.genearte_MD5(hash_str, pt)
  149. sole = Helper.genearte_MD5(sole_str, pt)
  150. size_home_key = ["match_id", "lg_id", "odds_code", "status", "sort", "p_code", "odds", "condition",
  151. "odds_only", "sole", "source", "type", "team"]
  152. condition = size_home_rule[index]
  153. size_home_value = [match_id, league_id, "gsb", "0", index, p_code, value, condition, odds_only,
  154. sole, "hg3535", "0", ""]
  155. size_home_data = dict(zip(size_home_key, size_home_value))
  156. data_list.append(size_home_data)
  157. # size_guest
  158. for index, value in enumerate(size_guest):
  159. hash_str = p_code + "gss" + str(index) + str(size_guest_rule[index]) + str(value) + "hg3535" + str(
  160. match_id)
  161. sole_str = p_code + "gss" + str(index) + str(match_id) + "hg3535"
  162. odds_only = Helper.genearte_MD5(hash_str, pt)
  163. sole = Helper.genearte_MD5(sole_str, pt)
  164. size_guest_key = ["match_id", "lg_id", "odds_code", "status", "sort", "p_code", "odds", "condition",
  165. "odds_only", "sole", "source", "type", "team"]
  166. condition = size_guest_rule[index]
  167. size_guest_value = [match_id, league_id, "gss", "0", index, p_code, value, condition, odds_only,
  168. sole, "hg3535", "0", ""]
  169. size_home_data = dict(zip(size_guest_key, size_guest_value))
  170. data_list.append(size_home_data)
  171. p_code = 'CO'
  172. half_concede_home_rule = item["half_concede_home_rule"]
  173. half_concede_home = item["half_concede_home"]
  174. half_concede_guest_rule = item["half_concede_guest_rule"]
  175. half_concede_guest = item["half_concede_guest"]
  176. # half_concede_home
  177. for index, value in enumerate(half_concede_guest):
  178. hash_str = p_code + "cog_h" + str(index) + str(half_concede_guest_rule[index]) + str(
  179. value) + "hg3535" + str(match_id)
  180. sole_str = p_code + "cog_h" + str(index) + str(match_id) + "hg3535"
  181. odds_only = Helper.genearte_MD5(hash_str, pt)
  182. sole = Helper.genearte_MD5(sole_str, pt)
  183. half_concede_guest_key = ["match_id", "lg_id", "odds_code", "status", "sort", "p_code", "odds", "condition",
  184. "odds_only", "sole", "source", "type", "team"]
  185. condition = half_concede_guest_rule[index]
  186. half_concede_guest_value = [match_id, league_id, "cog_h", "0", index, p_code, value, condition,
  187. odds_only, sole, "hg3535", "0", ""]
  188. half_concede_guest_data = dict(zip(half_concede_guest_key, half_concede_guest_value))
  189. data_list.append(half_concede_guest_data)
  190. # half_concede_home
  191. for index, value in enumerate(half_concede_home):
  192. hash_str = p_code + "coh_h" + str(index) + str(half_concede_home_rule[index]) + str(
  193. value) + "hg3535" + str(match_id)
  194. sole_str = p_code + "coh_h" + str(index) + str(match_id) + "hg3535"
  195. odds_only = Helper.genearte_MD5(hash_str, pt)
  196. sole = Helper.genearte_MD5(sole_str, pt)
  197. half_concede_home_key = ["match_id", "lg_id", "odds_code", "status", "sort", "p_code", "odds", "condition",
  198. "odds_only", "sole", "source", "type", "team"]
  199. condition = half_concede_home_rule[index]
  200. half_concede_home_value = [match_id, league_id, "coh_h", "0", index, p_code, value, condition,
  201. odds_only, sole, "hg3535", "0", ""]
  202. half_concede_home_data = dict(zip(half_concede_home_key, half_concede_home_value))
  203. data_list.append(half_concede_home_data)
  204. concede_guest = item["concede_guest"]
  205. concede_guest_rule = item["concede_guest_rule"]
  206. concede_home = item["concede_home"]
  207. concede_home_rule = item["concede_home_rule"]
  208. # concede_guest
  209. for index, value in enumerate(concede_guest):
  210. hash_str = p_code + "cog" + str(index) + str(concede_guest_rule[index]) + str(
  211. value) + "hg3535" + str(match_id)
  212. sole_str = p_code + "cog" + str(index) + str(match_id) + "hg3535"
  213. odds_only = Helper.genearte_MD5(hash_str, pt)
  214. sole = Helper.genearte_MD5(sole_str, pt)
  215. concede_guest_key = ["match_id", "lg_id", "odds_code", "status", "sort", "p_code", "odds", "condition",
  216. "odds_only", "sole", "source", "type", "team"]
  217. condition = concede_guest_rule[index]
  218. concede_guest_value = [match_id, league_id, "cog", "0", index, p_code, value, condition,
  219. odds_only, sole, "hg3535", "0", ""]
  220. concede_guest_data = dict(zip(concede_guest_key, concede_guest_value))
  221. data_list.append(concede_guest_data)
  222. # concede_home
  223. for index, value in enumerate(concede_home):
  224. hash_str = p_code + "coh" + str(index) + str(concede_home_rule[index]) + str(
  225. value) + "hg3535" + str(match_id)
  226. sole_str = p_code + "coh" + str(index) + str(match_id) + "hg3535"
  227. odds_only = Helper.genearte_MD5(hash_str, pt)
  228. sole = Helper.genearte_MD5(sole_str, pt)
  229. concede_home_key = ["match_id", "lg_id", "odds_code", "status", "sort", "p_code", "odds", "condition",
  230. "odds_only", "sole", "source", "type", "team"]
  231. condition = concede_home_rule[index]
  232. concede_home_value = [match_id, league_id, "coh", "0", index, p_code, value, condition, odds_only,
  233. sole, "hg3535", "0", ""]
  234. concede_guest_data = dict(zip(concede_home_key, concede_home_value))
  235. data_list.append(concede_guest_data)
  236. # 独赢-------------------------------------------------------------------------------------------------------
  237. p_code = 'C'
  238. half_capot_home = item["half_capot_home"]
  239. half_capot_guest = item["half_capot_guest"]
  240. half_capot_dogfall = item["half_capot_dogfall"]
  241. capot_home = item["capot_home"]
  242. capot_guest = item["capot_guest"]
  243. capot_dogfall = item["capot_dogfall"]
  244. # half_capot_home
  245. hash_str = p_code + "ch_h" + '0' + '1' + str(half_capot_home) + "hg3535" + str(match_id)
  246. sole_str = p_code + "ch_h" + '0' + str(match_id) + "hg3535"
  247. odds_only = Helper.genearte_MD5(hash_str, pt)
  248. sole = Helper.genearte_MD5(sole_str, pt)
  249. half_capot_home_key = ["match_id", "lg_id", "odds_code", "status", "sort", "p_code", "odds", "condition",
  250. "odds_only", "sole", "source", "type", "team"]
  251. half_capot_home_value = [match_id, league_id, "ch_h", "0", 0, p_code, half_capot_home, '1',
  252. odds_only, sole, "hg3535", "0", ""]
  253. half_capot_homet_data = dict(zip(half_capot_home_key, half_capot_home_value))
  254. data_list.append(half_capot_homet_data)
  255. # half_capot_guest
  256. hash_str = p_code + "cg_h" + '0' + '2' + str(half_capot_guest) + "hg3535" + str(match_id)
  257. sole_str = p_code + "cg_h" + '0' + str(match_id) + "hg3535"
  258. odds_only = Helper.genearte_MD5(hash_str, pt)
  259. sole = Helper.genearte_MD5(sole_str, pt)
  260. half_capot_guest_key = ["match_id", "lg_id", "odds_code", "status", "sort", "p_code", "odds", "condition",
  261. "odds_only", "sole", "source", "type", "team"]
  262. half_capot_guest_value = [match_id, league_id, "cg_h", "0", 0, p_code, half_capot_guest, '2',
  263. odds_only, sole, "hg3535", "0", ""]
  264. half_capot_guest_data = dict(zip(half_capot_guest_key, half_capot_guest_value))
  265. data_list.append(half_capot_guest_data)
  266. # half_capot_dogfall
  267. hash_str = p_code + "cd_h" + '0' + 'X' + str(half_capot_dogfall) + "hg3535" + str(match_id)
  268. sole_str = p_code + "cd_h" + '0' + str(match_id) + "hg3535"
  269. odds_only = Helper.genearte_MD5(hash_str, pt)
  270. sole = Helper.genearte_MD5(sole_str, pt)
  271. half_capot_dogfall_key = ["match_id", "lg_id", "odds_code", "status", "sort", "p_code", "odds", "condition",
  272. "odds_only", "sole", "source", "type", "team"]
  273. half_capot_dogfall_value = [match_id, league_id, "cd_h", "0", 0, p_code, half_capot_dogfall, 'X',
  274. odds_only, sole, "hg3535", "0", ""]
  275. half_capot_dogfall_data = dict(zip(half_capot_dogfall_key, half_capot_dogfall_value))
  276. data_list.append(half_capot_dogfall_data)
  277. # capot_dogfall
  278. hash_str = p_code + "cd" + '0' + 'X' + str(capot_dogfall) + "hg3535" + str(match_id)
  279. sole_str = p_code + "cd" + '0' + str(match_id) + "hg3535"
  280. odds_only = Helper.genearte_MD5(hash_str, pt)
  281. sole = Helper.genearte_MD5(sole_str, pt)
  282. capot_dogfall_key = ["match_id", "lg_id", "odds_code", "status", "sort", "p_code", "odds", "condition",
  283. "odds_only", "sole", "source", "type", "team"]
  284. capot_dogfall_value = [match_id, league_id, "cd", "0", 0, p_code, capot_dogfall, 'X', odds_only,
  285. sole, "hg3535", "0", ""]
  286. capot_dogfall_data = dict(zip(capot_dogfall_key, capot_dogfall_value))
  287. data_list.append(capot_dogfall_data)
  288. # capot_home
  289. hash_str = p_code + "ch" + '0' + '1' + str(capot_home) + "hg3535" + str(match_id)
  290. sole_str = p_code + "ch" + '0' + str(match_id) + "hg3535"
  291. odds_only = Helper.genearte_MD5(hash_str, pt)
  292. sole = Helper.genearte_MD5(sole_str, pt)
  293. capot_home_key = ["match_id", "lg_id", "odds_code", "status", "sort", "p_code", "odds", "condition",
  294. "odds_only", "sole", "source", "type", "team"]
  295. capot_home_value = [match_id, league_id, "ch", "0", 0, p_code, capot_home, '1',
  296. odds_only, sole, "hg3535", "0", ""]
  297. capot_homet_data = dict(zip(capot_home_key, capot_home_value))
  298. data_list.append(capot_homet_data)
  299. # capot_guest
  300. hash_str = p_code + "cg" + '0' + '2' + str(capot_guest) + "hg3535" + str(match_id)
  301. sole_str = p_code + "cg" + '0' + str(match_id) + "hg3535"
  302. odds_only = Helper.genearte_MD5(hash_str, pt)
  303. sole = Helper.genearte_MD5(sole_str, pt)
  304. capot_guest_key = ["match_id", "lg_id", "odds_code", "status", "sort", "p_code", "odds", "condition",
  305. "odds_only", "sole", "source", "type", "team"]
  306. capot_guest_value = [match_id, league_id, "cg", "0", 0, p_code, capot_guest, '2',
  307. odds_only, sole, "hg3535", "0", ""]
  308. capot_guest_data = dict(zip(capot_guest_key, capot_guest_value))
  309. data_list.append(capot_guest_data)
  310. # 入球数单双--------------------------------------------------------------------------------------------------
  311. p_code = 'TS'
  312. odd_even_odd = item["odd_even_odd"]
  313. odd_even_even = item["odd_even_even"]
  314. half_odd_even_odd = item["half_odd_even_odd"]
  315. half_odd_even_even = item["half_odd_even_even"]
  316. # odd_even_odd
  317. hash_str = p_code + "tss" + '0' + '单' + str(odd_even_odd) + "hg3535" + str(match_id)
  318. sole_str = p_code + "tss" + '0' + str(match_id) + "hg3535"
  319. odds_only = Helper.genearte_MD5(hash_str, pt)
  320. sole = Helper.genearte_MD5(sole_str, pt)
  321. single_key = ["match_id", "lg_id", "odds_code", "status", "sort", "p_code", "odds", "condition",
  322. "odds_only", "sole", "source", "type", "team"]
  323. single_value = [match_id, league_id, "tss", "0", 0, p_code, odd_even_odd, '单',
  324. odds_only, sole, "hg3535", "0", ""]
  325. single_data = dict(zip(single_key, single_value))
  326. data_list.append(single_data)
  327. # odd_even_even
  328. hash_str = p_code + "tsd" + '0' + '双' + str(odd_even_even) + "hg3535" + str(match_id)
  329. sole_str = p_code + "tsd" + '0' + str(match_id) + "hg3535"
  330. odds_only = Helper.genearte_MD5(hash_str, pt)
  331. sole = Helper.genearte_MD5(sole_str, pt)
  332. double_key = ["match_id", "lg_id", "odds_code", "status", "sort", "p_code", "odds", "condition",
  333. "odds_only", "sole", "source", "type", "team"]
  334. double_value = [match_id, league_id, "tsd", "0", 0, p_code, odd_even_even, '双',
  335. odds_only, sole, "hg3535", "0", ""]
  336. double_data = dict(zip(double_key, double_value))
  337. data_list.append(double_data)
  338. # half_odd_even_even
  339. hash_str = p_code + "tsd_h" + '0' + '双' + str(half_odd_even_even) + "hg3535" + str(match_id)
  340. sole_str = p_code + "tsd_h" + '0' + str(match_id) + "hg3535"
  341. odds_only = Helper.genearte_MD5(hash_str, pt)
  342. sole = Helper.genearte_MD5(sole_str, pt)
  343. half_double_key = ["match_id", "lg_id", "odds_code", "status", "sort", "p_code", "odds", "condition",
  344. "odds_only", "sole", "source", "type", "team"]
  345. half_double_value = [match_id, league_id, "tsd_h", "0", 0, p_code, half_odd_even_even, '双',
  346. odds_only, sole, "hg3535", "0", ""]
  347. half_double_data = dict(zip(half_double_key, half_double_value))
  348. data_list.append(half_double_data)
  349. # half_odd_even_odd
  350. hash_str = p_code + "tss_h" + '0' + '单' + str(half_odd_even_odd) + "hg3535" + str(match_id)
  351. sole_str = p_code + "tss_h" + '0' + str(match_id) + "hg3535"
  352. odds_only = Helper.genearte_MD5(hash_str, pt)
  353. sole = Helper.genearte_MD5(sole_str, pt)
  354. half_single_key = ["match_id", "lg_id", "odds_code", "status", "sort", "p_code", "odds", "condition",
  355. "odds_only", "sole", "source", "type", "team"]
  356. half_single_value = [match_id, league_id, "tss_h", "0", 0, p_code, half_odd_even_odd, '单', odds_only,
  357. sole, "hg3535", "0", ""]
  358. half_single_data = dict(zip(half_single_key, half_single_value))
  359. data_list.append(half_single_data)
  360. p_code = 'TG'
  361. # 总入球数 ---------------------------------------------------------------------------------------------------
  362. total_goals = item['total_goal']
  363. total_dict = {'tg0': '0-1', 'tg1': '2-3', 'tg2': '4-6', 'tg3': '7或以上', 'tg0_h': '0', "tg1_h": '1',
  364. "tg2_h": '2', "tg3_h": '3或以上'}
  365. # 全场入球数 单双
  366. for key, value in total_goals.items():
  367. hash_str = p_code + key + '0' + total_dict[key] + str(value) + "hg3535" + str(match_id)
  368. sole_str = p_code + key + '0' + str(match_id) + "hg3535"
  369. odds_only = Helper.genearte_MD5(hash_str, pt)
  370. sole = Helper.genearte_MD5(sole_str, pt)
  371. total_goals_key = ["match_id", "lg_id", "odds_code", "status", "sort", "p_code", "odds", "condition",
  372. "odds_only", "sole", "source", "type", "team"]
  373. total_goals_value = [match_id, league_id, key, "0", 0, p_code, value, total_dict[key], odds_only,
  374. sole, "hg3535", "0", ""]
  375. total_goals_data = dict(zip(total_goals_key, total_goals_value))
  376. data_list.append(total_goals_data)
  377. # 全场半场 ---------------------------------------------------------------------------------------------------
  378. half_fulls = item['half_full']
  379. # p_code, p_id = get_pcode(corner_ball, 'half_full')
  380. p_code = 'HF'
  381. full_dict = {"hfhh": "主主", "hfhd": "主和", "hfhg": "主客", "hfdh": "和主",
  382. "hfdd": "和和", "hfdg": "和客", "hfgh": "客主", "hfgd": "客和", "hfgg": "客客"}
  383. if half_fulls:
  384. for key, value in half_fulls.items():
  385. hash_str = p_code + key + '0' + full_dict[key] + str(value) + "hg3535" + str(match_id)
  386. sole_str = p_code + key + '0' + str(match_id) + "hg3535"
  387. odds_only = Helper.genearte_MD5(hash_str, pt)
  388. sole = Helper.genearte_MD5(sole_str, pt)
  389. half_fulls_key = ["match_id", "lg_id", "odds_code", "status", "sort", "p_code", "odds", "condition",
  390. "odds_only", "sole", "source", "type", "team"]
  391. half_fulls_value = [match_id, league_id, key, "0", 0, p_code, value, full_dict[key], odds_only,
  392. sole, "hg3535", "0", ""]
  393. half_fulls_data = dict(zip(half_fulls_key, half_fulls_value))
  394. data_list.append(half_fulls_data)
  395. # 波胆-------------------------------------------------------------------------------------------------------
  396. p_code = 'B'
  397. bodan_datas = item['bodan_data']
  398. # p_code, p_id = get_pcode(corner_ball, 'bodan')
  399. bodan_dict = {"b10": "1-0", "b20": "2-0", "b21": "2-1", "b30": "3-0", "b31": "3-1", "b32": "3-2",
  400. "b40": "4-0", "b41": "4-1", "b42": "4-2", "b43": "4-3", "b01": "0-1", "b02": "0-2",
  401. "b12": "1-2", "b03": "0-3", "b13": "1-3", "b23": "2-3", "b04": "0-4", "b14": "1-4",
  402. "b24": "2-4", "b34": "3-4", "b00": "0-0", "b11": "1-1", "b22": "2-2", "b33": "3-3",
  403. "b44": "4-4", "bo": "其他", "b10_h": "1-0", "b20_h": "2-0", "b21_h": "2-1", "b30_h": "3-0",
  404. "b31_h": "3-1", "b32_h": "3-2", "b01_h": "0-1", "b02_h": "0-2", "b12_h": "1-2", "b03_h": "0-3",
  405. "b13_h": "1-3", "b23_h": "2-3", "b00_h": "0-0", "b11_h": "1-1", "b22_h": "2-2", "b33_h": "3-3",
  406. "bo_h": "其他"}
  407. if bodan_datas:
  408. for key, value in bodan_datas.items():
  409. hash_str = p_code + key + '0' + bodan_dict[key] + str(value) + "hg3535" + str(match_id)
  410. sole_str = p_code + key + '0' + str(match_id) + "hg3535"
  411. odds_only = Helper.genearte_MD5(hash_str, pt)
  412. sole = Helper.genearte_MD5(sole_str, pt)
  413. bodan_dict_key = ["match_id", "lg_id", "odds_code", "status", "sort", "p_code", "odds", "condition",
  414. "odds_only", "sole", "source", "type", "team"]
  415. bodan_dict_value = [match_id, league_id, key, "0", 0, p_code, value, bodan_dict[key], odds_only,
  416. sole, "hg3535", "0", ""]
  417. bodan_dict_data = dict(zip(bodan_dict_key, bodan_dict_value))
  418. data_list.append(bodan_dict_data)
  419. # 最先进球/最后进球 -------------------------------------------------------------------------------------------
  420. first_last_balls = item['first_last_ball']
  421. p_code = 'FLB'
  422. first_last_dict = {"flbfh": "最先进球", "flbfg": "最先进球", "flblh": "最后进球", "flblg": "最后进球", "flbn": "没有进球"}
  423. if first_last_balls:
  424. for key, value in first_last_balls.items():
  425. hash_str = p_code + key + '0' + first_last_dict[key] + str(value) + "hg3535" + str(match_id)
  426. sole_str = p_code + key + '0' + str(match_id) + "hg3535"
  427. odds_only = Helper.genearte_MD5(hash_str, pt)
  428. sole = Helper.genearte_MD5(sole_str, pt)
  429. first_last_balls_key = ["match_id", "lg_id", "odds_code", "status", "sort", "p_code", "odds",
  430. "condition",
  431. "odds_only", "sole", "source", "type", "team"]
  432. first_last_balls_value = [match_id, league_id, key, "0", 0, p_code, value, first_last_dict[key],
  433. odds_only,
  434. sole, "hg3535", "0", ""]
  435. first_last_balls_data = dict(zip(first_last_balls_key, first_last_balls_value))
  436. data_list.append(first_last_balls_data)
  437. p_code = 'TB'
  438. # 球队得分全场,上半场
  439. full_dicts = item['full_data']
  440. half_dicts = item['half_data']
  441. full_dict_rules = item['full_data_rule']
  442. half_dict_rules = item['half_data_rule']
  443. if full_dicts:
  444. for key, value in full_dicts.items():
  445. hash_str = p_code + key + '0' + full_dict_rules[key] + str(value) + "hg3535" + str(match_id)
  446. sole_str = p_code + key + '0' + str(match_id) + "hg3535"
  447. odds_only = Helper.genearte_MD5(hash_str, pt)
  448. sole = Helper.genearte_MD5(sole_str, pt)
  449. full_dict_rules_key = ["match_id", "lg_id", "odds_code", "status", "sort", "p_code", "odds",
  450. "condition", "odds_only", "sole", "source", "type", "team"]
  451. full_dict_rules_value = [match_id, league_id, key, "0", 0, p_code, value, full_dict_rules[key],
  452. odds_only, sole, "hg3535", "0", ""]
  453. full_dict_rules_data = dict(zip(full_dict_rules_key, full_dict_rules_value))
  454. data_list.append(full_dict_rules_data)
  455. if half_dicts:
  456. for key, value in half_dicts.items():
  457. hash_str = p_code + key + '0' + half_dict_rules[key] + str(value) + "hg3535" + str(match_id)
  458. sole_str = p_code + key + '0' + str(match_id) + "hg3535"
  459. odds_only = Helper.genearte_MD5(hash_str, pt)
  460. sole = Helper.genearte_MD5(sole_str, pt)
  461. half_dicts_key = ["match_id", "lg_id", "odds_code", "status", "sort", "p_code", "odds",
  462. "condition", "odds_only", "sole", "source", "type", "team"]
  463. half_dicts_value = [match_id, league_id, key, "0", 0, p_code, value, half_dict_rules[key],
  464. odds_only, sole, "hg3535", "0", ""]
  465. half_dicts_data = dict(zip(half_dicts_key, half_dicts_value))
  466. data_list.append(half_dicts_data)
  467. p_code = 'CB'
  468. # 球队得分全场,上半场
  469. horn_ou_dict = item['horn_ou_dict']
  470. horn_ou_dict_rule = item['horn_ou_dict_rule']
  471. horn_oe_dict = item['horn_oe_dict']
  472. horn_oe_dict_rule = item['horn_oe_dict_rule']
  473. if horn_ou_dict:
  474. for key, value in horn_ou_dict.items():
  475. hash_str = p_code + key + '0' + horn_ou_dict_rule[key] + str(value) + "hg3535" + str(match_id)
  476. sole_str = p_code + key + '0' + str(match_id) + "hg3535"
  477. odds_only = Helper.genearte_MD5(hash_str, pt)
  478. sole = Helper.genearte_MD5(sole_str, pt)
  479. horn_ou_key = ["match_id", "lg_id", "odds_code", "status", "sort", "p_code", "odds",
  480. "condition", "odds_only", "sole", "source", "type", "team"]
  481. horn_ou_value = [match_id, league_id, key, "0", 0, p_code, value, horn_ou_dict_rule[key],
  482. odds_only, sole, "hg3535", "0", ""]
  483. horn_ou_data = dict(zip(horn_ou_key, horn_ou_value))
  484. data_list.append(horn_ou_data)
  485. if horn_oe_dict:
  486. for key, value in horn_oe_dict.items():
  487. hash_str = p_code + key + '0' + horn_oe_dict_rule[key] + str(value) + "hg3535" + str(match_id)
  488. sole_str = p_code + key + '0' + str(match_id) + "hg3535"
  489. odds_only = Helper.genearte_MD5(hash_str, pt)
  490. sole = Helper.genearte_MD5(sole_str, pt)
  491. horn_oe_key = ["match_id", "lg_id", "odds_code", "status", "sort", "p_code", "odds",
  492. "condition", "odds_only", "sole", "source", "type", "team"]
  493. horn_oe_value = [match_id, league_id, key, "0", 0, p_code, value, horn_oe_dict_rule[key],
  494. odds_only, sole, "hg3535", "0", ""]
  495. horn_oe_data = dict(zip(horn_oe_key, horn_oe_value))
  496. data_list.append(horn_oe_data)
  497. odds_key = ["game_code", "title", "match_id", "lg_id", "data", "source", "odds_only", "tag", "uuid",
  498. "is_stringscene", "utime", "pt"]
  499. odds_value = ["zq", "odds", match_id, league_id, data_list, "hg3535", odds_onlys, number, uuid,
  500. 0, utime, pt]
  501. odds_dict = dict(zip(odds_key, odds_value))
  502. if data_list:
  503. res = Helper.async_post(ODDS_URL, odds_dict)
  504. if res:
  505. if res.get('status') == 1:
  506. logger.info('足球滚球详细赔率提交成功, {}'.format(res))
  507. logger.info(odds_dict)
  508. else:
  509. logger.warning('足球滚球详细赔率提交失败, {}'.format(res))
  510. logger.warning(odds_dict)
  511. else:
  512. logger.warning('足球滚球详细赔率接口异常,提交失败, {}'.format(res))
  513. logger.warning(odds_dict)
  514. else:
  515. logger.info('足球滚球详细赔率列表为空')
  516. data_list = []
  517. zq_rball = {"home_team": team_home, "guest_team": team_guest,
  518. "lg_id": league_id, "home_rate": 0,
  519. "guest_rate": 0, "home_score": score_home,
  520. "guest_score": score_guest, "all_goal": all_goal, "status": 1,
  521. "first_score": "", "last_score": "", "match_score": match_score, "uuid": uuid,
  522. "match_winer": "", "match_time": time_game,
  523. "match_process": half_way, "tag": number,
  524. "match_id": match_id, "p_code": ""}
  525. data_list.append(zq_rball)
  526. r_data_dict = {
  527. "game_code": "zq",
  528. "title": "match_result_r",
  529. "source": "hg3535",
  530. "data": data_list
  531. }
  532. if data_list:
  533. try:
  534. res = Helper.async_post(MATCH_RESULT, r_data_dict)
  535. if res:
  536. if res.get('status') == 1:
  537. logger.info('足球滚球结果记录提交成功, {}'.format(res))
  538. logger.info(r_data_dict)
  539. else:
  540. logger.warning('足球滚球结果记录提交失败, {}'.format(res))
  541. logger.warning(r_data_dict)
  542. else:
  543. logger.warning('足球滚球结果记录接口异常,提交失败, {}'.format(res))
  544. logger.warning(r_data_dict)
  545. except Exception as e:
  546. logger.warning('滚球数据接口异常,提交失败, {}'.format(e))
  547. # status_dict = {"game_code": 'zq', "title": "match_status", "source": "hg3535"}
  548. # data_list = []
  549. # data = {'match_id': match_id, 'status': 1, "is_rollball": 0, "is_today": 0, "is_morningplate": 0,
  550. # "is_stringscene": 0, "is_horn": 0}
  551. # data_list.append(data)
  552. # status_dict['data'] = data_list
  553. # res = Helper.async_post(MATCH_STATUS, status_dict)
  554. # if res:
  555. # if res.get('status') == 1:
  556. # self.db.match_status35.insert(status_dict)
  557. # logger.info('{},赛事结果状态交成功, {}'.format('zq', res))
  558. # logger.info(status_dict)
  559. # else:
  560. # logger.warning('{},赛事结果状态交失败, {}'.format('zq', res))
  561. # logger.warning(status_dict)
  562. # else:
  563. # logger.warning('{},赛事结果状态接口异常提交失败, {}'.format('zq', res))
  564. # logger.warning(status_dict)
  565. # 角球分割处理--------------------------------------------------------------------------------------------------
  566. if horn_team:
  567. team_home = horn_team['horn_home']
  568. team_guest = horn_team['horn_guest']
  569. horn_scoreh = horn_team['horn_scoreh']
  570. horn_scoreg = horn_team['horn_scoreg']
  571. all_goal = int(horn_scoreh) + int(horn_scoreg)
  572. match_id = horn_team['horn_id']
  573. # half_way = item['half_way']
  574. match_score = "{}:{}".format(horn_scoreh, horn_scoreg)
  575. if self.db.zq_competition35.find({"match_id": match_id, 'is_rollball': 1}).count() < 1:
  576. match_list = []
  577. match_dict = {"game_code": "zq", "title": "match", "source": "hg3535"}
  578. match_kay = ["home_team", "guest_team", "lg_id", "status", "match_id", "match_date", "match_time",
  579. "tag", "source", "is_rollball", "is_morningplate", "is_stringscene", "us_time", "uuid",
  580. "half_match_id", "is_today", "is_horn"]
  581. match_value = [team_home, team_guest, league_id, 1, match_id, match_date, match_time, number,
  582. "hg3535", 1, 0, 0, utime, uuid, 0, 0, 1]
  583. match_data = dict(zip(match_kay, match_value))
  584. match_list.append(match_data)
  585. match_dict['data'] = match_list
  586. res = Helper.async_post(MATCH_URL, match_dict)
  587. if res:
  588. if res.get('status') == 1:
  589. self.db.zq_competition35.insert(match_data)
  590. # self.db.zq_competition35.update({'match_id': match_id, 'is_rollball': 1}, {'$set': match_data},
  591. # upsert=True)
  592. logger.info('足球滚球角球, 赛事提交成功, {}'.format(res))
  593. logger.info(match_data)
  594. else:
  595. logger.warning('足球滚球赛事, 角球提交失败, {}'.format(res))
  596. logger.warning(match_data)
  597. else:
  598. logger.warning('足球滚球赛事接口异常, 角球赛事提交失败, {}'.format(res))
  599. logger.warning(match_data)
  600. else:
  601. logger.info('足球滚球赛事已存在, 不提交')
  602. p_code = "GS"
  603. # 构建唯一索引
  604. half_size_guest = item["half_size_guest"]
  605. half_size_guest_rule = item["half_size_guest_rule"]
  606. half_size_home = item["half_size_home"]
  607. half_size_home_rule = item["half_size_home_rule"]
  608. data_list = []
  609. odds_onlys = []
  610. # half_size_guest
  611. for index, value in enumerate(half_size_guest):
  612. hash_str = p_code + "gss_h" + str(index) + str(half_size_guest_rule[index]) + str(
  613. value) + "hg3535" + str(match_id)
  614. sole_str = p_code + "gss_h" + str(index) + str(match_id) + "hg3535"
  615. odds_only = Helper.genearte_MD5(hash_str, pt)
  616. sole = Helper.genearte_MD5(sole_str, pt)
  617. half_size_guest_key = ["match_id", "lg_id", "odds_code", "status", "sort", "p_code", "odds", "condition",
  618. "odds_only", "sole", "source", "type", "team"]
  619. condition = half_size_guest_rule[index]
  620. half_size_guest_value = [match_id, league_id, "gss_h", "0", index, p_code, value, condition,
  621. odds_only, sole, "hg3535", "0", ""]
  622. half_size_guest_data = dict(zip(half_size_guest_key, half_size_guest_value))
  623. data_list.append(half_size_guest_data)
  624. # half_size_home
  625. for index, value in enumerate(half_size_home):
  626. hash_str = p_code + "gsb_h" + str(index) + str(half_size_home_rule[index]) + str(
  627. value) + "hg3535" + str(match_id)
  628. sole_str = p_code + "gsb_h" + str(index) + str(match_id) + "hg3535"
  629. odds_only = Helper.genearte_MD5(hash_str, pt)
  630. sole = Helper.genearte_MD5(sole_str, pt)
  631. half_size_home_key = ["match_id", "lg_id", "odds_code", "status", "sort", "p_code", "odds", "condition",
  632. "odds_only", "sole", "source", "type", "team"]
  633. condition = half_size_home_rule[index]
  634. half_size_home_value = [match_id, league_id, "gsb_h", "0", index, p_code, value, condition,
  635. odds_only, sole, "hg3535", "0", ""]
  636. half_size_home_data = dict(zip(half_size_home_key, half_size_home_value))
  637. data_list.append(half_size_home_data)
  638. # 全场场大小
  639. size_guest = item["size_guest"]
  640. size_guest_rule = item["size_guest_rule"]
  641. size_home = item["size_home"]
  642. size_home_rule = item["size_home_rule"]
  643. # size_home
  644. for index, value in enumerate(size_home):
  645. hash_str = p_code + "gsb" + str(index) + str(size_home_rule[index]) + str(value) + "hg3535" + str(
  646. match_id)
  647. sole_str = p_code + "gsb" + str(index) + str(match_id) + "hg3535"
  648. odds_only = Helper.genearte_MD5(hash_str, pt)
  649. sole = Helper.genearte_MD5(sole_str, pt)
  650. size_home_key = ["match_id", "lg_id", "odds_code", "status", "sort", "p_code", "odds", "condition",
  651. "odds_only", "sole", "source", "type", "team"]
  652. condition = size_home_rule[index]
  653. size_home_value = [match_id, league_id, "gsb", "0", index, p_code, value, condition, odds_only,
  654. sole, "hg3535", "0", ""]
  655. size_home_data = dict(zip(size_home_key, size_home_value))
  656. data_list.append(size_home_data)
  657. # size_guest
  658. for index, value in enumerate(size_guest):
  659. hash_str = p_code + "gss" + str(index) + str(size_guest_rule[index]) + str(value) + "hg3535" + str(
  660. match_id)
  661. sole_str = p_code + "gss" + str(index) + str(match_id) + "hg3535"
  662. odds_only = Helper.genearte_MD5(hash_str, pt)
  663. sole = Helper.genearte_MD5(sole_str, pt)
  664. size_guest_key = ["match_id", "lg_id", "odds_code", "status", "sort", "p_code", "odds", "condition",
  665. "odds_only", "sole", "source", "type", "team"]
  666. condition = size_guest_rule[index]
  667. size_guest_value = [match_id, league_id, "gss", "0", index, p_code, value, condition, odds_only,
  668. sole, "hg3535", "0", ""]
  669. size_home_data = dict(zip(size_guest_key, size_guest_value))
  670. data_list.append(size_home_data)
  671. p_code = 'CO'
  672. half_concede_home_rule = item["half_concede_home_rule"]
  673. half_concede_home = item["half_concede_home"]
  674. half_concede_guest_rule = item["half_concede_guest_rule"]
  675. half_concede_guest = item["half_concede_guest"]
  676. # half_concede_home
  677. for index, value in enumerate(half_concede_guest):
  678. hash_str = p_code + "cog_h" + str(index) + str(half_concede_guest_rule[index]) + str(
  679. value) + "hg3535" + str(match_id)
  680. sole_str = p_code + "cog_h" + str(index) + str(match_id) + "hg3535"
  681. odds_only = Helper.genearte_MD5(hash_str, pt)
  682. sole = Helper.genearte_MD5(sole_str, pt)
  683. half_concede_guest_key = ["match_id", "lg_id", "odds_code", "status", "sort", "p_code", "odds", "condition",
  684. "odds_only", "sole", "source", "type", "team"]
  685. condition = half_concede_guest_rule[index]
  686. half_concede_guest_value = [match_id, league_id, "cog_h", "0", index, p_code, value, condition,
  687. odds_only, sole, "hg3535", "0", ""]
  688. half_concede_guest_data = dict(zip(half_concede_guest_key, half_concede_guest_value))
  689. data_list.append(half_concede_guest_data)
  690. # half_concede_home
  691. for index, value in enumerate(half_concede_home):
  692. hash_str = p_code + "coh_h" + str(index) + str(half_concede_home_rule[index]) + str(
  693. value) + "hg3535" + str(match_id)
  694. sole_str = p_code + "coh_h" + str(index) + str(match_id) + "hg3535"
  695. odds_only = Helper.genearte_MD5(hash_str, pt)
  696. sole = Helper.genearte_MD5(sole_str, pt)
  697. half_concede_home_key = ["match_id", "lg_id", "odds_code", "status", "sort", "p_code", "odds", "condition",
  698. "odds_only", "sole", "source", "type", "team"]
  699. condition = half_concede_home_rule[index]
  700. half_concede_home_value = [match_id, league_id, "coh_h", "0", index, p_code, value, condition,
  701. odds_only, sole, "hg3535", "0", ""]
  702. half_concede_home_data = dict(zip(half_concede_home_key, half_concede_home_value))
  703. data_list.append(half_concede_home_data)
  704. concede_guest = item["concede_guest"]
  705. concede_guest_rule = item["concede_guest_rule"]
  706. concede_home = item["concede_home"]
  707. concede_home_rule = item["concede_home_rule"]
  708. # concede_guest
  709. for index, value in enumerate(concede_guest):
  710. hash_str = p_code + "cog" + str(index) + str(concede_guest_rule[index]) + str(
  711. value) + "hg3535" + str(match_id)
  712. sole_str = p_code + "cog" + str(index) + str(match_id) + "hg3535"
  713. odds_only = Helper.genearte_MD5(hash_str, pt)
  714. sole = Helper.genearte_MD5(sole_str, pt)
  715. concede_guest_key = ["match_id", "lg_id", "odds_code", "status", "sort", "p_code", "odds", "condition",
  716. "odds_only", "sole", "source", "type", "team"]
  717. condition = concede_guest_rule[index]
  718. concede_guest_value = [match_id, league_id, "cog", "0", index, p_code, value, condition,
  719. odds_only, sole, "hg3535", "0", ""]
  720. concede_guest_data = dict(zip(concede_guest_key, concede_guest_value))
  721. data_list.append(concede_guest_data)
  722. # concede_home
  723. for index, value in enumerate(concede_home):
  724. hash_str = p_code + "coh" + str(index) + str(concede_home_rule[index]) + str(
  725. value) + "hg3535" + str(match_id)
  726. sole_str = p_code + "coh" + str(index) + str(match_id) + "hg3535"
  727. odds_only = Helper.genearte_MD5(hash_str, pt)
  728. sole = Helper.genearte_MD5(sole_str, pt)
  729. concede_home_key = ["match_id", "lg_id", "odds_code", "status", "sort", "p_code", "odds", "condition",
  730. "odds_only", "sole", "source", "type", "team"]
  731. condition = concede_home_rule[index]
  732. concede_home_value = [match_id, league_id, "coh", "0", index, p_code, value, condition, odds_only,
  733. sole, "hg3535", "0", ""]
  734. concede_guest_data = dict(zip(concede_home_key, concede_home_value))
  735. data_list.append(concede_guest_data)
  736. # 独赢-------------------------------------------------------------------------------------------------------
  737. p_code = 'C'
  738. half_capot_home = item["half_capot_home"]
  739. half_capot_guest = item["half_capot_guest"]
  740. half_capot_dogfall = item["half_capot_dogfall"]
  741. capot_home = item["capot_home"]
  742. capot_guest = item["capot_guest"]
  743. capot_dogfall = item["capot_dogfall"]
  744. # half_capot_home
  745. hash_str = p_code + "ch_h" + '0' + '1' + str(half_capot_home) + "hg3535" + str(match_id)
  746. sole_str = p_code + "ch_h" + '0' + str(match_id) + "hg3535"
  747. odds_only = Helper.genearte_MD5(hash_str, pt)
  748. sole = Helper.genearte_MD5(sole_str, pt)
  749. half_capot_home_key = ["match_id", "lg_id", "odds_code", "status", "sort", "p_code", "odds", "condition",
  750. "odds_only", "sole", "source", "type", "team"]
  751. half_capot_home_value = [match_id, league_id, "ch_h", "0", 0, p_code, half_capot_home, '1',
  752. odds_only, sole, "hg3535", "0", ""]
  753. half_capot_homet_data = dict(zip(half_capot_home_key, half_capot_home_value))
  754. data_list.append(half_capot_homet_data)
  755. # half_capot_guest
  756. hash_str = p_code + "cg_h" + '0' + '2' + str(half_capot_guest) + "hg3535" + str(match_id)
  757. sole_str = p_code + "cg_h" + '0' + str(match_id) + "hg3535"
  758. odds_only = Helper.genearte_MD5(hash_str, pt)
  759. sole = Helper.genearte_MD5(sole_str, pt)
  760. half_capot_guest_key = ["match_id", "lg_id", "odds_code", "status", "sort", "p_code", "odds", "condition",
  761. "odds_only", "sole", "source", "type", "team"]
  762. half_capot_guest_value = [match_id, league_id, "cg_h", "0", 0, p_code, half_capot_guest, '2',
  763. odds_only, sole, "hg3535", "0", ""]
  764. half_capot_guest_data = dict(zip(half_capot_guest_key, half_capot_guest_value))
  765. data_list.append(half_capot_guest_data)
  766. # half_capot_dogfall
  767. hash_str = p_code + "cd_h" + '0' + 'X' + str(half_capot_dogfall) + "hg3535" + str(match_id)
  768. sole_str = p_code + "cd_h" + '0' + str(match_id) + "hg3535"
  769. odds_only = Helper.genearte_MD5(hash_str, pt)
  770. sole = Helper.genearte_MD5(sole_str, pt)
  771. half_capot_dogfall_key = ["match_id", "lg_id", "odds_code", "status", "sort", "p_code", "odds", "condition",
  772. "odds_only", "sole", "source", "type", "team"]
  773. half_capot_dogfall_value = [match_id, league_id, "cd_h", "0", 0, p_code, half_capot_dogfall, 'X',
  774. odds_only, sole, "hg3535", "0", ""]
  775. half_capot_dogfall_data = dict(zip(half_capot_dogfall_key, half_capot_dogfall_value))
  776. data_list.append(half_capot_dogfall_data)
  777. # capot_dogfall
  778. hash_str = p_code + "cd" + '0' + 'X' + str(capot_dogfall) + "hg3535" + str(match_id)
  779. sole_str = p_code + "cd" + '0' + str(match_id) + "hg3535"
  780. odds_only = Helper.genearte_MD5(hash_str, pt)
  781. sole = Helper.genearte_MD5(sole_str, pt)
  782. capot_dogfall_key = ["match_id", "lg_id", "odds_code", "status", "sort", "p_code", "odds", "condition",
  783. "odds_only", "sole", "source", "type", "team"]
  784. capot_dogfall_value = [match_id, league_id, "cd", "0", 0, p_code, capot_dogfall, 'X', odds_only,
  785. sole, "hg3535", "0", ""]
  786. capot_dogfall_data = dict(zip(capot_dogfall_key, capot_dogfall_value))
  787. data_list.append(capot_dogfall_data)
  788. # capot_home
  789. hash_str = p_code + "ch" + '0' + '1' + str(capot_home) + "hg3535" + str(match_id)
  790. sole_str = p_code + "ch" + '0' + str(match_id) + "hg3535"
  791. odds_only = Helper.genearte_MD5(hash_str, pt)
  792. sole = Helper.genearte_MD5(sole_str, pt)
  793. capot_home_key = ["match_id", "lg_id", "odds_code", "status", "sort", "p_code", "odds", "condition",
  794. "odds_only", "sole", "source", "type", "team"]
  795. capot_home_value = [match_id, league_id, "ch", "0", 0, p_code, capot_home, '1',
  796. odds_only, sole, "hg3535", "0", ""]
  797. capot_homet_data = dict(zip(capot_home_key, capot_home_value))
  798. data_list.append(capot_homet_data)
  799. # capot_guest
  800. hash_str = p_code + "cg" + '0' + '2' + str(capot_guest) + "hg3535" + str(match_id)
  801. sole_str = p_code + "cg" + '0' + str(match_id) + "hg3535"
  802. odds_only = Helper.genearte_MD5(hash_str, pt)
  803. sole = Helper.genearte_MD5(sole_str, pt)
  804. capot_guest_key = ["match_id", "lg_id", "odds_code", "status", "sort", "p_code", "odds", "condition",
  805. "odds_only", "sole", "source", "type", "team"]
  806. capot_guest_value = [match_id, league_id, "cg", "0", 0, p_code, capot_guest, '2',
  807. odds_only, sole, "hg3535", "0", ""]
  808. capot_guest_data = dict(zip(capot_guest_key, capot_guest_value))
  809. data_list.append(capot_guest_data)
  810. # 入球数单双--------------------------------------------------------------------------------------------------
  811. p_code = 'TS'
  812. odd_even_odd = item["odd_even_odd"]
  813. odd_even_even = item["odd_even_even"]
  814. half_odd_even_odd = item["half_odd_even_odd"]
  815. half_odd_even_even = item["half_odd_even_even"]
  816. # odd_even_odd
  817. hash_str = p_code + "tss" + '0' + '单' + str(odd_even_odd) + "hg3535" + str(match_id)
  818. sole_str = p_code + "tss" + '0' + str(match_id) + "hg3535"
  819. odds_only = Helper.genearte_MD5(hash_str, pt)
  820. sole = Helper.genearte_MD5(sole_str, pt)
  821. single_key = ["match_id", "lg_id", "odds_code", "status", "sort", "p_code", "odds", "condition",
  822. "odds_only", "sole", "source", "type", "team"]
  823. single_value = [match_id, league_id, "tss", "0", 0, p_code, odd_even_odd, '单',
  824. odds_only, sole, "hg3535", "0", ""]
  825. single_data = dict(zip(single_key, single_value))
  826. data_list.append(single_data)
  827. # odd_even_even
  828. hash_str = p_code + "tsd" + '0' + '双' + str(odd_even_even) + "hg3535" + str(match_id)
  829. sole_str = p_code + "tsd" + '0' + str(match_id) + "hg3535"
  830. odds_only = Helper.genearte_MD5(hash_str, pt)
  831. sole = Helper.genearte_MD5(sole_str, pt)
  832. double_key = ["match_id", "lg_id", "odds_code", "status", "sort", "p_code", "odds", "condition",
  833. "odds_only", "sole", "source", "type", "team"]
  834. double_value = [match_id, league_id, "tsd", "0", 0, p_code, odd_even_even, '双',
  835. odds_only, sole, "hg3535", "0", ""]
  836. double_data = dict(zip(double_key, double_value))
  837. data_list.append(double_data)
  838. # half_odd_even_even
  839. hash_str = p_code + "tsd_h" + '0' + '双' + str(half_odd_even_even) + "hg3535" + str(match_id)
  840. sole_str = p_code + "tsd_h" + '0' + str(match_id) + "hg3535"
  841. odds_only = Helper.genearte_MD5(hash_str, pt)
  842. sole = Helper.genearte_MD5(sole_str, pt)
  843. half_double_key = ["match_id", "lg_id", "odds_code", "status", "sort", "p_code", "odds", "condition",
  844. "odds_only", "sole", "source", "type", "team"]
  845. half_double_value = [match_id, league_id, "tsd_h", "0", 0, p_code, half_odd_even_even, '双',
  846. odds_only, sole, "hg3535", "0", ""]
  847. half_double_data = dict(zip(half_double_key, half_double_value))
  848. data_list.append(half_double_data)
  849. # half_odd_even_odd
  850. hash_str = p_code + "tss_h" + '0' + '单' + str(half_odd_even_odd) + "hg3535" + str(match_id)
  851. sole_str = p_code + "tss_h" + '0' + str(match_id) + "hg3535"
  852. odds_only = Helper.genearte_MD5(hash_str, pt)
  853. sole = Helper.genearte_MD5(sole_str, pt)
  854. half_single_key = ["match_id", "lg_id", "odds_code", "status", "sort", "p_code", "odds", "condition",
  855. "odds_only", "sole", "source", "type", "team"]
  856. half_single_value = [match_id, league_id, "tss_h", "0", 0, p_code, half_odd_even_odd, '单', odds_only,
  857. sole, "hg3535", "0", ""]
  858. half_single_data = dict(zip(half_single_key, half_single_value))
  859. data_list.append(half_single_data)
  860. p_code = 'TG'
  861. # 总入球数 ---------------------------------------------------------------------------------------------------
  862. total_goals = item['total_goal']
  863. total_dict = {'tg0': '0-1', 'tg1': '2-3', 'tg2': '4-6', 'tg3': '7或以上', 'tg0_h': '0', "tg1_h": '1',
  864. "tg2_h": '2', "tg3_h": '3或以上'}
  865. # 全场入球数 单双
  866. for key, value in total_goals.items():
  867. hash_str = p_code + key + '0' + total_dict[key] + str(value) + "hg3535" + str(match_id)
  868. sole_str = p_code + key + '0' + str(match_id) + "hg3535"
  869. odds_only = Helper.genearte_MD5(hash_str, pt)
  870. sole = Helper.genearte_MD5(sole_str, pt)
  871. total_goals_key = ["match_id", "lg_id", "odds_code", "status", "sort", "p_code", "odds", "condition",
  872. "odds_only", "sole", "source", "type", "team"]
  873. total_goals_value = [match_id, league_id, key, "0", 0, p_code, value, total_dict[key], odds_only,
  874. sole, "hg3535", "0", ""]
  875. total_goals_data = dict(zip(total_goals_key, total_goals_value))
  876. data_list.append(total_goals_data)
  877. # 全场半场 ---------------------------------------------------------------------------------------------------
  878. half_fulls = item['half_full']
  879. # p_code, p_id = get_pcode(corner_ball, 'half_full')
  880. p_code = 'HF'
  881. full_dict = {"hfhh": "主主", "hfhd": "主和", "hfhg": "主客", "hfdh": "和主",
  882. "hfdd": "和和", "hfdg": "和客", "hfgh": "客主", "hfgd": "客和", "hfgg": "客客"}
  883. if half_fulls:
  884. for key, value in half_fulls.items():
  885. hash_str = p_code + key + '0' + full_dict[key] + str(value) + "hg3535" + str(match_id)
  886. sole_str = p_code + key + '0' + str(match_id) + "hg3535"
  887. odds_only = Helper.genearte_MD5(hash_str, pt)
  888. sole = Helper.genearte_MD5(sole_str, pt)
  889. half_fulls_key = ["match_id", "lg_id", "odds_code", "status", "sort", "p_code", "odds", "condition",
  890. "odds_only", "sole", "source", "type", "team"]
  891. half_fulls_value = [match_id, league_id, key, "0", 0, p_code, value, full_dict[key], odds_only,
  892. sole, "hg3535", "0", ""]
  893. half_fulls_data = dict(zip(half_fulls_key, half_fulls_value))
  894. data_list.append(half_fulls_data)
  895. # 波胆-------------------------------------------------------------------------------------------------------
  896. p_code = 'B'
  897. bodan_datas = item['bodan_data']
  898. # p_code, p_id = get_pcode(corner_ball, 'bodan')
  899. bodan_dict = {"b10": "1-0", "b20": "2-0", "b21": "2-1", "b30": "3-0", "b31": "3-1", "b32": "3-2",
  900. "b40": "4-0", "b41": "4-1", "b42": "4-2", "b43": "4-3", "b01": "0-1", "b02": "0-2",
  901. "b12": "1-2", "b03": "0-3", "b13": "1-3", "b23": "2-3", "b04": "0-4", "b14": "1-4",
  902. "b24": "2-4", "b34": "3-4", "b00": "0-0", "b11": "1-1", "b22": "2-2", "b33": "3-3",
  903. "b44": "4-4", "bo": "其他", "b10_h": "1-0", "b20_h": "2-0", "b21_h": "2-1", "b30_h": "3-0",
  904. "b31_h": "3-1", "b32_h": "3-2", "b01_h": "0-1", "b02_h": "0-2", "b12_h": "1-2", "b03_h": "0-3",
  905. "b13_h": "1-3", "b23_h": "2-3", "b00_h": "0-0", "b11_h": "1-1", "b22_h": "2-2", "b33_h": "3-3",
  906. "bo_h": "其他"}
  907. if bodan_datas:
  908. for key, value in bodan_datas.items():
  909. hash_str = p_code + key + '0' + bodan_dict[key] + str(value) + "hg3535" + str(match_id)
  910. sole_str = p_code + key + '0' + str(match_id) + "hg3535"
  911. odds_only = Helper.genearte_MD5(hash_str, pt)
  912. sole = Helper.genearte_MD5(sole_str, pt)
  913. bodan_dict_key = ["match_id", "lg_id", "odds_code", "status", "sort", "p_code", "odds", "condition",
  914. "odds_only", "sole", "source", "type", "team"]
  915. bodan_dict_value = [match_id, league_id, key, "0", 0, p_code, value, bodan_dict[key], odds_only,
  916. sole, "hg3535", "0", ""]
  917. bodan_dict_data = dict(zip(bodan_dict_key, bodan_dict_value))
  918. data_list.append(bodan_dict_data)
  919. # 最先进球/最后进球 -------------------------------------------------------------------------------------------
  920. first_last_balls = item['first_last_ball']
  921. p_code = 'FLB'
  922. first_last_dict = {"flbfh": "最先进球", "flbfg": "最先进球", "flblh": "最后进球", "flblg": "最后进球", "flbn": "没有进球"}
  923. if first_last_balls:
  924. for key, value in first_last_balls.items():
  925. hash_str = p_code + key + '0' + first_last_dict[key] + str(value) + "hg3535" + str(match_id)
  926. sole_str = p_code + key + '0' + str(match_id) + "hg3535"
  927. odds_only = Helper.genearte_MD5(hash_str, pt)
  928. sole = Helper.genearte_MD5(sole_str, pt)
  929. first_last_balls_key = ["match_id", "lg_id", "odds_code", "status", "sort", "p_code", "odds",
  930. "condition",
  931. "odds_only", "sole", "source", "type", "team"]
  932. first_last_balls_value = [match_id, league_id, key, "0", 0, p_code, value, first_last_dict[key],
  933. odds_only,
  934. sole, "hg3535", "0", ""]
  935. first_last_balls_data = dict(zip(first_last_balls_key, first_last_balls_value))
  936. data_list.append(first_last_balls_data)
  937. p_code = 'TB'
  938. # 球队得分全场,上半场
  939. full_dicts = item['full_data']
  940. half_dicts = item['half_data']
  941. full_dict_rules = item['full_data_rule']
  942. half_dict_rules = item['half_data_rule']
  943. if full_dicts:
  944. for key, value in full_dicts.items():
  945. hash_str = p_code + key + '0' + full_dict_rules[key] + str(value) + "hg3535" + str(match_id)
  946. sole_str = p_code + key + '0' + str(match_id) + "hg3535"
  947. odds_only = Helper.genearte_MD5(hash_str, pt)
  948. sole = Helper.genearte_MD5(sole_str, pt)
  949. full_dict_rules_key = ["match_id", "lg_id", "odds_code", "status", "sort", "p_code", "odds",
  950. "condition", "odds_only", "sole", "source", "type", "team"]
  951. full_dict_rules_value = [match_id, league_id, key, "0", 0, p_code, value, full_dict_rules[key],
  952. odds_only, sole, "hg3535", "0", ""]
  953. full_dict_rules_data = dict(zip(full_dict_rules_key, full_dict_rules_value))
  954. data_list.append(full_dict_rules_data)
  955. if half_dicts:
  956. for key, value in half_dicts.items():
  957. hash_str = p_code + key + '0' + half_dict_rules[key] + str(value) + "hg3535" + str(match_id)
  958. sole_str = p_code + key + '0' + str(match_id) + "hg3535"
  959. odds_only = Helper.genearte_MD5(hash_str, pt)
  960. sole = Helper.genearte_MD5(sole_str, pt)
  961. half_dicts_key = ["match_id", "lg_id", "odds_code", "status", "sort", "p_code", "odds",
  962. "condition", "odds_only", "sole", "source", "type", "team"]
  963. half_dicts_value = [match_id, league_id, key, "0", 0, p_code, value, half_dict_rules[key],
  964. odds_only, sole, "hg3535", "0", ""]
  965. half_dicts_data = dict(zip(half_dicts_key, half_dicts_value))
  966. data_list.append(half_dicts_data)
  967. p_code = 'CB'
  968. horn_ou_dict = item['horn_ou_dict']
  969. horn_ou_dict_rule = item['horn_ou_dict_rule']
  970. horn_oe_dict = item['horn_oe_dict']
  971. horn_oe_dict_rule = item['horn_oe_dict_rule']
  972. if horn_ou_dict:
  973. for key, value in horn_ou_dict.items():
  974. hash_str = p_code + key + '0' + horn_ou_dict_rule[key] + str(value) + "hg3535" + str(match_id)
  975. sole_str = p_code + key + '0' + str(match_id) + "hg3535"
  976. odds_only = Helper.genearte_MD5(hash_str, pt)
  977. sole = Helper.genearte_MD5(sole_str, pt)
  978. horn_ou_key = ["match_id", "lg_id", "odds_code", "status", "sort", "p_code", "odds",
  979. "condition", "odds_only", "sole", "source", "type", "team"]
  980. horn_ou_value = [match_id, league_id, key, "0", 0, p_code, value, horn_ou_dict_rule[key],
  981. odds_only, sole, "hg3535", "0", ""]
  982. horn_ou_data = dict(zip(horn_ou_key, horn_ou_value))
  983. data_list.append(horn_ou_data)
  984. if horn_oe_dict:
  985. for key, value in horn_oe_dict.items():
  986. hash_str = p_code + key + '0' + horn_oe_dict_rule[key] + str(value) + "hg3535" + str(match_id)
  987. sole_str = p_code + key + '0' + str(match_id) + "hg3535"
  988. odds_only = Helper.genearte_MD5(hash_str, pt)
  989. sole = Helper.genearte_MD5(sole_str, pt)
  990. horn_oe_key = ["match_id", "lg_id", "odds_code", "status", "sort", "p_code", "odds",
  991. "condition", "odds_only", "sole", "source", "type", "team"]
  992. horn_oe_value = [match_id, league_id, key, "0", 0, p_code, value, horn_oe_dict_rule[key],
  993. odds_only, sole, "hg3535", "0", ""]
  994. horn_oe_data = dict(zip(horn_oe_key, horn_oe_value))
  995. data_list.append(horn_oe_data)
  996. odds_key = ["game_code", "title", "match_id", "lg_id", "data", "source", "odds_only", "tag", "uuid",
  997. "is_stringscene", "utime", "pt"]
  998. odds_value = ["zq", "odds", match_id, league_id, data_list, "hg3535", odds_onlys, number, uuid,
  999. 0, utime, pt]
  1000. odds_dict = dict(zip(odds_key, odds_value))
  1001. if data_list:
  1002. res = Helper.async_post(ODDS_URL, odds_dict)
  1003. if res:
  1004. if res.get('status') == 1:
  1005. logger.info('足球滚球, 角球详细赔率提交成功, {}'.format(res))
  1006. logger.info(odds_dict)
  1007. else:
  1008. logger.warning('足球滚球, 角球详细赔率提交失败, {}'.format(res))
  1009. logger.warning(odds_dict)
  1010. else:
  1011. logger.warning('足球滚球, 角球详细赔率接口异常,提交失败, {}'.format(res))
  1012. logger.warning(odds_dict)
  1013. else:
  1014. logger.info('足球滚球, 角球详细赔率列表为空')
  1015. data_list = []
  1016. zq_rball = {"home_team": team_home, "guest_team": team_guest,
  1017. "lg_id": league_id, "home_rate": 0,
  1018. "guest_rate": 0, "home_score": horn_scoreh,
  1019. "guest_score": horn_scoreg, "all_goal": all_goal, "status": 1,
  1020. "first_score": "", "last_score": "", "match_score": match_score, "uuid": uuid,
  1021. "match_winer": "", "match_time": time_game,
  1022. "match_process": half_way, "tag": number,
  1023. "match_id": match_id, "p_code": ""}
  1024. data_list.append(zq_rball)
  1025. r_data_dict = {
  1026. "game_code": "zq",
  1027. "title": "match_result_r",
  1028. "source": "hg3535",
  1029. "data": data_list
  1030. }
  1031. if data_list:
  1032. try:
  1033. res = Helper.async_post(MATCH_RESULT, r_data_dict)
  1034. if res:
  1035. if res.get('status') == 1:
  1036. logger.info('足球滚球, 角球结果记录提交成功, {}'.format(res))
  1037. logger.info(r_data_dict)
  1038. else:
  1039. logger.warning('足球滚球, 角球结果记录提交失败, {}'.format(res))
  1040. logger.warning(r_data_dict)
  1041. else:
  1042. logger.warning('足球滚球, 角球结果记录接口异常,提交失败, {}'.format(res))
  1043. logger.warning(r_data_dict)
  1044. except Exception as e:
  1045. logger.warning('滚球数据接口异常, 角球结果提交失败, {}'.format(e))
  1046. reactor.callFromThread(out.callback, item)