roll_zuqiu.py 35 KB

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