zuqiu.py 31 KB

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