roll_zuqiu.py 32 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565
  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
  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 _do_calculation(self, item, out):
  23. logger = logging.getLogger(__name__)
  24. pt = 4
  25. # 比赛日期
  26. # try:
  27. # data_game = item['data_game'].split("/")
  28. # month = str(data_game[1].strip())
  29. # day = str(data_game[0])
  30. # except Exception as e:
  31. # logger.warning(e)
  32. # data_game = item['data_game'].split(" ")
  33. # months = str(data_game[1].strip())
  34. # 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'}
  35. # month = month_dict[months]
  36. # day = str(data_game[0])
  37. # 比赛时间
  38. time_game = str(item['time_game'])
  39. # 现在时间,时间戳
  40. utime = time.strftime("%Y-%m-%d %H:%M:%S", time.localtime())
  41. match_date = datetime.datetime.now().strftime("%Y-%m-%d")
  42. # 比赛id
  43. match_id = item['game_id']
  44. # 联赛id
  45. league_id = item['league_id']
  46. # 联赛name
  47. league_name = item['league_name']
  48. # 主队
  49. team_home = item['team_home']
  50. # 客队
  51. team_guest = item['team_guest']
  52. # number
  53. number = item['number']
  54. score_home = item['score_home']
  55. score_guest = item['score_guest']
  56. all_goal = int(score_home) + int(score_guest)
  57. half_way = item['half_way']
  58. match_score = "{}:{}".format(score_home, score_guest)
  59. corner_ball = item['corner_ball']
  60. last_time = '{}-12-31 23:59:59'.format(datetime.datetime.now().year)
  61. league_list = []
  62. uuid = Helper.genearte_uuid(league_name + 'hg3535')
  63. if self.db.zq_league35.find({'league_id': league_id}).count() < 1:
  64. league_dict = {"game_code": "zq", "title": "league", "source": "hg3535"}
  65. league_key = ["name_chinese", "kind", "match_mode", "if_stop", "last_time", "lg_id", "source", "uuid"]
  66. league_value = [league_name, "1", "1", "0", last_time, league_id, "hg3535", uuid]
  67. league_data = dict(zip(league_key, league_value))
  68. league_list.append(league_data)
  69. league_dict['data'] = league_list
  70. res = Helper.async_post(LEAGUE_URL, league_dict)
  71. if res:
  72. if "成功" in res:
  73. self.db.hg3535_zq_league.insert(league_list)
  74. logger.info('足球滚球联赛提交失败, {}'.format(res))
  75. logger.info(league_dict)
  76. else:
  77. logger.warning('足球滚球联赛提交失败, {}'.format(res))
  78. logger.warning(league_dict)
  79. else:
  80. logger.warning('足球滚球联赛接口异常提交失败, {}'.format(res))
  81. logger.warning(league_dict)
  82. else:
  83. logger.info('足球滚球联赛已存在, 不存在')
  84. if self.db.zq_competition35.find({"match_id": match_id, 'is_rollball': 1}).count() < 1:
  85. match_list = []
  86. match_dict = {"game_code": "zq", "title": "match", "source": "hg3535"}
  87. match_kay = ["home_team", "guest_team", "lg_id", "status", "match_id", "match_date", "match_time",
  88. "tag", "source", "is_rollball", "is_morningplate", "is_stringscene", "us_time", "uuid",
  89. "half_match_id", "is_today"]
  90. match_value = [team_home, team_guest, league_id, 1, match_id, match_date, '00:00', number,
  91. "hg3535", 1, 0, 0, utime, uuid, 0, 0]
  92. match_data = dict(zip(match_kay, match_value))
  93. match_list.append(match_data)
  94. match_dict['data'] = match_list
  95. res = Helper.async_post(MATCH_URL, match_dict)
  96. if res:
  97. if "成功" in res:
  98. self.db.zq_competition35.insert(match_data)
  99. logger.info('足球滚球赛事提交成功, {}'.format(res))
  100. logger.info(match_data)
  101. else:
  102. logger.warning('足球滚球赛事,提交失败, {}'.format(res))
  103. logger.warning(match_data)
  104. else:
  105. logger.warning('足球滚球赛事接口异常提交失败, {}'.format(res))
  106. logger.warning(match_data)
  107. else:
  108. logger.info('足球滚球赛事已存在, 不提交')
  109. p_code = "GS"
  110. # 构建唯一索引
  111. half_size_guest = item["half_size_guest"]
  112. half_size_guest_rule = item["half_size_guest_rule"]
  113. half_size_home = item["half_size_home"]
  114. half_size_home_rule = item["half_size_home_rule"]
  115. data_list = []
  116. odds_onlys = []
  117. # half_size_guest
  118. for index, value in enumerate(half_size_guest):
  119. hash_str = p_code + "gss_h" + str(index) + str(half_size_guest_rule[index]) + str(
  120. value) + "hg3535" + str(match_id)
  121. sole_str = p_code + "gss_h" + str(index) + str(match_id) + "hg3535"
  122. odds_only = Helper.genearte_MD5(hash_str, pt)
  123. sole = Helper.genearte_MD5(sole_str, pt)
  124. odds_onlys.append(odds_only)
  125. half_size_guest_key = ["match_id", "lg_id", "odds_code", "status", "sort", "p_code", "odds", "condition",
  126. "odds_only", "sole", "source", "type", "team"]
  127. condition = half_size_guest_rule[index]
  128. half_size_guest_value = [match_id, league_id, "gss_h", "0", index, p_code, value, condition,
  129. odds_only, sole, "hg3535", "0", ""]
  130. half_size_guest_data = dict(zip(half_size_guest_key, half_size_guest_value))
  131. data_list.append(half_size_guest_data)
  132. # half_size_home
  133. for index, value in enumerate(half_size_home):
  134. hash_str = p_code + "gsb_h" + str(index) + str(half_size_home_rule[index]) + str(
  135. value) + "hg3535" + str(match_id)
  136. sole_str = p_code + "gsb_h" + str(index) + str(match_id) + "hg3535"
  137. odds_only = Helper.genearte_MD5(hash_str, pt)
  138. sole = Helper.genearte_MD5(sole_str, pt)
  139. half_size_home_key = ["match_id", "lg_id", "odds_code", "status", "sort", "p_code", "odds", "condition",
  140. "odds_only", "sole", "source", "type", "team"]
  141. condition = half_size_home_rule[index]
  142. half_size_home_value = [match_id, league_id, "gsb_h", "0", index, p_code, value, condition,
  143. odds_only, sole, "hg3535", "0", ""]
  144. half_size_home_data = dict(zip(half_size_home_key, half_size_home_value))
  145. data_list.append(half_size_home_data)
  146. # 全场场大小
  147. size_guest = item["size_guest"]
  148. size_guest_rule = item["size_guest_rule"]
  149. size_home = item["size_home"]
  150. size_home_rule = item["size_home_rule"]
  151. # size_home
  152. for index, value in enumerate(size_home):
  153. hash_str = p_code + "gsb" + str(index) + str(size_home_rule[index]) + str(value) + "hg3535" + str(
  154. match_id)
  155. sole_str = p_code + "gsb" + str(index) + str(match_id) + "hg3535"
  156. odds_only = Helper.genearte_MD5(hash_str, pt)
  157. sole = Helper.genearte_MD5(sole_str, pt)
  158. size_home_key = ["match_id", "lg_id", "odds_code", "status", "sort", "p_code", "odds", "condition",
  159. "odds_only", "sole", "source", "type", "team"]
  160. condition = size_home_rule[index]
  161. size_home_value = [match_id, league_id, "gsb", "0", index, p_code, value, condition, odds_only,
  162. sole, "hg3535", "0", ""]
  163. size_home_data = dict(zip(size_home_key, size_home_value))
  164. data_list.append(size_home_data)
  165. # size_guest
  166. for index, value in enumerate(size_guest):
  167. hash_str = p_code + "gss" + str(index) + str(size_guest_rule[index]) + str(value) + "hg3535" + str(
  168. match_id)
  169. sole_str = p_code + "gss" + str(index) + str(match_id) + "hg3535"
  170. odds_only = Helper.genearte_MD5(hash_str, pt)
  171. sole = Helper.genearte_MD5(sole_str, pt)
  172. size_guest_key = ["match_id", "lg_id", "odds_code", "status", "sort", "p_code", "odds", "condition",
  173. "odds_only", "sole", "source", "type", "team"]
  174. condition = size_guest_rule[index]
  175. size_guest_value = [match_id, league_id, "gss", "0", index, p_code, value, condition, odds_only,
  176. sole, "hg3535", "0", ""]
  177. size_home_data = dict(zip(size_guest_key, size_guest_value))
  178. data_list.append(size_home_data)
  179. p_code = 'CO'
  180. half_concede_home_rule = item["half_concede_home_rule"]
  181. half_concede_home = item["half_concede_home"]
  182. half_concede_guest_rule = item["half_concede_guest_rule"]
  183. half_concede_guest = item["half_concede_guest"]
  184. # half_concede_home
  185. for index, value in enumerate(half_concede_guest):
  186. hash_str = p_code + "cog_h" + str(index) + str(half_concede_guest_rule[index]) + str(
  187. value) + "hg3535" + str(match_id)
  188. sole_str = p_code + "cog_h" + str(index) + str(match_id) + "hg3535"
  189. odds_only = Helper.genearte_MD5(hash_str, pt)
  190. sole = Helper.genearte_MD5(sole_str, pt)
  191. odds_onlys.append(odds_only)
  192. half_concede_guest_key = ["match_id", "lg_id", "odds_code", "status", "sort", "p_code", "odds", "condition",
  193. "odds_only", "sole", "source", "type", "team"]
  194. condition = half_concede_guest_rule[index]
  195. half_concede_guest_value = [match_id, league_id, "cog_h", "0", index, p_code, value, condition,
  196. odds_only, sole, "hg3535", "0", ""]
  197. half_concede_guest_data = dict(zip(half_concede_guest_key, half_concede_guest_value))
  198. data_list.append(half_concede_guest_data)
  199. # half_concede_home
  200. for index, value in enumerate(half_concede_home):
  201. hash_str = p_code + "coh_h" + str(index) + str(half_concede_home_rule[index]) + str(
  202. value) + "hg3535" + str(match_id)
  203. sole_str = p_code + "coh_h" + str(index) + str(match_id) + "hg3535"
  204. odds_only = Helper.genearte_MD5(hash_str, pt)
  205. sole = Helper.genearte_MD5(sole_str, pt)
  206. half_concede_home_key = ["match_id", "lg_id", "odds_code", "status", "sort", "p_code", "odds", "condition",
  207. "odds_only", "sole", "source", "type", "team"]
  208. condition = half_concede_home_rule[index]
  209. half_concede_home_value = [match_id, league_id, "coh_h", "0", index, p_code, value, condition,
  210. odds_only, sole, "hg3535", "0", ""]
  211. half_concede_home_data = dict(zip(half_concede_home_key, half_concede_home_value))
  212. data_list.append(half_concede_home_data)
  213. concede_guest = item["concede_guest"]
  214. concede_guest_rule = item["concede_guest_rule"]
  215. concede_home = item["concede_home"]
  216. concede_home_rule = item["concede_home_rule"]
  217. # concede_guest
  218. for index, value in enumerate(concede_guest):
  219. hash_str = p_code + "cog" + str(index) + str(concede_guest_rule[index]) + str(
  220. value) + "hg3535" + str(match_id)
  221. sole_str = p_code + "cog" + str(index) + str(match_id) + "hg3535"
  222. odds_only = Helper.genearte_MD5(hash_str, pt)
  223. sole = Helper.genearte_MD5(sole_str, pt)
  224. concede_guest_key = ["match_id", "lg_id", "odds_code", "status", "sort", "p_code", "odds", "condition",
  225. "odds_only", "sole", "source", "type", "team"]
  226. condition = concede_guest[index]
  227. concede_guest_value = [match_id, league_id, "cog", "0", index, p_code, value, condition,
  228. odds_only, sole, "hg3535", "0", ""]
  229. concede_guest_data = dict(zip(concede_guest_key, concede_guest_value))
  230. data_list.append(concede_guest_data)
  231. # concede_home
  232. for index, value in enumerate(concede_home):
  233. hash_str = p_code + "coh" + str(index) + str(concede_home_rule[index]) + str(
  234. value) + "hg3535" + str(match_id)
  235. sole_str = p_code + "coh" + str(index) + str(match_id) + "hg3535"
  236. odds_only = Helper.genearte_MD5(hash_str, pt)
  237. sole = Helper.genearte_MD5(sole_str, pt)
  238. concede_home_key = ["match_id", "lg_id", "odds_code", "status", "sort", "p_code", "odds", "condition",
  239. "odds_only", "sole", "source", "type", "team"]
  240. condition = concede_home_rule[index]
  241. concede_home_value = [match_id, league_id, "coh", "0", index, p_code, value, condition, odds_only,
  242. sole, "hg3535", "0", ""]
  243. concede_guest_data = dict(zip(concede_home_key, concede_home_value))
  244. data_list.append(concede_guest_data)
  245. # 独赢----------------------------------------------------------------------------------------------------------
  246. p_code = 'C'
  247. half_capot_home = item["half_capot_home"]
  248. half_capot_guest = item["half_capot_guest"]
  249. half_capot_dogfall = item["half_capot_dogfall"]
  250. capot_home = item["capot_home"]
  251. capot_guest = item["capot_guest"]
  252. capot_dogfall = item["capot_dogfall"]
  253. # half_capot_home
  254. hash_str = p_code + "ch_h" + '0' + '1' + str(half_capot_home) + "hg3535" + str(match_id)
  255. sole_str = p_code + "ch_h" + '0' + str(match_id) + "hg3535"
  256. odds_only = Helper.genearte_MD5(hash_str, pt)
  257. sole = Helper.genearte_MD5(sole_str, pt)
  258. odds_onlys.append(odds_only)
  259. half_capot_home_key = ["match_id", "lg_id", "odds_code", "status", "sort", "p_code", "odds", "condition",
  260. "odds_only", "sole", "source", "type", "team"]
  261. half_capot_home_value = [match_id, league_id, "ch_h", "0", 0, p_code, half_capot_home, '1',
  262. odds_only, sole, "hg3535", "0", ""]
  263. half_capot_homet_data = dict(zip(half_capot_home_key, half_capot_home_value))
  264. data_list.append(half_capot_homet_data)
  265. # half_capot_guest
  266. hash_str = p_code + "cg_h" + '0' + '2' + str(half_capot_guest) + "hg3535" + str(match_id)
  267. sole_str = p_code + "cg_h" + '0' + str(match_id) + "hg3535"
  268. odds_only = Helper.genearte_MD5(hash_str, pt)
  269. sole = Helper.genearte_MD5(sole_str, pt)
  270. half_capot_guest_key = ["match_id", "lg_id", "odds_code", "status", "sort", "p_code", "odds", "condition",
  271. "odds_only", "sole", "source", "type", "team"]
  272. half_capot_guest_value = [match_id, league_id, "cg_h", "0", 0, p_code, half_capot_guest, '2',
  273. odds_only, sole, "hg3535", "0", ""]
  274. half_capot_guest_data = dict(zip(half_capot_guest_key, half_capot_guest_value))
  275. data_list.append(half_capot_guest_data)
  276. # half_capot_dogfall
  277. hash_str = p_code + "cd_h" + '0' + 'X' + str(half_capot_dogfall) + "hg3535" + str(match_id)
  278. sole_str = p_code + "cd_h" + '0' + str(match_id) + "hg3535"
  279. odds_only = Helper.genearte_MD5(hash_str, pt)
  280. sole = Helper.genearte_MD5(sole_str, pt)
  281. odds_onlys.append(odds_only)
  282. half_capot_dogfall_key = ["match_id", "lg_id", "odds_code", "status", "sort", "p_code", "odds", "condition",
  283. "odds_only", "sole", "source", "type", "team"]
  284. half_capot_dogfall_value = [match_id, league_id, "cd_h", "0", 0, p_code, half_capot_dogfall, 'X',
  285. odds_only, sole, "hg3535", "0", ""]
  286. half_capot_dogfall_data = dict(zip(half_capot_dogfall_key, half_capot_dogfall_value))
  287. data_list.append(half_capot_dogfall_data)
  288. # capot_dogfall
  289. hash_str = p_code + "cd" + '0' + 'X' + str(capot_dogfall) + "hg3535" + str(match_id)
  290. sole_str = p_code + "cd" + '0' + str(match_id) + "hg3535"
  291. odds_only = Helper.genearte_MD5(hash_str, pt)
  292. sole = Helper.genearte_MD5(sole_str, pt)
  293. capot_dogfall_key = ["match_id", "lg_id", "odds_code", "status", "sort", "p_code", "odds", "condition",
  294. "odds_only", "sole", "source", "type", "team"]
  295. capot_dogfall_value = [match_id, league_id, "cd", "0", 0, p_code, capot_dogfall, 'X', odds_only,
  296. sole, "hg3535", "0", ""]
  297. capot_dogfall_data = dict(zip(capot_dogfall_key, capot_dogfall_value))
  298. data_list.append(capot_dogfall_data)
  299. # capot_home
  300. hash_str = p_code + "ch" + '0' + '1' + str(capot_home) + "hg3535" + str(match_id)
  301. sole_str = p_code + "ch" + '0' + str(match_id) + "hg3535"
  302. odds_only = Helper.genearte_MD5(hash_str, pt)
  303. sole = Helper.genearte_MD5(sole_str, pt)
  304. capot_home_key = ["match_id", "lg_id", "odds_code", "status", "sort", "p_code", "odds", "condition",
  305. "odds_only", "sole", "source", "type", "team"]
  306. capot_home_value = [match_id, league_id, "ch", "0", 0, p_code, capot_home, '1',
  307. odds_only, sole, "hg3535", "0", ""]
  308. capot_homet_data = dict(zip(capot_home_key, capot_home_value))
  309. data_list.append(capot_homet_data)
  310. # capot_guest
  311. hash_str = p_code + "cg" + '0' + '2' + str(capot_guest) + "hg3535" + str(match_id)
  312. sole_str = p_code + "cg" + '0' + str(match_id) + "hg3535"
  313. odds_only = Helper.genearte_MD5(hash_str, pt)
  314. sole = Helper.genearte_MD5(sole_str, pt)
  315. capot_guest_key = ["match_id", "lg_id", "odds_code", "status", "sort", "p_code", "odds", "condition",
  316. "odds_only", "sole", "source", "type", "team"]
  317. capot_guest_value = [match_id, league_id, "cg", "0", 0, p_code, capot_guest, '2',
  318. odds_only, sole, "hg3535", "0", ""]
  319. capot_guest_data = dict(zip(capot_guest_key, capot_guest_value))
  320. data_list.append(capot_guest_data)
  321. # 入球数单双-----------------------------------------------------------------------------------------------------
  322. p_code = 'TS'
  323. odd_even_odd = item["odd_even_odd"]
  324. odd_even_even = item["odd_even_even"]
  325. half_odd_even_odd = item["half_odd_even_odd"]
  326. half_odd_even_even = item["half_odd_even_even"]
  327. # odd_even_odd
  328. hash_str = p_code + "tss" + '0' + '单' + str(odd_even_odd) + "hg3535" + str(match_id)
  329. sole_str = p_code + "tss" + '0' + str(match_id) + "hg3535"
  330. odds_only = Helper.genearte_MD5(hash_str, pt)
  331. sole = Helper.genearte_MD5(sole_str, pt)
  332. odds_onlys.append(odds_only)
  333. single_key = ["match_id", "lg_id", "odds_code", "status", "sort", "p_code", "odds", "condition",
  334. "odds_only", "sole", "source", "type", "team"]
  335. single_value = [match_id, league_id, "tss", "0", 0, p_code, odd_even_odd, '单',
  336. odds_only, sole, "hg3535", "0", ""]
  337. single_data = dict(zip(single_key, single_value))
  338. data_list.append(single_data)
  339. # odd_even_even
  340. hash_str = p_code + "tsd" + '0' + '双' + str(odd_even_even) + "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. double_key = ["match_id", "lg_id", "odds_code", "status", "sort", "p_code", "odds", "condition",
  345. "odds_only", "sole", "source", "type", "team"]
  346. double_value = [match_id, league_id, "tss", "0", 0, p_code, odd_even_even, '双',
  347. odds_only, sole, "hg3535", "0", ""]
  348. double_data = dict(zip(double_key, double_value))
  349. data_list.append(double_data)
  350. # half_odd_even_even
  351. hash_str = p_code + "tsd_h" + '0' + '双' + str(half_odd_even_even) + "hg3535" + str(match_id)
  352. sole_str = p_code + "tsd_h" + '0' + str(match_id) + "hg3535"
  353. odds_only = Helper.genearte_MD5(hash_str, pt)
  354. sole = Helper.genearte_MD5(sole_str, pt)
  355. half_double_key = ["match_id", "lg_id", "odds_code", "status", "sort", "p_code", "odds", "condition",
  356. "odds_only", "sole", "source", "type", "team"]
  357. half_double_value = [match_id, league_id, "tsd_h", "0", 0, p_code, half_odd_even_even, '双',
  358. odds_only, sole, "hg3535", "0", ""]
  359. half_double_data = dict(zip(half_double_key, half_double_value))
  360. data_list.append(half_double_data)
  361. # half_odd_even_odd
  362. hash_str = p_code + "tss_h" + '0' + '单' + str(half_odd_even_odd) + "hg3535" + str(match_id)
  363. sole_str = p_code + "tss_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_single_key = ["match_id", "lg_id", "odds_code", "status", "sort", "p_code", "odds", "condition",
  367. "odds_only", "sole", "source", "type", "team"]
  368. half_single_value = [match_id, league_id, "tss_h", "0", 0, p_code, half_odd_even_odd, '单', odds_only,
  369. sole, "hg3535", "0", ""]
  370. half_single_data = dict(zip(half_single_key, half_single_value))
  371. data_list.append(half_single_data)
  372. # 总入球数 ------------------------------------------------------------------------------------------------------
  373. total_goals = item['total_goal']
  374. total_dict = {'tg0': '0-1', 'tg1': '2-3', 'tg2': '4-6','tg3': '7或以上', 'tg0_h': '0', "tg1_h": '1',
  375. "tg2_h": '2', "tg3_h": '3或以上'}
  376. # 全场入球数 单双
  377. for key, value in total_goals.items():
  378. hash_str = p_code + key + '0' + total_dict[key] + str(value) + "hg3535" + str(match_id)
  379. sole_str = p_code + key + '0' + str(match_id) + "hg3535"
  380. odds_only = Helper.genearte_MD5(hash_str, pt)
  381. sole = Helper.genearte_MD5(sole_str, pt)
  382. total_goals_key = ["match_id", "lg_id", "odds_code", "status", "sort", "p_code", "odds", "condition",
  383. "odds_only", "sole", "source", "type", "team"]
  384. total_goals_value = [match_id, league_id, key, "0", 0, p_code, value, total_dict[key], odds_only,
  385. sole, "hg3535", "0", ""]
  386. total_goals_data = dict(zip(total_goals_key, total_goals_value))
  387. data_list.append(total_goals_data)
  388. # 全场半场 ------------------------------------------------------------------------------------------------------
  389. half_fulls = item['half_full']
  390. # p_code, p_id = get_pcode(corner_ball, 'half_full')
  391. p_code = 'HF'
  392. full_dict = {"hfhh": "主主", "hfhd": "主和", "hfhg": "主客", "hfdh": "和主",
  393. "hfdd": "和和", "hfdg": "和客", "hfgh": "客主", "hfgd": "客和", "hfgg": "客客"}
  394. if half_fulls:
  395. for key, value in half_fulls.items():
  396. hash_str = p_code + key + '0' + full_dict[key] + str(value) + "hg3535" + str(match_id)
  397. sole_str = p_code + key + '0' + str(match_id) + "hg3535"
  398. odds_only = Helper.genearte_MD5(hash_str, pt)
  399. sole = Helper.genearte_MD5(sole_str, pt)
  400. half_fulls_key = ["match_id", "lg_id", "odds_code", "status", "sort", "p_code", "odds", "condition",
  401. "odds_only", "sole", "source", "type", "team"]
  402. half_fulls_value = [match_id, league_id, key, "0", 0, p_code, value, full_dict[key], odds_only,
  403. sole, "hg3535", "0", ""]
  404. half_fulls_data = dict(zip(half_fulls_key, half_fulls_value))
  405. data_list.append(half_fulls_data)
  406. # 波胆------------------------------------------------------------------------------------------------------------------
  407. bodan_datas = item['bodan_data']
  408. p_code, p_id = get_pcode(corner_ball, 'bodan')
  409. bodan_dict = {"b10": "1-0", "b20": "2-0", "b21": "2-1", "b30": "3-0", "b31": "3-1", "b32": "3-2",
  410. "b40": "4-0", "b41": "4-1", "b42": "4-2", "b43": "4-3", "b01": "0-1", "b02": "0-2",
  411. "b12": "1-2", "b03": "0-3", "b13": "1-3", "b23": "2-3", "b04": "0-4", "b14": "1-4",
  412. "b24": "2-4", "b34": "3-4", "b00": "0-0", "b11": "1-1", "b22": "2-2", "b33": "3-3",
  413. "b44": "4-4", "bo": "其他", "b10_h": "1-0", "b20_h": "2-0", "b21_h": "2-1", "b30_h": "3-0",
  414. "b31_h": "3-1", "b32_h": "3-2", "b01_h": "0-1", "b02_h": "0-2", "b12_h": "1-2", "b03_h": "0-3",
  415. "b13_h": "1-3", "b23_h": "2-3", "b00_h": "0-0", "b11_h": "1-1", "b22_h": "2-2", "b33_h": "3-3",
  416. "bo_h": "其他"}
  417. if bodan_datas:
  418. for key, value in bodan_datas.items():
  419. hash_str = p_code + key + '0' + bodan_dict[key] + str(value) + "hg3535" + str(match_id)
  420. sole_str = p_code + key + '0' + str(match_id) + "hg3535"
  421. odds_only = Helper.genearte_MD5(hash_str, pt)
  422. sole = Helper.genearte_MD5(sole_str, pt)
  423. bodan_dict_key = ["match_id", "lg_id", "odds_code", "status", "sort", "p_code", "odds", "condition",
  424. "odds_only", "sole", "source", "type", "team"]
  425. bodan_dict_value = [match_id, league_id, key, "0", 0, p_code, value, bodan_dict[key], odds_only,
  426. sole, "hg3535", "0", ""]
  427. bodan_dict_data = dict(zip(bodan_dict_key, bodan_dict_value))
  428. data_list.append(bodan_dict_data)
  429. # 最先进球/最后进球 ----------------------------------------------------------------------------------------------
  430. first_last_balls = item['first_last_ball']
  431. p_code = 'FLB'
  432. first_last_dict = {"flbfh": "最先进球", "flbfg": "最先进球", "flblh": "最后进球", "flblg": "最后进球", "flbn": "没有进球"}
  433. if first_last_balls:
  434. for key, value in first_last_balls.items():
  435. hash_str = p_code + key + '0' + first_last_dict[key] + str(value) + "hg3535" + str(match_id)
  436. sole_str = p_code + key + '0' + str(match_id) + "hg3535"
  437. odds_only = Helper.genearte_MD5(hash_str, pt)
  438. sole = Helper.genearte_MD5(sole_str, pt)
  439. odds_onlys.append(odds_only)
  440. first_last_balls_key = ["match_id", "lg_id", "odds_code", "status", "sort", "p_code", "odds",
  441. "condition",
  442. "odds_only", "sole", "source", "type", "team"]
  443. first_last_balls_value = [match_id, league_id, key, "0", 0, p_code, value, first_last_dict[key],
  444. odds_only,
  445. sole, "hg3535", "0", ""]
  446. first_last_balls_data = dict(zip(first_last_balls_key, first_last_balls_value))
  447. data_list.append(first_last_balls_data)
  448. p_code = 'TB'
  449. # 球队得分全场,上半场
  450. full_dicts = item['full_data']
  451. half_dicts = item['half_data']
  452. full_dict_rules = item['full_data_rule']
  453. half_dict_rules = item['half_data_rule']
  454. if full_dicts:
  455. for key, value in full_dicts.items():
  456. hash_str = p_code + key + '0' + full_dict_rules[key] + str(value) + "hg3535" + str(match_id)
  457. sole_str = p_code + key + '0' + str(match_id) + "hg3535"
  458. odds_only = Helper.genearte_MD5(hash_str, pt)
  459. sole = Helper.genearte_MD5(sole_str, pt)
  460. odds_onlys.append(odds_only)
  461. full_dict_rules_key = ["match_id", "lg_id", "odds_code", "status", "sort", "p_code", "odds",
  462. "condition", "odds_only", "sole", "source", "type", "team"]
  463. full_dict_rules_value = [match_id, league_id, key, "0", 0, p_code, value, full_dict_rules[key],
  464. odds_only, sole, "hg3535", "0", ""]
  465. full_dict_rules_data = dict(zip(full_dict_rules_key, full_dict_rules_value))
  466. data_list.append(full_dict_rules_data)
  467. if half_dicts:
  468. for key, value in half_dicts.items():
  469. hash_str = p_code + key + '0' + half_dict_rules[key] + str(value) + "hg3535" + str(match_id)
  470. sole_str = p_code + key + '0' + str(match_id) + "hg3535"
  471. odds_only = Helper.genearte_MD5(hash_str, pt)
  472. sole = Helper.genearte_MD5(sole_str, pt)
  473. odds_onlys.append(odds_only)
  474. half_dicts_key = ["match_id", "lg_id", "odds_code", "status", "sort", "p_code", "odds",
  475. "condition", "odds_only", "sole", "source", "type", "team"]
  476. half_dicts_value = [match_id, league_id, key, "0", 0, p_code, value, half_dict_rules[key],
  477. odds_only, sole, "hg3535", "0", ""]
  478. half_dicts_data = dict(zip(half_dicts_key, half_dicts_value))
  479. data_list.append(half_dicts_data)
  480. odds_key = ["game_code", "title", "match_id", "lg_id", "data", "source", "odds_only", "tag", "uuid",
  481. "is_stringscene", "utime", "pt"]
  482. odds_value = ["zq", "odds", match_id, league_id, data_list, "hg3535", odds_onlys, number, uuid,
  483. 0, utime, pt]
  484. odds_dict = dict(zip(odds_key, odds_value))
  485. if data_list:
  486. res = Helper.async_post(ODDS_URL, odds_dict)
  487. if res:
  488. if "成功" in res:
  489. logger.info('足球滚球详细赔率提交成功, {}'.format(res))
  490. else:
  491. logger.warning('足球滚球详细赔率提交失败, {}'.format(res))
  492. logger.warning(odds_dict)
  493. else:
  494. logger.warning('足球滚球详细赔率接口异常,提交失败, {}'.format(res))
  495. logger.warning(odds_dict)
  496. else:
  497. logger.info('足球滚球详细赔率列表为空')
  498. data_list = []
  499. zq_rball = {"home_team": team_home, "guest_team": team_guest,
  500. "lg_id": league_id, "home_rate": 0,
  501. "guest_rate": 0, "home_score": score_home,
  502. "guest_score": score_guest, "all_goal": all_goal, "status": 1,
  503. "first_score": "", "last_score": "", "match_score": match_score, "uuid": uuid,
  504. "match_winer": "", "match_time": time_game,
  505. "match_process": half_way, "tag": number,
  506. "match_id": match_id, "p_code": ""}
  507. data_list.append(zq_rball)
  508. r_data_dict = {
  509. "game_code": "zq",
  510. "title": "match_result_r",
  511. "source": "hg3535",
  512. "data": data_list
  513. }
  514. if data_list:
  515. try:
  516. res = Helper.async_post(MATCH_RESULT, r_data_dict)
  517. if res:
  518. if "成功" in res:
  519. logger.info('足球滚球结果记录提交成功, {}'.format(res))
  520. logger.info(r_data_dict)
  521. else:
  522. logger.warning('足球滚球结果记录提交失败, {}'.format(res))
  523. logger.warning(r_data_dict)
  524. else:
  525. logger.warning('足球滚球结果记录接口异常,提交失败, {}'.format(res))
  526. logger.warning(r_data_dict)
  527. except Exception as e:
  528. logger.warning('滚球数据接口异常,提交失败, {}'.format(e))
  529. reactor.callFromThread(out.callback, item)