roll_zuqiu.py 35 KB

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