zuqiu.py 65 KB

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