roll_zuqiu.py 69 KB

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