roll_zuqiu.py 32 KB

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