roll_zuqiu.py 41 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701
  1. # import datetime
  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, LEAGUE_URL, ODDS_URL, MATCH_URL, MATCH_RESULT
  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. 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())
  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 + 'hg3535')
  51. horn_team = item['horn_team']
  52. if self.db.zq_league35.find({'league_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(LEAGUE_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))
  67. logger.warning(league_dict)
  68. else:
  69. logger.warning('足球滚球联赛接口异常提交失败, {}'.format(res))
  70. logger.warning(league_dict)
  71. else:
  72. logger.info('足球滚球联赛已存在, 不存在')
  73. if self.db.zq_competition35.find({"match_id": match_id, 'is_rollball': 1}).count() < 1:
  74. match_list = []
  75. match_dict = {"game_code": "zq", "title": "match", "source": "hg3535"}
  76. match_kay = ["home_team", "guest_team", "lg_id", "status", "match_id", "match_date", "match_time",
  77. "tag", "source", "is_rollball", "is_morningplate", "is_stringscene", "us_time", "uuid",
  78. "half_match_id", "is_today", "is_horn"]
  79. match_value = [team_home, team_guest, league_id, 1, match_id, match_date, match_time, number,
  80. "hg3535", 1, 0, 0, utime, uuid, 0, 0, 0]
  81. match_data = dict(zip(match_kay, match_value))
  82. match_list.append(match_data)
  83. match_dict['data'] = match_list
  84. res = Helper.async_post(MATCH_URL, match_dict)
  85. if res:
  86. if res.get('status') == 1:
  87. self.db.zq_competition35.insert(match_data)
  88. logger.info('足球滚球赛事提交成功, {}'.format(res))
  89. logger.info(match_data)
  90. else:
  91. logger.warning('足球滚球赛事,提交失败, {}'.format(res))
  92. logger.warning(match_data)
  93. else:
  94. logger.warning('足球滚球赛事接口异常提交失败, {}'.format(res))
  95. logger.warning(match_data)
  96. else:
  97. logger.info('足球滚球赛事已存在, 不提交')
  98. p_code = "GS"
  99. # 构建唯一索引
  100. half_size_guest = item["half_size_guest"]
  101. half_size_guest_rule = item["half_size_guest_rule"]
  102. half_size_home = item["half_size_home"]
  103. half_size_home_rule = item["half_size_home_rule"]
  104. data_list = []
  105. odds_onlys = []
  106. # half_size_guest
  107. for index, value in enumerate(half_size_guest):
  108. hash_str = p_code + "gss_h" + str(index) + str(half_size_guest_rule[index]) + str(
  109. value) + "hg3535" + str(match_id)
  110. sole_str = p_code + "gss_h" + str(index) + str(match_id) + "hg3535"
  111. odds_only = Helper.genearte_MD5(hash_str, pt)
  112. sole = Helper.genearte_MD5(sole_str, pt)
  113. half_size_guest_key = ["match_id", "lg_id", "odds_code", "status", "sort", "p_code", "odds", "condition",
  114. "odds_only", "sole", "source", "type", "team"]
  115. condition = half_size_guest_rule[index]
  116. half_size_guest_value = [match_id, league_id, "gss_h", "0", index, p_code, value, condition,
  117. odds_only, sole, "hg3535", "0", ""]
  118. half_size_guest_data = dict(zip(half_size_guest_key, half_size_guest_value))
  119. data_list.append(half_size_guest_data)
  120. # half_size_home
  121. for index, value in enumerate(half_size_home):
  122. hash_str = p_code + "gsb_h" + str(index) + str(half_size_home_rule[index]) + str(
  123. value) + "hg3535" + str(match_id)
  124. sole_str = p_code + "gsb_h" + str(index) + str(match_id) + "hg3535"
  125. odds_only = Helper.genearte_MD5(hash_str, pt)
  126. sole = Helper.genearte_MD5(sole_str, pt)
  127. half_size_home_key = ["match_id", "lg_id", "odds_code", "status", "sort", "p_code", "odds", "condition",
  128. "odds_only", "sole", "source", "type", "team"]
  129. condition = half_size_home_rule[index]
  130. half_size_home_value = [match_id, league_id, "gsb_h", "0", index, p_code, value, condition,
  131. odds_only, sole, "hg3535", "0", ""]
  132. half_size_home_data = dict(zip(half_size_home_key, half_size_home_value))
  133. data_list.append(half_size_home_data)
  134. # 全场场大小
  135. size_guest = item["size_guest"]
  136. size_guest_rule = item["size_guest_rule"]
  137. size_home = item["size_home"]
  138. size_home_rule = item["size_home_rule"]
  139. # size_home
  140. for index, value in enumerate(size_home):
  141. hash_str = p_code + "gsb" + str(index) + str(size_home_rule[index]) + str(value) + "hg3535" + str(
  142. match_id)
  143. sole_str = p_code + "gsb" + str(index) + str(match_id) + "hg3535"
  144. odds_only = Helper.genearte_MD5(hash_str, pt)
  145. sole = Helper.genearte_MD5(sole_str, pt)
  146. size_home_key = ["match_id", "lg_id", "odds_code", "status", "sort", "p_code", "odds", "condition",
  147. "odds_only", "sole", "source", "type", "team"]
  148. condition = size_home_rule[index]
  149. size_home_value = [match_id, league_id, "gsb", "0", index, p_code, value, condition, odds_only,
  150. sole, "hg3535", "0", ""]
  151. size_home_data = dict(zip(size_home_key, size_home_value))
  152. data_list.append(size_home_data)
  153. # size_guest
  154. for index, value in enumerate(size_guest):
  155. hash_str = p_code + "gss" + str(index) + str(size_guest_rule[index]) + str(value) + "hg3535" + str(
  156. match_id)
  157. sole_str = p_code + "gss" + str(index) + str(match_id) + "hg3535"
  158. odds_only = Helper.genearte_MD5(hash_str, pt)
  159. sole = Helper.genearte_MD5(sole_str, pt)
  160. size_guest_key = ["match_id", "lg_id", "odds_code", "status", "sort", "p_code", "odds", "condition",
  161. "odds_only", "sole", "source", "type", "team"]
  162. condition = size_guest_rule[index]
  163. size_guest_value = [match_id, league_id, "gss", "0", index, p_code, value, condition, odds_only,
  164. sole, "hg3535", "0", ""]
  165. size_home_data = dict(zip(size_guest_key, size_guest_value))
  166. data_list.append(size_home_data)
  167. p_code = 'CO'
  168. half_concede_home_rule = item["half_concede_home_rule"]
  169. half_concede_home = item["half_concede_home"]
  170. half_concede_guest_rule = item["half_concede_guest_rule"]
  171. half_concede_guest = item["half_concede_guest"]
  172. # half_concede_home
  173. for index, value in enumerate(half_concede_guest):
  174. hash_str = p_code + "cog_h" + str(index) + str(half_concede_guest_rule[index]) + str(
  175. value) + "hg3535" + str(match_id)
  176. sole_str = p_code + "cog_h" + str(index) + str(match_id) + "hg3535"
  177. odds_only = Helper.genearte_MD5(hash_str, pt)
  178. sole = Helper.genearte_MD5(sole_str, pt)
  179. half_concede_guest_key = ["match_id", "lg_id", "odds_code", "status", "sort", "p_code", "odds", "condition",
  180. "odds_only", "sole", "source", "type", "team"]
  181. condition = half_concede_guest_rule[index]
  182. half_concede_guest_value = [match_id, league_id, "cog_h", "0", index, p_code, value, condition,
  183. odds_only, sole, "hg3535", "0", ""]
  184. half_concede_guest_data = dict(zip(half_concede_guest_key, half_concede_guest_value))
  185. data_list.append(half_concede_guest_data)
  186. # half_concede_home
  187. for index, value in enumerate(half_concede_home):
  188. hash_str = p_code + "coh_h" + str(index) + str(half_concede_home_rule[index]) + str(
  189. value) + "hg3535" + str(match_id)
  190. sole_str = p_code + "coh_h" + str(index) + str(match_id) + "hg3535"
  191. odds_only = Helper.genearte_MD5(hash_str, pt)
  192. sole = Helper.genearte_MD5(sole_str, pt)
  193. half_concede_home_key = ["match_id", "lg_id", "odds_code", "status", "sort", "p_code", "odds", "condition",
  194. "odds_only", "sole", "source", "type", "team"]
  195. condition = half_concede_home_rule[index]
  196. half_concede_home_value = [match_id, league_id, "coh_h", "0", index, p_code, value, condition,
  197. odds_only, sole, "hg3535", "0", ""]
  198. half_concede_home_data = dict(zip(half_concede_home_key, half_concede_home_value))
  199. data_list.append(half_concede_home_data)
  200. concede_guest = item["concede_guest"]
  201. concede_guest_rule = item["concede_guest_rule"]
  202. concede_home = item["concede_home"]
  203. concede_home_rule = item["concede_home_rule"]
  204. # concede_guest
  205. for index, value in enumerate(concede_guest):
  206. hash_str = p_code + "cog" + str(index) + str(concede_guest_rule[index]) + str(
  207. value) + "hg3535" + str(match_id)
  208. sole_str = p_code + "cog" + str(index) + str(match_id) + "hg3535"
  209. odds_only = Helper.genearte_MD5(hash_str, pt)
  210. sole = Helper.genearte_MD5(sole_str, pt)
  211. concede_guest_key = ["match_id", "lg_id", "odds_code", "status", "sort", "p_code", "odds", "condition",
  212. "odds_only", "sole", "source", "type", "team"]
  213. condition = concede_guest_rule[index]
  214. concede_guest_value = [match_id, league_id, "cog", "0", index, p_code, value, condition,
  215. odds_only, sole, "hg3535", "0", ""]
  216. concede_guest_data = dict(zip(concede_guest_key, concede_guest_value))
  217. data_list.append(concede_guest_data)
  218. # concede_home
  219. for index, value in enumerate(concede_home):
  220. hash_str = p_code + "coh" + str(index) + str(concede_home_rule[index]) + str(
  221. value) + "hg3535" + str(match_id)
  222. sole_str = p_code + "coh" + str(index) + str(match_id) + "hg3535"
  223. odds_only = Helper.genearte_MD5(hash_str, pt)
  224. sole = Helper.genearte_MD5(sole_str, pt)
  225. concede_home_key = ["match_id", "lg_id", "odds_code", "status", "sort", "p_code", "odds", "condition",
  226. "odds_only", "sole", "source", "type", "team"]
  227. condition = concede_home_rule[index]
  228. concede_home_value = [match_id, league_id, "coh", "0", index, p_code, value, condition, odds_only,
  229. sole, "hg3535", "0", ""]
  230. concede_guest_data = dict(zip(concede_home_key, concede_home_value))
  231. data_list.append(concede_guest_data)
  232. # 独赢-------------------------------------------------------------------------------------------------------
  233. p_code = 'C'
  234. half_capot_home = item["half_capot_home"]
  235. half_capot_guest = item["half_capot_guest"]
  236. half_capot_dogfall = item["half_capot_dogfall"]
  237. capot_home = item["capot_home"]
  238. capot_guest = item["capot_guest"]
  239. capot_dogfall = item["capot_dogfall"]
  240. # half_capot_home
  241. hash_str = p_code + "ch_h" + '0' + '1' + str(half_capot_home) + "hg3535" + str(match_id)
  242. sole_str = p_code + "ch_h" + '0' + str(match_id) + "hg3535"
  243. odds_only = Helper.genearte_MD5(hash_str, pt)
  244. sole = Helper.genearte_MD5(sole_str, pt)
  245. half_capot_home_key = ["match_id", "lg_id", "odds_code", "status", "sort", "p_code", "odds", "condition",
  246. "odds_only", "sole", "source", "type", "team"]
  247. half_capot_home_value = [match_id, league_id, "ch_h", "0", 0, p_code, half_capot_home, '1',
  248. odds_only, sole, "hg3535", "0", ""]
  249. half_capot_homet_data = dict(zip(half_capot_home_key, half_capot_home_value))
  250. data_list.append(half_capot_homet_data)
  251. # half_capot_guest
  252. hash_str = p_code + "cg_h" + '0' + '2' + str(half_capot_guest) + "hg3535" + str(match_id)
  253. sole_str = p_code + "cg_h" + '0' + str(match_id) + "hg3535"
  254. odds_only = Helper.genearte_MD5(hash_str, pt)
  255. sole = Helper.genearte_MD5(sole_str, pt)
  256. half_capot_guest_key = ["match_id", "lg_id", "odds_code", "status", "sort", "p_code", "odds", "condition",
  257. "odds_only", "sole", "source", "type", "team"]
  258. half_capot_guest_value = [match_id, league_id, "cg_h", "0", 0, p_code, half_capot_guest, '2',
  259. odds_only, sole, "hg3535", "0", ""]
  260. half_capot_guest_data = dict(zip(half_capot_guest_key, half_capot_guest_value))
  261. data_list.append(half_capot_guest_data)
  262. # half_capot_dogfall
  263. hash_str = p_code + "cd_h" + '0' + 'X' + str(half_capot_dogfall) + "hg3535" + str(match_id)
  264. sole_str = p_code + "cd_h" + '0' + str(match_id) + "hg3535"
  265. odds_only = Helper.genearte_MD5(hash_str, pt)
  266. sole = Helper.genearte_MD5(sole_str, pt)
  267. half_capot_dogfall_key = ["match_id", "lg_id", "odds_code", "status", "sort", "p_code", "odds", "condition",
  268. "odds_only", "sole", "source", "type", "team"]
  269. half_capot_dogfall_value = [match_id, league_id, "cd_h", "0", 0, p_code, half_capot_dogfall, 'X',
  270. odds_only, sole, "hg3535", "0", ""]
  271. half_capot_dogfall_data = dict(zip(half_capot_dogfall_key, half_capot_dogfall_value))
  272. data_list.append(half_capot_dogfall_data)
  273. # capot_dogfall
  274. hash_str = p_code + "cd" + '0' + 'X' + str(capot_dogfall) + "hg3535" + str(match_id)
  275. sole_str = p_code + "cd" + '0' + str(match_id) + "hg3535"
  276. odds_only = Helper.genearte_MD5(hash_str, pt)
  277. sole = Helper.genearte_MD5(sole_str, pt)
  278. capot_dogfall_key = ["match_id", "lg_id", "odds_code", "status", "sort", "p_code", "odds", "condition",
  279. "odds_only", "sole", "source", "type", "team"]
  280. capot_dogfall_value = [match_id, league_id, "cd", "0", 0, p_code, capot_dogfall, 'X', odds_only,
  281. sole, "hg3535", "0", ""]
  282. capot_dogfall_data = dict(zip(capot_dogfall_key, capot_dogfall_value))
  283. data_list.append(capot_dogfall_data)
  284. # capot_home
  285. hash_str = p_code + "ch" + '0' + '1' + str(capot_home) + "hg3535" + str(match_id)
  286. sole_str = p_code + "ch" + '0' + str(match_id) + "hg3535"
  287. odds_only = Helper.genearte_MD5(hash_str, pt)
  288. sole = Helper.genearte_MD5(sole_str, pt)
  289. capot_home_key = ["match_id", "lg_id", "odds_code", "status", "sort", "p_code", "odds", "condition",
  290. "odds_only", "sole", "source", "type", "team"]
  291. capot_home_value = [match_id, league_id, "ch", "0", 0, p_code, capot_home, '1',
  292. odds_only, sole, "hg3535", "0", ""]
  293. capot_homet_data = dict(zip(capot_home_key, capot_home_value))
  294. data_list.append(capot_homet_data)
  295. # capot_guest
  296. hash_str = p_code + "cg" + '0' + '2' + str(capot_guest) + "hg3535" + str(match_id)
  297. sole_str = p_code + "cg" + '0' + str(match_id) + "hg3535"
  298. odds_only = Helper.genearte_MD5(hash_str, pt)
  299. sole = Helper.genearte_MD5(sole_str, pt)
  300. capot_guest_key = ["match_id", "lg_id", "odds_code", "status", "sort", "p_code", "odds", "condition",
  301. "odds_only", "sole", "source", "type", "team"]
  302. capot_guest_value = [match_id, league_id, "cg", "0", 0, p_code, capot_guest, '2',
  303. odds_only, sole, "hg3535", "0", ""]
  304. capot_guest_data = dict(zip(capot_guest_key, capot_guest_value))
  305. data_list.append(capot_guest_data)
  306. # 入球数单双--------------------------------------------------------------------------------------------------
  307. p_code = 'TS'
  308. odd_even_odd = item["odd_even_odd"]
  309. odd_even_even = item["odd_even_even"]
  310. half_odd_even_odd = item["half_odd_even_odd"]
  311. half_odd_even_even = item["half_odd_even_even"]
  312. # odd_even_odd
  313. hash_str = p_code + "tss" + '0' + '单' + str(odd_even_odd) + "hg3535" + str(match_id)
  314. sole_str = p_code + "tss" + '0' + str(match_id) + "hg3535"
  315. odds_only = Helper.genearte_MD5(hash_str, pt)
  316. sole = Helper.genearte_MD5(sole_str, pt)
  317. single_key = ["match_id", "lg_id", "odds_code", "status", "sort", "p_code", "odds", "condition",
  318. "odds_only", "sole", "source", "type", "team"]
  319. single_value = [match_id, league_id, "tss", "0", 0, p_code, odd_even_odd, '单',
  320. odds_only, sole, "hg3535", "0", ""]
  321. single_data = dict(zip(single_key, single_value))
  322. data_list.append(single_data)
  323. # odd_even_even
  324. hash_str = p_code + "tsd" + '0' + '双' + str(odd_even_even) + "hg3535" + str(match_id)
  325. sole_str = p_code + "tsd" + '0' + str(match_id) + "hg3535"
  326. odds_only = Helper.genearte_MD5(hash_str, pt)
  327. sole = Helper.genearte_MD5(sole_str, pt)
  328. double_key = ["match_id", "lg_id", "odds_code", "status", "sort", "p_code", "odds", "condition",
  329. "odds_only", "sole", "source", "type", "team"]
  330. double_value = [match_id, league_id, "tsd", "0", 0, p_code, odd_even_even, '双',
  331. odds_only, sole, "hg3535", "0", ""]
  332. double_data = dict(zip(double_key, double_value))
  333. data_list.append(double_data)
  334. # half_odd_even_even
  335. hash_str = p_code + "tsd_h" + '0' + '双' + str(half_odd_even_even) + "hg3535" + str(match_id)
  336. sole_str = p_code + "tsd_h" + '0' + str(match_id) + "hg3535"
  337. odds_only = Helper.genearte_MD5(hash_str, pt)
  338. sole = Helper.genearte_MD5(sole_str, pt)
  339. half_double_key = ["match_id", "lg_id", "odds_code", "status", "sort", "p_code", "odds", "condition",
  340. "odds_only", "sole", "source", "type", "team"]
  341. half_double_value = [match_id, league_id, "tsd_h", "0", 0, p_code, half_odd_even_even, '双',
  342. odds_only, sole, "hg3535", "0", ""]
  343. half_double_data = dict(zip(half_double_key, half_double_value))
  344. data_list.append(half_double_data)
  345. # half_odd_even_odd
  346. hash_str = p_code + "tss_h" + '0' + '单' + str(half_odd_even_odd) + "hg3535" + str(match_id)
  347. sole_str = p_code + "tss_h" + '0' + str(match_id) + "hg3535"
  348. odds_only = Helper.genearte_MD5(hash_str, pt)
  349. sole = Helper.genearte_MD5(sole_str, pt)
  350. half_single_key = ["match_id", "lg_id", "odds_code", "status", "sort", "p_code", "odds", "condition",
  351. "odds_only", "sole", "source", "type", "team"]
  352. half_single_value = [match_id, league_id, "tss_h", "0", 0, p_code, half_odd_even_odd, '单', odds_only,
  353. sole, "hg3535", "0", ""]
  354. half_single_data = dict(zip(half_single_key, half_single_value))
  355. data_list.append(half_single_data)
  356. p_code = 'TG'
  357. # 总入球数 ---------------------------------------------------------------------------------------------------
  358. total_goals = item['total_goal']
  359. total_dict = {'tg0': '0-1', 'tg1': '2-3', 'tg2': '4-6', 'tg3': '7或以上', 'tg0_h': '0', "tg1_h": '1',
  360. "tg2_h": '2', "tg3_h": '3或以上'}
  361. # 全场入球数 单双
  362. for key, value in total_goals.items():
  363. hash_str = p_code + key + '0' + total_dict[key] + str(value) + "hg3535" + str(match_id)
  364. sole_str = p_code + key + '0' + str(match_id) + "hg3535"
  365. odds_only = Helper.genearte_MD5(hash_str, pt)
  366. sole = Helper.genearte_MD5(sole_str, pt)
  367. total_goals_key = ["match_id", "lg_id", "odds_code", "status", "sort", "p_code", "odds", "condition",
  368. "odds_only", "sole", "source", "type", "team"]
  369. total_goals_value = [match_id, league_id, key, "0", 0, p_code, value, total_dict[key], odds_only,
  370. sole, "hg3535", "0", ""]
  371. total_goals_data = dict(zip(total_goals_key, total_goals_value))
  372. data_list.append(total_goals_data)
  373. # 全场半场 ---------------------------------------------------------------------------------------------------
  374. half_fulls = item['half_full']
  375. # p_code, p_id = get_pcode(corner_ball, 'half_full')
  376. p_code = 'HF'
  377. full_dict = {"hfhh": "主主", "hfhd": "主和", "hfhg": "主客", "hfdh": "和主",
  378. "hfdd": "和和", "hfdg": "和客", "hfgh": "客主", "hfgd": "客和", "hfgg": "客客"}
  379. if half_fulls:
  380. for key, value in half_fulls.items():
  381. hash_str = p_code + key + '0' + full_dict[key] + str(value) + "hg3535" + str(match_id)
  382. sole_str = p_code + key + '0' + str(match_id) + "hg3535"
  383. odds_only = Helper.genearte_MD5(hash_str, pt)
  384. sole = Helper.genearte_MD5(sole_str, pt)
  385. half_fulls_key = ["match_id", "lg_id", "odds_code", "status", "sort", "p_code", "odds", "condition",
  386. "odds_only", "sole", "source", "type", "team"]
  387. half_fulls_value = [match_id, league_id, key, "0", 0, p_code, value, full_dict[key], odds_only,
  388. sole, "hg3535", "0", ""]
  389. half_fulls_data = dict(zip(half_fulls_key, half_fulls_value))
  390. data_list.append(half_fulls_data)
  391. # 波胆-------------------------------------------------------------------------------------------------------
  392. p_code = 'B'
  393. bodan_datas = item['bodan_data']
  394. # p_code, p_id = get_pcode(corner_ball, 'bodan')
  395. bodan_dict = {"b10": "1-0", "b20": "2-0", "b21": "2-1", "b30": "3-0", "b31": "3-1", "b32": "3-2",
  396. "b40": "4-0", "b41": "4-1", "b42": "4-2", "b43": "4-3", "b01": "0-1", "b02": "0-2",
  397. "b12": "1-2", "b03": "0-3", "b13": "1-3", "b23": "2-3", "b04": "0-4", "b14": "1-4",
  398. "b24": "2-4", "b34": "3-4", "b00": "0-0", "b11": "1-1", "b22": "2-2", "b33": "3-3",
  399. "b44": "4-4", "bo": "其他", "b10_h": "1-0", "b20_h": "2-0", "b21_h": "2-1", "b30_h": "3-0",
  400. "b31_h": "3-1", "b32_h": "3-2", "b01_h": "0-1", "b02_h": "0-2", "b12_h": "1-2", "b03_h": "0-3",
  401. "b13_h": "1-3", "b23_h": "2-3", "b00_h": "0-0", "b11_h": "1-1", "b22_h": "2-2", "b33_h": "3-3",
  402. "bo_h": "其他"}
  403. if bodan_datas:
  404. for key, value in bodan_datas.items():
  405. hash_str = p_code + key + '0' + bodan_dict[key] + str(value) + "hg3535" + str(match_id)
  406. sole_str = p_code + key + '0' + str(match_id) + "hg3535"
  407. odds_only = Helper.genearte_MD5(hash_str, pt)
  408. sole = Helper.genearte_MD5(sole_str, pt)
  409. bodan_dict_key = ["match_id", "lg_id", "odds_code", "status", "sort", "p_code", "odds", "condition",
  410. "odds_only", "sole", "source", "type", "team"]
  411. bodan_dict_value = [match_id, league_id, key, "0", 0, p_code, value, bodan_dict[key], odds_only,
  412. sole, "hg3535", "0", ""]
  413. bodan_dict_data = dict(zip(bodan_dict_key, bodan_dict_value))
  414. data_list.append(bodan_dict_data)
  415. # 最先进球/最后进球 -------------------------------------------------------------------------------------------
  416. first_last_balls = item['first_last_ball']
  417. p_code = 'FLB'
  418. first_last_dict = {"flbfh": "最先进球", "flbfg": "最先进球", "flblh": "最后进球", "flblg": "最后进球", "flbn": "没有进球"}
  419. if first_last_balls:
  420. for key, value in first_last_balls.items():
  421. hash_str = p_code + key + '0' + first_last_dict[key] + str(value) + "hg3535" + str(match_id)
  422. sole_str = p_code + key + '0' + str(match_id) + "hg3535"
  423. odds_only = Helper.genearte_MD5(hash_str, pt)
  424. sole = Helper.genearte_MD5(sole_str, pt)
  425. first_last_balls_key = ["match_id", "lg_id", "odds_code", "status", "sort", "p_code", "odds",
  426. "condition",
  427. "odds_only", "sole", "source", "type", "team"]
  428. first_last_balls_value = [match_id, league_id, key, "0", 0, p_code, value, first_last_dict[key],
  429. odds_only,
  430. sole, "hg3535", "0", ""]
  431. first_last_balls_data = dict(zip(first_last_balls_key, first_last_balls_value))
  432. data_list.append(first_last_balls_data)
  433. p_code = 'TB'
  434. # 球队得分全场,上半场
  435. full_dicts = item['full_data']
  436. half_dicts = item['half_data']
  437. full_dict_rules = item['full_data_rule']
  438. half_dict_rules = item['half_data_rule']
  439. if full_dicts:
  440. for key, value in full_dicts.items():
  441. hash_str = p_code + key + '0' + full_dict_rules[key] + str(value) + "hg3535" + str(match_id)
  442. sole_str = p_code + key + '0' + str(match_id) + "hg3535"
  443. odds_only = Helper.genearte_MD5(hash_str, pt)
  444. sole = Helper.genearte_MD5(sole_str, pt)
  445. full_dict_rules_key = ["match_id", "lg_id", "odds_code", "status", "sort", "p_code", "odds",
  446. "condition", "odds_only", "sole", "source", "type", "team"]
  447. full_dict_rules_value = [match_id, league_id, key, "0", 0, p_code, value, full_dict_rules[key],
  448. odds_only, sole, "hg3535", "0", ""]
  449. full_dict_rules_data = dict(zip(full_dict_rules_key, full_dict_rules_value))
  450. data_list.append(full_dict_rules_data)
  451. if half_dicts:
  452. for key, value in half_dicts.items():
  453. hash_str = p_code + key + '0' + half_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. half_dicts_key = ["match_id", "lg_id", "odds_code", "status", "sort", "p_code", "odds",
  458. "condition", "odds_only", "sole", "source", "type", "team"]
  459. half_dicts_value = [match_id, league_id, key, "0", 0, p_code, value, half_dict_rules[key],
  460. odds_only, sole, "hg3535", "0", ""]
  461. half_dicts_data = dict(zip(half_dicts_key, half_dicts_value))
  462. data_list.append(half_dicts_data)
  463. p_code = 'CB'
  464. # 球队得分全场,上半场
  465. horn_ou_dict = item['horn_ou_dict']
  466. horn_ou_dict_rule = item['horn_ou_dict_rule']
  467. horn_oe_dict = item['horn_oe_dict']
  468. horn_oe_dict_rule = item['horn_oe_dict_rule']
  469. if horn_ou_dict:
  470. for key, value in horn_ou_dict.items():
  471. hash_str = p_code + key + '0' + horn_ou_dict_rule[key] + str(value) + "hg3535" + str(match_id)
  472. sole_str = p_code + key + '0' + str(match_id) + "hg3535"
  473. odds_only = Helper.genearte_MD5(hash_str, pt)
  474. sole = Helper.genearte_MD5(sole_str, pt)
  475. horn_ou_key = ["match_id", "lg_id", "odds_code", "status", "sort", "p_code", "odds",
  476. "condition", "odds_only", "sole", "source", "type", "team"]
  477. horn_ou_value = [match_id, league_id, key, "0", 0, p_code, value, horn_ou_dict_rule[key],
  478. odds_only, sole, "hg3535", "0", ""]
  479. horn_ou_data = dict(zip(horn_ou_key, horn_ou_value))
  480. data_list.append(horn_ou_data)
  481. if horn_oe_dict:
  482. for key, value in horn_oe_dict.items():
  483. hash_str = p_code + key + '0' + horn_oe_dict_rule[key] + str(value) + "hg3535" + str(match_id)
  484. sole_str = p_code + key + '0' + str(match_id) + "hg3535"
  485. odds_only = Helper.genearte_MD5(hash_str, pt)
  486. sole = Helper.genearte_MD5(sole_str, pt)
  487. horn_oe_key = ["match_id", "lg_id", "odds_code", "status", "sort", "p_code", "odds",
  488. "condition", "odds_only", "sole", "source", "type", "team"]
  489. horn_oe_value = [match_id, league_id, key, "0", 0, p_code, value, horn_oe_dict_rule[key],
  490. odds_only, sole, "hg3535", "0", ""]
  491. horn_oe_data = dict(zip(horn_oe_key, horn_oe_value))
  492. data_list.append(horn_oe_data)
  493. odds_key = ["game_code", "title", "match_id", "lg_id", "data", "source", "odds_only", "tag", "uuid",
  494. "is_stringscene", "utime", "pt"]
  495. odds_value = ["zq", "odds", match_id, league_id, data_list, "hg3535", odds_onlys, number, uuid,
  496. 0, utime, pt]
  497. odds_dict = dict(zip(odds_key, odds_value))
  498. if data_list:
  499. res = Helper.async_post(ODDS_URL, odds_dict)
  500. if res:
  501. if res.get('status') == 1:
  502. logger.info('足球滚球详细赔率提交成功, {}'.format(res))
  503. logger.info(odds_dict)
  504. else:
  505. logger.warning('足球滚球详细赔率提交失败, {}'.format(res))
  506. logger.warning(odds_dict)
  507. else:
  508. logger.warning('足球滚球详细赔率接口异常,提交失败, {}'.format(res))
  509. logger.warning(odds_dict)
  510. else:
  511. logger.info('足球滚球详细赔率列表为空')
  512. data_list = []
  513. zq_rball = {"home_team": team_home, "guest_team": team_guest,
  514. "lg_id": league_id, "home_rate": 0,
  515. "guest_rate": 0, "home_score": score_home,
  516. "guest_score": score_guest, "all_goal": all_goal, "status": 1,
  517. "first_score": "", "last_score": "", "match_score": match_score, "uuid": uuid,
  518. "match_winer": "", "match_time": time_game,
  519. "match_process": half_way, "tag": number,
  520. "match_id": match_id, "p_code": ""}
  521. data_list.append(zq_rball)
  522. r_data_dict = {
  523. "game_code": "zq",
  524. "title": "match_result_r",
  525. "source": "hg3535",
  526. "data": data_list
  527. }
  528. if data_list:
  529. try:
  530. res = Helper.async_post(MATCH_RESULT, r_data_dict)
  531. if res:
  532. if res.get('status') == 1:
  533. logger.info('足球滚球结果记录提交成功, {}'.format(res))
  534. self.db.zq_match_result35.insert(zq_rball)
  535. logger.info(r_data_dict)
  536. else:
  537. logger.warning('足球滚球结果记录提交失败, {}'.format(res))
  538. logger.warning(r_data_dict)
  539. else:
  540. logger.warning('足球滚球结果记录接口异常,提交失败, {}'.format(res))
  541. logger.warning(r_data_dict)
  542. except Exception as e:
  543. logger.warning('滚球数据接口异常,提交失败, {}'.format(e))
  544. # 角球分割处理--------------------------------------------------------------------------------------------------
  545. if horn_team:
  546. team_home = horn_team['horn_home']
  547. team_guest = horn_team['horn_guest']
  548. horn_scoreh = horn_team['horn_scoreh']
  549. horn_scoreg = horn_team['horn_scoreg']
  550. all_goal = int(horn_scoreh) + int(horn_scoreg)
  551. match_id = horn_team['horn_id']
  552. # half_way = item['half_way']
  553. match_score = "{}:{}".format(horn_scoreh, horn_scoreg)
  554. if self.db.zq_competition35.find({"match_id": match_id, 'is_rollball': 1}).count() < 1:
  555. match_list = []
  556. match_dict = {"game_code": "zq", "title": "match", "source": "hg3535"}
  557. match_kay = ["home_team", "guest_team", "lg_id", "status", "match_id", "match_date", "match_time",
  558. "tag", "source", "is_rollball", "is_morningplate", "is_stringscene", "us_time", "uuid",
  559. "half_match_id", "is_today", "is_horn"]
  560. match_value = [team_home, team_guest, league_id, 1, match_id, match_date, match_time, number,
  561. "hg3535", 1, 0, 0, utime, uuid, 0, 0, 1]
  562. match_data = dict(zip(match_kay, match_value))
  563. match_list.append(match_data)
  564. match_dict['data'] = match_list
  565. res = Helper.async_post(MATCH_URL, match_dict)
  566. if res:
  567. if res.get('status') == 1:
  568. self.db.zq_competition35.insert(match_data)
  569. logger.info('足球滚球角球, 赛事提交成功, {}'.format(res))
  570. logger.info(match_data)
  571. else:
  572. logger.warning('足球滚球赛事, 角球提交失败, {}'.format(res))
  573. logger.warning(match_data)
  574. else:
  575. logger.warning('足球滚球赛事接口异常, 角球赛事提交失败, {}'.format(res))
  576. logger.warning(match_data)
  577. else:
  578. logger.info('足球滚球赛事已存在, 不提交')
  579. data_list = []
  580. odds_onlys = []
  581. p_code = 'CB'
  582. horn_ou_dict = item['horn_ou_dict']
  583. horn_ou_dict_rule = item['horn_ou_dict_rule']
  584. horn_oe_dict = item['horn_oe_dict']
  585. horn_oe_dict_rule = item['horn_oe_dict_rule']
  586. if horn_ou_dict:
  587. for key, value in horn_ou_dict.items():
  588. hash_str = p_code + key + '0' + horn_ou_dict_rule[key] + str(value) + "hg3535" + str(match_id)
  589. sole_str = p_code + key + '0' + str(match_id) + "hg3535"
  590. odds_only = Helper.genearte_MD5(hash_str, pt)
  591. sole = Helper.genearte_MD5(sole_str, pt)
  592. horn_ou_key = ["match_id", "lg_id", "odds_code", "status", "sort", "p_code", "odds",
  593. "condition", "odds_only", "sole", "source", "type", "team"]
  594. horn_ou_value = [match_id, league_id, key, "0", 0, p_code, value, horn_ou_dict_rule[key],
  595. odds_only, sole, "hg3535", "0", ""]
  596. horn_ou_data = dict(zip(horn_ou_key, horn_ou_value))
  597. data_list.append(horn_ou_data)
  598. if horn_oe_dict:
  599. for key, value in horn_oe_dict.items():
  600. hash_str = p_code + key + '0' + horn_oe_dict_rule[key] + str(value) + "hg3535" + str(match_id)
  601. sole_str = p_code + key + '0' + str(match_id) + "hg3535"
  602. odds_only = Helper.genearte_MD5(hash_str, pt)
  603. sole = Helper.genearte_MD5(sole_str, pt)
  604. horn_oe_key = ["match_id", "lg_id", "odds_code", "status", "sort", "p_code", "odds",
  605. "condition", "odds_only", "sole", "source", "type", "team"]
  606. horn_oe_value = [match_id, league_id, key, "0", 0, p_code, value, horn_oe_dict_rule[key],
  607. odds_only, sole, "hg3535", "0", ""]
  608. horn_oe_data = dict(zip(horn_oe_key, horn_oe_value))
  609. data_list.append(horn_oe_data)
  610. odds_key = ["game_code", "title", "match_id", "lg_id", "data", "source", "odds_only", "tag", "uuid",
  611. "is_stringscene", "utime", "pt"]
  612. odds_value = ["zq", "odds", match_id, league_id, data_list, "hg3535", odds_onlys, number, uuid,
  613. 0, utime, pt]
  614. odds_dict = dict(zip(odds_key, odds_value))
  615. if data_list:
  616. res = Helper.async_post(ODDS_URL, odds_dict)
  617. if res:
  618. if res.get('status') == 1:
  619. logger.info('足球滚球, 角球详细赔率提交成功, {}'.format(res))
  620. logger.info(odds_dict)
  621. else:
  622. logger.warning('足球滚球, 角球详细赔率提交失败, {}'.format(res))
  623. logger.warning(odds_dict)
  624. else:
  625. logger.warning('足球滚球, 角球详细赔率接口异常,提交失败, {}'.format(res))
  626. logger.warning(odds_dict)
  627. else:
  628. logger.info('足球滚球, 角球详细赔率列表为空')
  629. data_list = []
  630. zq_rball = {"home_team": team_home, "guest_team": team_guest,
  631. "lg_id": league_id, "home_rate": 0,
  632. "guest_rate": 0, "home_score": horn_scoreh,
  633. "guest_score": horn_scoreg, "all_goal": all_goal, "status": 1,
  634. "first_score": "", "last_score": "", "match_score": match_score, "uuid": uuid,
  635. "match_winer": "", "match_time": time_game,
  636. "match_process": half_way, "tag": number,
  637. "match_id": match_id, "p_code": ""}
  638. data_list.append(zq_rball)
  639. r_data_dict = {
  640. "game_code": "zq",
  641. "title": "match_result_r",
  642. "source": "hg3535",
  643. "data": data_list
  644. }
  645. if data_list:
  646. try:
  647. res = Helper.async_post(MATCH_RESULT, r_data_dict)
  648. if res:
  649. if res.get('status') == 1:
  650. logger.info('足球滚球, 角球结果记录提交成功, {}'.format(res))
  651. self.db.zq_match_result35.insert(zq_rball)
  652. logger.info(r_data_dict)
  653. else:
  654. logger.warning('足球滚球, 角球结果记录提交失败, {}'.format(res))
  655. logger.warning(r_data_dict)
  656. else:
  657. logger.warning('足球滚球, 角球结果记录接口异常,提交失败, {}'.format(res))
  658. logger.warning(r_data_dict)
  659. except Exception as e:
  660. logger.warning('滚球数据接口异常, 角球结果提交失败, {}'.format(e))
  661. reactor.callFromThread(out.callback, item)