roll_zuqiu.py 31 KB

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