zuqiu.py 33 KB

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