roll_zuqiu.py 34 KB

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