zuqiu.py 31 KB

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