roll_zuqiu.py 68 KB

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