roll_zuqiu.py 69 KB

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