zuqiu.py 30 KB

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