zuqiu.py 38 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652
  1. import datetime
  2. import time
  3. import logging
  4. import pymongo
  5. from twisted.internet import defer, reactor
  6. from ..utils.helper import Helper
  7. from .ball_func import new_time
  8. from ..settings import M_HOST, M_USER, M_PASSWORD, M_POST, M_DB, LEAGUE_URL, ODDS_URL, MATCH_URL
  9. class Zuqiupipeline(object):
  10. def open_spider(self, spider):
  11. # self.connection = AsyncIOMotorClient("mongodb://{}:{}@{}:{}/database?authSource={}".format('kaiyou', 'kaiyou', '192.168.2.200', 27017, 'kaiyou'))
  12. # session = aiohttp.ClientSession()
  13. self.mongo = pymongo.MongoClient(host=M_HOST, username=M_USER, password=M_PASSWORD, port=M_POST, authSource='kaiyou')
  14. self.db = self.mongo[M_DB]
  15. @defer.inlineCallbacks
  16. def process_item(self, item, spider):
  17. out = defer.Deferred()
  18. reactor.callInThread(self._do_calculation, item, out)
  19. yield out
  20. # defer.returnValue(item)
  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])
  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(datetime.datetime.now().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 = str(item['pt'])
  56. match_date, match_time, time3 = new_time(us_time)
  57. # 联赛接口写入
  58. last_time = '{}-12-31 23:59:59'.format(datetime.datetime.now().year)
  59. league_list = []
  60. uuid = Helper.genearte_uuid(league_name + 'hg3535')
  61. if self.db.zq_league35.find({'lg_id': league_id}).count() < 1:
  62. league_dict = {"game_code": "zq", "title": "league", "source": "hg3535"}
  63. league_key = ["name_chinese", "kind", "match_mode", "if_stop", "last_time", "lg_id", "source", "uuid"]
  64. league_value = [league_name, "1", "1", "0", last_time, league_id, "hg3535", uuid]
  65. league_data = dict(zip(league_key, league_value))
  66. league_list.append(league_data)
  67. league_dict['data'] = league_list
  68. res = Helper.async_post(LEAGUE_URL, league_dict)
  69. if res:
  70. if res.get('status') == 1:
  71. self.db.zq_league35.insert(league_data)
  72. else:
  73. logging.warning('足球详细赔率接口异常, {}'.format(res))
  74. else:
  75. logging.info('{},联赛已存在, 不提交'.format(league_name))
  76. pt_dict = {'1': 'is_today', '2': 'is_morningplate', '3': 'is_stringscene', '4': 'is_rollball'}
  77. pt_status = pt_dict[pt]
  78. if pt == '3':
  79. is_rollball = 0
  80. is_today = 0
  81. is_morningplate = 0
  82. is_stringscene = 1
  83. elif pt == '2':
  84. is_rollball = 0
  85. is_today = 0
  86. is_morningplate = 1
  87. is_stringscene = 0
  88. else:
  89. is_today = 1
  90. is_rollball = 0
  91. is_morningplate = 0
  92. is_stringscene = 0
  93. match_list = []
  94. if self.db.zq_competition35.find({'match_id': match_id, pt_status: 1}).count() < 1:
  95. match_dict = {"game_code": "zq", "title": "match", "source": "hg3535"}
  96. match_kay = ["home_team", "guest_team", "lg_id", "status", "match_id", "match_date", "match_time",
  97. "tag", "source", "is_rollball", "is_morningplate", "is_stringscene", "us_time", "uuid",
  98. "half_match_id", "is_today", "is_horn"]
  99. match_value = [team_home, team_guest, league_id, 0, match_id, match_date, match_time, tag_number,
  100. "hg3535", is_rollball, is_morningplate, is_stringscene, us_time, uuid, 0, is_today, 0]
  101. match_data = dict(zip(match_kay, match_value))
  102. match_list.append(match_data)
  103. match_dict['data'] = match_list
  104. res = Helper.async_post(MATCH_URL, match_dict)
  105. if res:
  106. if res.get('status') == 1:
  107. self.db.zq_competition35.insert(match_data)
  108. else:
  109. logger.warning('足球赛事表提交失败, {}'.format(res))
  110. logger.warning(match_dict)
  111. else:
  112. logger.warning('足球赛事接口异常提交失败, {}'.format(res))
  113. logger.warning(match_dict)
  114. else:
  115. logger.info('足球赛事已存在,不提交')
  116. p_code = "GS"
  117. half_size_guest = item["half_size_guest"]
  118. half_size_guest_rule = item["half_size_guest_rule"]
  119. half_size_home = item["half_size_home"]
  120. half_size_home_rule = item["half_size_home_rule"]
  121. data_list = []
  122. odds_onlys = []
  123. # half_size_guest
  124. for index, value in enumerate(half_size_guest):
  125. hash_str = p_code + "gss_h" + str(index) + str(half_size_guest_rule[index]) + str(
  126. value) + "hg3535" + str(match_id)
  127. sole_str = p_code + "gss_h" + str(index) + str(match_id) + "hg3535"
  128. odds_only = Helper.genearte_MD5(hash_str, pt)
  129. sole = Helper.genearte_MD5(sole_str, pt)
  130. half_size_guest_key = ["match_id", "lg_id", "odds_code", "status", "sort", "p_code", "odds", "condition",
  131. "odds_only", "sole", "source", "type", "team"]
  132. condition = half_size_guest_rule[index]
  133. half_size_guest_value = [match_id, league_id, "gss_h", "0", index, p_code, value, condition,
  134. odds_only, sole, "hg3535", "0", ""]
  135. half_size_guest_data = dict(zip(half_size_guest_key, half_size_guest_value))
  136. data_list.append(half_size_guest_data)
  137. # half_size_home
  138. for index, value in enumerate(half_size_home):
  139. hash_str = p_code + "gsb_h" + str(index) + str(half_size_home_rule[index]) + str(
  140. value) + "hg3535" + str(match_id)
  141. sole_str = p_code + "gsb_h" + str(index) + str(match_id) + "hg3535"
  142. odds_only = Helper.genearte_MD5(hash_str, pt)
  143. sole = Helper.genearte_MD5(sole_str, pt)
  144. half_size_home_key = ["match_id", "lg_id", "odds_code", "status", "sort", "p_code", "odds", "condition",
  145. "odds_only", "sole", "source", "type", "team"]
  146. condition = half_size_home_rule[index]
  147. half_size_home_value = [match_id, league_id, "gsb_h", "0", index, p_code, value, condition,
  148. odds_only, sole, "hg3535", "0", ""]
  149. half_size_home_data = dict(zip(half_size_home_key, half_size_home_value))
  150. data_list.append(half_size_home_data)
  151. # 全场场大小
  152. size_guest = item["size_guest"]
  153. size_guest_rule = item["size_guest_rule"]
  154. size_home = item["size_home"]
  155. size_home_rule = item["size_home_rule"]
  156. # size_home
  157. for index, value in enumerate(size_home):
  158. hash_str = p_code + "gsb" + str(index) + str(size_home_rule[index]) + str(value) + "hg3535" + str(
  159. match_id)
  160. sole_str = p_code + "gsb" + str(index) + str(match_id) + "hg3535"
  161. odds_only = Helper.genearte_MD5(hash_str, pt)
  162. sole = Helper.genearte_MD5(sole_str, pt)
  163. size_home_key = ["match_id", "lg_id", "odds_code", "status", "sort", "p_code", "odds", "condition",
  164. "odds_only", "sole", "source", "type", "team"]
  165. condition = size_home_rule[index]
  166. size_home_value = [match_id, league_id, "gsb", "0", index, p_code, value, condition, odds_only,
  167. sole, "hg3535", "0", ""]
  168. size_home_data = dict(zip(size_home_key, size_home_value))
  169. data_list.append(size_home_data)
  170. # size_guest
  171. for index, value in enumerate(size_guest):
  172. hash_str = p_code + "gss" + str(index) + str(size_guest_rule[index]) + str(value) + "hg3535" + str(
  173. match_id)
  174. sole_str = p_code + "gss" + str(index) + str(match_id) + "hg3535"
  175. odds_only = Helper.genearte_MD5(hash_str, pt)
  176. sole = Helper.genearte_MD5(sole_str, pt)
  177. size_guest_key = ["match_id", "lg_id", "odds_code", "status", "sort", "p_code", "odds", "condition",
  178. "odds_only", "sole", "source", "type", "team"]
  179. condition = size_guest_rule[index]
  180. size_guest_value = [match_id, league_id, "gss", "0", index, p_code, value, condition, odds_only,
  181. sole, "hg3535", "0", ""]
  182. size_home_data = dict(zip(size_guest_key, size_guest_value))
  183. data_list.append(size_home_data)
  184. p_code = 'CO'
  185. half_concede_home_rule = item["half_concede_home_rule"]
  186. half_concede_home = item["half_concede_home"]
  187. half_concede_guest_rule = item["half_concede_guest_rule"]
  188. half_concede_guest = item["half_concede_guest"]
  189. # half_concede_home
  190. if half_concede_guest:
  191. for index, value in enumerate(half_concede_guest):
  192. hash_str = p_code + "cog_h" + str(index) + str(half_concede_guest_rule[index]) + str(
  193. value) + "hg3535" + str(match_id)
  194. sole_str = p_code + "cog_h" + str(index) + str(match_id) + "hg3535"
  195. odds_only = Helper.genearte_MD5(hash_str, pt)
  196. sole = Helper.genearte_MD5(sole_str, pt)
  197. half_concede_guest_key = ["match_id", "lg_id", "odds_code", "status", "sort", "p_code", "odds", "condition",
  198. "odds_only", "sole", "source", "type", "team"]
  199. condition = half_concede_guest_rule[index]
  200. half_concede_guest_value = [match_id, league_id, "cog_h", "0", index, p_code, value, condition,
  201. odds_only, sole, "hg3535", "0", ""]
  202. half_concede_guest_data = dict(zip(half_concede_guest_key, half_concede_guest_value))
  203. data_list.append(half_concede_guest_data)
  204. # half_concede_home
  205. if half_concede_home:
  206. for index, value in enumerate(half_concede_home):
  207. hash_str = p_code + "coh_h" + str(index) + str(half_concede_home_rule[index]) + str(
  208. value) + "hg3535" + str(match_id)
  209. sole_str = p_code + "coh_h" + str(index) + str(match_id) + "hg3535"
  210. odds_only = Helper.genearte_MD5(hash_str, pt)
  211. sole = Helper.genearte_MD5(sole_str, pt)
  212. half_concede_home_key = ["match_id", "lg_id", "odds_code", "status", "sort", "p_code", "odds", "condition",
  213. "odds_only", "sole", "source", "type", "team"]
  214. condition = half_concede_home_rule[index]
  215. half_concede_home_value = [match_id, league_id, "coh_h", "0", index, p_code, value, condition,
  216. odds_only, sole, "hg3535", "0", ""]
  217. half_concede_home_data = dict(zip(half_concede_home_key, half_concede_home_value))
  218. data_list.append(half_concede_home_data)
  219. concede_guest = item["concede_guest"]
  220. concede_guest_rule = item["concede_guest_rule"]
  221. concede_home = item["concede_home"]
  222. concede_home_rule = item["concede_home_rule"]
  223. # concede_guest
  224. if concede_guest:
  225. for index, value in enumerate(concede_guest):
  226. hash_str = p_code + "cog" + str(index) + str(concede_guest_rule[index]) + str(
  227. value) + "hg3535" + str(match_id)
  228. sole_str = p_code + "cog" + str(index) + str(match_id) + "hg3535"
  229. odds_only = Helper.genearte_MD5(hash_str, pt)
  230. sole = Helper.genearte_MD5(sole_str, pt)
  231. concede_guest_key = ["match_id", "lg_id", "odds_code", "status", "sort", "p_code", "odds", "condition",
  232. "odds_only", "sole", "source", "type", "team"]
  233. condition = concede_guest_rule[index]
  234. concede_guest_value = [match_id, league_id, "cog", "0", index, p_code, value, condition,
  235. odds_only, sole, "hg3535", "0", ""]
  236. concede_guest_data = dict(zip(concede_guest_key, concede_guest_value))
  237. data_list.append(concede_guest_data)
  238. # concede_home
  239. if concede_home:
  240. for index, value in enumerate(concede_home):
  241. hash_str = p_code + "coh" + str(index) + str(concede_home_rule[index]) + str(
  242. value) + "hg3535" + str(match_id)
  243. sole_str = p_code + "coh" + str(index) + str(match_id) + "hg3535"
  244. odds_only = Helper.genearte_MD5(hash_str, pt)
  245. sole = Helper.genearte_MD5(sole_str, pt)
  246. concede_home_key = ["match_id", "lg_id", "odds_code", "status", "sort", "p_code", "odds", "condition",
  247. "odds_only", "sole", "source", "type", "team"]
  248. condition = concede_home_rule[index]
  249. concede_home_value = [match_id, league_id, "coh", "0", index, p_code, value, condition, odds_only,
  250. sole, "hg3535", "0", ""]
  251. concede_guest_data = dict(zip(concede_home_key, concede_home_value))
  252. data_list.append(concede_guest_data)
  253. # 独赢----------------------------------------------------------------------------------------------------------
  254. p_code = 'C'
  255. half_capot_home = item["half_capot_home"]
  256. half_capot_guest = item["half_capot_guest"]
  257. half_capot_dogfall = item["half_capot_dogfall"]
  258. capot_home = item["capot_home"]
  259. capot_guest = item["capot_guest"]
  260. capot_dogfall = item["capot_dogfall"]
  261. # half_capot_home
  262. hash_str = p_code + "ch_h" + '0' + '1' + str(half_capot_home) + "hg3535" + str(match_id)
  263. sole_str = p_code + "ch_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_home_key = ["match_id", "lg_id", "odds_code", "status", "sort", "p_code", "odds", "condition",
  267. "odds_only", "sole", "source", "type", "team"]
  268. half_capot_home_value = [match_id, league_id, "ch_h", "0", 0, p_code, half_capot_home, '1',
  269. odds_only, sole, "hg3535", "0", ""]
  270. half_capot_homet_data = dict(zip(half_capot_home_key, half_capot_home_value))
  271. data_list.append(half_capot_homet_data)
  272. # half_capot_guest
  273. hash_str = p_code + "cg_h" + '0' + '2' + str(half_capot_guest) + "hg3535" + str(match_id)
  274. sole_str = p_code + "cg_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_guest_key = ["match_id", "lg_id", "odds_code", "status", "sort", "p_code", "odds", "condition",
  278. "odds_only", "sole", "source", "type", "team"]
  279. half_capot_guest_value = [match_id, league_id, "cg_h", "0", 0, p_code, half_capot_guest, '2',
  280. odds_only, sole, "hg3535", "0", ""]
  281. half_capot_guest_data = dict(zip(half_capot_guest_key, half_capot_guest_value))
  282. data_list.append(half_capot_guest_data)
  283. # half_capot_dogfall
  284. hash_str = p_code + "cd_h" + '0' + 'X' + str(half_capot_dogfall) + "hg3535" + str(match_id)
  285. sole_str = p_code + "cd_h" + '0' + str(match_id) + "hg3535"
  286. odds_only = Helper.genearte_MD5(hash_str, pt)
  287. sole = Helper.genearte_MD5(sole_str, pt)
  288. half_capot_dogfall_key = ["match_id", "lg_id", "odds_code", "status", "sort", "p_code", "odds", "condition",
  289. "odds_only", "sole", "source", "type", "team"]
  290. half_capot_dogfall_value = [match_id, league_id, "cd_h", "0", 0, p_code, half_capot_dogfall, 'X',
  291. odds_only, sole, "hg3535", "0", ""]
  292. half_capot_dogfall_data = dict(zip(half_capot_dogfall_key, half_capot_dogfall_value))
  293. data_list.append(half_capot_dogfall_data)
  294. # capot_dogfall
  295. hash_str = p_code + "cd" + '0' + 'X' + str(capot_dogfall) + "hg3535" + str(match_id)
  296. sole_str = p_code + "cd" + '0' + str(match_id) + "hg3535"
  297. odds_only = Helper.genearte_MD5(hash_str, pt)
  298. sole = Helper.genearte_MD5(sole_str, pt)
  299. capot_dogfall_key = ["match_id", "lg_id", "odds_code", "status", "sort", "p_code", "odds", "condition",
  300. "odds_only", "sole", "source", "type", "team"]
  301. capot_dogfall_value = [match_id, league_id, "cd", "0", 0, p_code, capot_dogfall, 'X', odds_only,
  302. sole, "hg3535", "0", ""]
  303. capot_dogfall_data = dict(zip(capot_dogfall_key, capot_dogfall_value))
  304. data_list.append(capot_dogfall_data)
  305. # capot_home
  306. hash_str = p_code + "ch" + '0' + '1' + str(capot_home) + "hg3535" + str(match_id)
  307. sole_str = p_code + "ch" + '0' + str(match_id) + "hg3535"
  308. odds_only = Helper.genearte_MD5(hash_str, pt)
  309. sole = Helper.genearte_MD5(sole_str, pt)
  310. capot_home_key = ["match_id", "lg_id", "odds_code", "status", "sort", "p_code", "odds", "condition",
  311. "odds_only", "sole", "source", "type", "team"]
  312. capot_home_value = [match_id, league_id, "ch", "0", 0, p_code, capot_home, '1',
  313. odds_only, sole, "hg3535", "0", ""]
  314. capot_homet_data = dict(zip(capot_home_key, capot_home_value))
  315. data_list.append(capot_homet_data)
  316. # capot_guest
  317. hash_str = p_code + "cg" + '0' + '2' + str(capot_guest) + "hg3535" + str(match_id)
  318. sole_str = p_code + "cg" + '0' + str(match_id) + "hg3535"
  319. odds_only = Helper.genearte_MD5(hash_str, pt)
  320. sole = Helper.genearte_MD5(sole_str, pt)
  321. capot_guest_key = ["match_id", "lg_id", "odds_code", "status", "sort", "p_code", "odds", "condition",
  322. "odds_only", "sole", "source", "type", "team"]
  323. capot_guest_value = [match_id, league_id, "cg", "0", 0, p_code, capot_guest, '2',
  324. odds_only, sole, "hg3535", "0", ""]
  325. capot_guest_data = dict(zip(capot_guest_key, capot_guest_value))
  326. data_list.append(capot_guest_data)
  327. # 入球数单双-----------------------------------------------------------------------------------------------------
  328. # p_code, p_id = get_pcode(corner_ball, 'two_sides')
  329. p_code = 'TS'
  330. odd_even_odd = item["odd_even_odd"]
  331. odd_even_even = item["odd_even_even"]
  332. half_odd_even_odd = item["half_odd_even_odd"]
  333. half_odd_even_even = item["half_odd_even_even"]
  334. # odd_even_odd
  335. hash_str = p_code + "tss" + '0' + '单' + str(odd_even_odd) + "hg3535" + str(match_id)
  336. sole_str = p_code + "tss" + '0' + str(match_id) + "hg3535"
  337. odds_only = Helper.genearte_MD5(hash_str, pt)
  338. sole = Helper.genearte_MD5(sole_str, pt)
  339. single_key = ["match_id", "lg_id", "odds_code", "status", "sort", "p_code", "odds", "condition",
  340. "odds_only", "sole", "source", "type", "team"]
  341. single_value = [match_id, league_id, "tss", "0", 0, p_code, odd_even_odd, '单',
  342. odds_only, sole, "hg3535", "0", ""]
  343. single_data = dict(zip(single_key, single_value))
  344. data_list.append(single_data)
  345. # odd_even_even
  346. hash_str = p_code + "tsd" + '0' + '双' + str(odd_even_even) + "hg3535" + str(match_id)
  347. sole_str = p_code + "tsd" + '0' + str(match_id) + "hg3535"
  348. odds_only = Helper.genearte_MD5(hash_str, pt)
  349. sole = Helper.genearte_MD5(sole_str, pt)
  350. double_key = ["match_id", "lg_id", "odds_code", "status", "sort", "p_code", "odds", "condition",
  351. "odds_only", "sole", "source", "type", "team"]
  352. double_value = [match_id, league_id, "tsd", "0", 0, p_code, odd_even_even, '双',
  353. odds_only, sole, "hg3535", "0", ""]
  354. double_data = dict(zip(double_key, double_value))
  355. data_list.append(double_data)
  356. # half_odd_even_even
  357. hash_str = p_code + "tsd_h" + '0' + '双' + str(half_odd_even_even) + "hg3535" + str(match_id)
  358. sole_str = p_code + "tsd_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_double_key = ["match_id", "lg_id", "odds_code", "status", "sort", "p_code", "odds", "condition",
  362. "odds_only", "sole", "source", "type", "team"]
  363. half_double_value = [match_id, league_id, "tsd_h", "0", 0, p_code, half_odd_even_even, '双',
  364. odds_only, sole, "hg3535", "0", ""]
  365. half_double_data = dict(zip(half_double_key, half_double_value))
  366. data_list.append(half_double_data)
  367. # half_odd_even_odd
  368. hash_str = p_code + "tss_h" + '0' + '单' + str(half_odd_even_odd) + "hg3535" + str(match_id)
  369. sole_str = p_code + "tss_h" + '0' + str(match_id) + "hg3535"
  370. odds_only = Helper.genearte_MD5(hash_str, pt)
  371. sole = Helper.genearte_MD5(sole_str, pt)
  372. half_single_key = ["match_id", "lg_id", "odds_code", "status", "sort", "p_code", "odds", "condition",
  373. "odds_only", "sole", "source", "type", "team"]
  374. half_single_value = [match_id, league_id, "tss_h", "0", 0, p_code, half_odd_even_odd, '单', odds_only,
  375. sole, "hg3535", "0", ""]
  376. half_single_data = dict(zip(half_single_key, half_single_value))
  377. data_list.append(half_single_data)
  378. # 总入球数 ------------------------------------------------------------------------------------------------------
  379. p_code = 'TG'
  380. total_goals = item['total_goal']
  381. total_dict = {'tg0': '0-1', 'tg1': '2-3', 'tg2': '4-6','tg3': '7或以上', 'tg0_h': '0', "tg1_h": '1',
  382. "tg2_h": '2', "tg3_h": '3或以上'}
  383. # 全场入球数 单双
  384. # 上半场入球数 单双
  385. for key, value in total_goals.items():
  386. hash_str = p_code + key + '0' + total_dict[key] + str(value) + "hg3535" + str(match_id)
  387. sole_str = p_code + key + '0' + str(match_id) + "hg3535"
  388. odds_only = Helper.genearte_MD5(hash_str, pt)
  389. sole = Helper.genearte_MD5(sole_str, pt)
  390. total_goals_key = ["match_id", "lg_id", "odds_code", "status", "sort", "p_code", "odds", "condition",
  391. "odds_only", "sole", "source", "type", "team"]
  392. total_goals_value = [match_id, league_id, key, "0", 0, p_code, value, total_dict[key], odds_only,
  393. sole, "hg3535", "0", ""]
  394. total_goals_data = dict(zip(total_goals_key, total_goals_value))
  395. data_list.append(total_goals_data)
  396. # 全场半场 ------------------------------------------------------------------------------------------------------
  397. half_fulls = item['half_full']
  398. p_code = 'HF'
  399. full_dict = {"hfhh": "主主", "hfhd": "主和", "hfhg": "主客", "hfdh": "和主",
  400. "hfdd": "和和", "hfdg": "和客", "hfgh": "客主", "hfgd": "客和", "hfgg": "客客"}
  401. if half_fulls:
  402. for key, value in half_fulls.items():
  403. hash_str = p_code + key + '0' + full_dict[key] + str(value) + "hg3535" + str(match_id)
  404. sole_str = p_code + key + '0' + str(match_id) + "hg3535"
  405. odds_only = Helper.genearte_MD5(hash_str, pt)
  406. sole = Helper.genearte_MD5(sole_str, pt)
  407. half_fulls_key = ["match_id", "lg_id", "odds_code", "status", "sort", "p_code", "odds", "condition",
  408. "odds_only", "sole", "source", "type", "team"]
  409. half_fulls_value = [match_id, league_id, key, "0", 0, p_code, value, full_dict[key], odds_only,
  410. sole, "hg3535", "0", ""]
  411. half_fulls_data = dict(zip(half_fulls_key, half_fulls_value))
  412. data_list.append(half_fulls_data)
  413. # 波胆-----------------------------------------------------------------------------------------------------------
  414. bodan_datas = item['bodan_data']
  415. p_code = 'B'
  416. bodan_dict = {"b10": "1-0", "b20": "2-0", "b21": "2-1", "b30": "3-0", "b31": "3-1", "b32": "3-2",
  417. "b40": "4-0", "b41": "4-1", "b42": "4-2", "b43": "4-3", "b01": "0-1", "b02": "0-2",
  418. "b12": "1-2", "b03": "0-3", "b13": "1-3", "b23": "2-3", "b04": "0-4", "b14": "1-4",
  419. "b24": "2-4", "b34": "3-4", "b00": "0-0", "b11": "1-1", "b22": "2-2", "b33": "3-3",
  420. "b44": "4-4", "bo": "其他", "b10_h": "1-0", "b20_h": "2-0", "b21_h": "2-1", "b30_h": "3-0",
  421. "b31_h": "3-1", "b32_h": "3-2", "b01_h": "0-1", "b02_h": "0-2", "b12_h": "1-2", "b03_h": "0-3",
  422. "b13_h": "1-3", "b23_h": "2-3", "b00_h": "0-0", "b11_h": "1-1", "b22_h": "2-2", "b33_h": "3-3",
  423. "bo_h": "其他"}
  424. if bodan_datas:
  425. for key, value in bodan_datas.items():
  426. hash_str = p_code + key + '0' + bodan_dict[key] + str(value) + "hg3535" + str(match_id)
  427. sole_str = p_code + key + '0' + str(match_id) + "hg3535"
  428. odds_only = Helper.genearte_MD5(hash_str, pt)
  429. sole = Helper.genearte_MD5(sole_str, pt)
  430. bodan_dict_key = ["match_id", "lg_id", "odds_code", "status", "sort", "p_code", "odds", "condition",
  431. "odds_only", "sole", "source", "type", "team"]
  432. bodan_dict_value = [match_id, league_id, key, "0", 0, p_code, value, bodan_dict[key], odds_only,
  433. sole, "hg3535", "0", ""]
  434. bodan_dict_data = dict(zip(bodan_dict_key, bodan_dict_value))
  435. data_list.append(bodan_dict_data)
  436. # 最先进球/最后进球 ----------------------------------------------------------------------------------------------
  437. first_last_balls = item['first_last_ball']
  438. # p_code, p_id = get_pcode(corner_ball, 'first_last_ball')
  439. p_code = 'FLB'
  440. first_last_dict = {"flbfh": "最先进球", "flbfg": "最先进球", "flblh": "最后进球", "flblg": "最后进球", "flbn": "没有进球"}
  441. if first_last_balls:
  442. for key, value in first_last_balls.items():
  443. hash_str = p_code + key + '0' + first_last_dict[key] + str(value) + "hg3535" + str(match_id)
  444. sole_str = p_code + key + '0' + str(match_id) + "hg3535"
  445. odds_only = Helper.genearte_MD5(hash_str, pt)
  446. sole = Helper.genearte_MD5(sole_str, pt)
  447. first_last_balls_key = ["match_id", "lg_id", "odds_code", "status", "sort", "p_code", "odds", "condition",
  448. "odds_only", "sole", "source", "type", "team"]
  449. first_last_balls_value = [match_id, league_id, key, "0", 0, p_code, value, first_last_dict[key], odds_only,
  450. sole, "hg3535", "0", ""]
  451. first_last_balls_data = dict(zip(first_last_balls_key, first_last_balls_value))
  452. data_list.append(first_last_balls_data)
  453. # 球队得分大小
  454. p_code = 'TB'
  455. # 全场
  456. full_dicts = item['full_data']
  457. # 上半场
  458. half_dicts = item['half_data']
  459. full_dict_rules = item['full_data_rule']
  460. half_dict_rules = item['half_data_rule']
  461. if full_dicts:
  462. for key, value in full_dicts.items():
  463. hash_str = p_code + key + '0' + full_dict_rules[key] + str(value) + "hg3535" + str(match_id)
  464. sole_str = p_code + key + '0' + str(match_id) + "hg3535"
  465. odds_only = Helper.genearte_MD5(hash_str, pt)
  466. sole = Helper.genearte_MD5(sole_str, pt)
  467. full_dict_rules_key = ["match_id", "lg_id", "odds_code", "status", "sort", "p_code", "odds",
  468. "condition", "odds_only", "sole", "source", "type", "team"]
  469. full_dict_rules_value = [match_id, league_id, key, "0", 0, p_code, value, full_dict_rules[key],
  470. odds_only,sole, "hg3535", "0", ""]
  471. full_dict_rules_data = dict(zip(full_dict_rules_key, full_dict_rules_value))
  472. data_list.append(full_dict_rules_data)
  473. if half_dicts:
  474. for key, value in half_dicts.items():
  475. hash_str = p_code + key + '0' + half_dict_rules[key] + str(value) + "hg3535" + str(match_id)
  476. sole_str = p_code + key + '0' + str(match_id) + "hg3535"
  477. odds_only = Helper.genearte_MD5(hash_str, pt)
  478. sole = Helper.genearte_MD5(sole_str, pt)
  479. half_dicts_key = ["match_id", "lg_id", "odds_code", "status", "sort", "p_code", "odds",
  480. "condition","odds_only", "sole", "source", "type", "team"]
  481. half_dicts_value = [match_id, league_id, key, "0", 0, p_code, value, half_dict_rules[key],
  482. odds_only, sole, "hg3535", "0", ""]
  483. half_dicts_data = dict(zip(half_dicts_key, half_dicts_value))
  484. data_list.append(half_dicts_data)
  485. p_code = 'CB'
  486. horn_ou_dict = item['horn_ou_dict']
  487. horn_ou_dict_rule = item['horn_ou_dict_rule']
  488. horn_oe_dict = item['horn_oe_dict']
  489. horn_oe_dict_rule = item['horn_oe_dict_rule']
  490. if horn_ou_dict:
  491. for key, value in horn_ou_dict.items():
  492. hash_str = p_code + key + '0' + horn_ou_dict_rule[key] + str(value) + "hg3535" + str(match_id)
  493. sole_str = p_code + key + '0' + str(match_id) + "hg3535"
  494. odds_only = Helper.genearte_MD5(hash_str, pt)
  495. sole = Helper.genearte_MD5(sole_str, pt)
  496. horn_ou_key = ["match_id", "lg_id", "odds_code", "status", "sort", "p_code", "odds",
  497. "condition", "odds_only", "sole", "source", "type", "team"]
  498. horn_ou_value = [match_id, league_id, key, "0", 0, p_code, value, horn_ou_dict_rule[key],
  499. odds_only, sole, "hg3535", "0", ""]
  500. horn_ou_data = dict(zip(horn_ou_key, horn_ou_value))
  501. data_list.append(horn_ou_data)
  502. if horn_oe_dict:
  503. for key, value in horn_oe_dict.items():
  504. hash_str = p_code + key + '0' + horn_oe_dict_rule[key] + str(value) + "hg3535" + str(match_id)
  505. sole_str = p_code + key + '0' + str(match_id) + "hg3535"
  506. odds_only = Helper.genearte_MD5(hash_str, pt)
  507. sole = Helper.genearte_MD5(sole_str, pt)
  508. horn_oe_key = ["match_id", "lg_id", "odds_code", "status", "sort", "p_code", "odds",
  509. "condition", "odds_only", "sole", "source", "type", "team"]
  510. horn_oe_value = [match_id, league_id, key, "0", 0, p_code, value, horn_oe_dict_rule[key],
  511. odds_only, sole, "hg3535", "0", ""]
  512. horn_oe_data = dict(zip(horn_oe_key, horn_oe_value))
  513. data_list.append(horn_oe_data)
  514. if pt == '3':
  515. ris_stringscene = 1
  516. else:
  517. ris_stringscene = 0
  518. odds_key = ["game_code", "title", "match_id", "lg_id", "data", "source", "odds_only", "tag", "uuid", "is_stringscene", "utime", "pt"]
  519. odds_value = ["zq", "odds", match_id, league_id, data_list, "hg3535", odds_onlys, tag_number, uuid, ris_stringscene, utime, pt]
  520. odds_dict = dict(zip(odds_key, odds_value))
  521. if data_list:
  522. res = Helper.async_post(ODDS_URL, odds_dict)
  523. if res:
  524. if res.get('status') == 1:
  525. logger.info('足球详细赔率提交成功, {}'.format(res))
  526. logger.info(odds_dict)
  527. else:
  528. logger.warning('足球相信赔率提交失败, {}'.format(res))
  529. logger.warning(odds_dict)
  530. else:
  531. logging.warning('足球详细赔率接口异常, {}'.format(res))
  532. else:
  533. logger.info('足球详细赔率列表为空')
  534. # 角球处理分割线---------------------------------------------------------------------------------------------------
  535. horn_team = item['horn_team']
  536. if horn_team:
  537. team_home = horn_team['horn_home']
  538. team_guest = horn_team['horn_guest']
  539. match_id = horn_team['horn_id']
  540. match_list = []
  541. if self.db.zq_competition35.find({'match_id': match_id, pt_status: 1}).count() < 1:
  542. match_dict = {"game_code": "zq", "title": "match", "source": "hg3535"}
  543. match_kay = ["home_team", "guest_team", "lg_id", "status", "match_id", "match_date", "match_time",
  544. "tag", "source", "is_rollball", "is_morningplate", "is_stringscene", "us_time", "uuid",
  545. "half_match_id", "is_today", 'is_horn']
  546. match_value = [team_home, team_guest, league_id, 0, match_id, match_date, match_time, tag_number,
  547. "hg3535", is_rollball, is_morningplate, is_stringscene, us_time, uuid, 0, is_today, 1]
  548. match_data = dict(zip(match_kay, match_value))
  549. match_list.append(match_data)
  550. match_dict['data'] = match_list
  551. res = Helper.async_post(MATCH_URL, match_dict)
  552. if res:
  553. if res.get('status') == 1:
  554. self.db.zq_competition35.insert(match_data)
  555. logger.info('足球角球, 赛事表提交失败, {}'.format(res))
  556. logger.info(match_dict)
  557. else:
  558. logger.warning('足球角球, 赛事表提交失败, {}'.format(res))
  559. logger.warning(match_dict)
  560. else:
  561. logger.warning('足球角球, 赛事接口异常提交失败, {}'.format(res))
  562. logger.warning(match_dict)
  563. else:
  564. logger.info('足球角球, 赛事已存在,不提交')
  565. data_list = []
  566. odds_onlys = []
  567. p_code = 'CB'
  568. horn_ou_dict = item['horn_ou_dict']
  569. horn_ou_dict_rule = item['horn_ou_dict_rule']
  570. horn_oe_dict = item['horn_oe_dict']
  571. horn_oe_dict_rule = item['horn_oe_dict_rule']
  572. if horn_ou_dict:
  573. for key, value in horn_ou_dict.items():
  574. hash_str = p_code + key + '0' + horn_ou_dict_rule[key] + str(value) + "hg3535" + str(match_id)
  575. sole_str = p_code + key + '0' + str(match_id) + "hg3535"
  576. odds_only = Helper.genearte_MD5(hash_str, pt)
  577. sole = Helper.genearte_MD5(sole_str, pt)
  578. horn_ou_key = ["match_id", "lg_id", "odds_code", "status", "sort", "p_code", "odds",
  579. "condition", "odds_only", "sole", "source", "type", "team"]
  580. horn_ou_value = [match_id, league_id, key, "0", 0, p_code, value, horn_ou_dict_rule[key],
  581. odds_only, sole, "hg3535", "0", ""]
  582. horn_ou_data = dict(zip(horn_ou_key, horn_ou_value))
  583. data_list.append(horn_ou_data)
  584. if horn_oe_dict:
  585. for key, value in horn_oe_dict.items():
  586. hash_str = p_code + key + '0' + horn_oe_dict_rule[key] + str(value) + "hg3535" + str(match_id)
  587. sole_str = p_code + key + '0' + str(match_id) + "hg3535"
  588. odds_only = Helper.genearte_MD5(hash_str, pt)
  589. sole = Helper.genearte_MD5(sole_str, pt)
  590. horn_oe_key = ["match_id", "lg_id", "odds_code", "status", "sort", "p_code", "odds",
  591. "condition", "odds_only", "sole", "source", "type", "team"]
  592. horn_oe_value = [match_id, league_id, key, "0", 0, p_code, value, horn_oe_dict_rule[key],
  593. odds_only, sole, "hg3535", "0", ""]
  594. horn_oe_data = dict(zip(horn_oe_key, horn_oe_value))
  595. data_list.append(horn_oe_data)
  596. if pt == '3':
  597. ris_stringscene = 1
  598. else:
  599. ris_stringscene = 0
  600. odds_key = ["game_code", "title", "match_id", "lg_id", "data", "source", "odds_only", "tag", "uuid",
  601. "is_stringscene", "utime", "pt"]
  602. odds_value = ["zq", "odds", match_id, league_id, data_list, "hg3535", odds_onlys, tag_number, uuid,
  603. ris_stringscene, utime, pt]
  604. odds_dict = dict(zip(odds_key, odds_value))
  605. if data_list:
  606. res = Helper.async_post(ODDS_URL, odds_dict)
  607. if res:
  608. if res.get('status') == 1:
  609. logger.info('足球角球, 详细赔率提交成功, {}'.format(res))
  610. logger.info(odds_dict)
  611. else:
  612. logger.warning('足球角球, 详细赔率提交失败, {}'.format(res))
  613. logger.warning(odds_dict)
  614. else:
  615. logging.warning('足球角球, 详细赔率接口异常, {}'.format(res))
  616. else:
  617. logger.info('足球详细赔率列表为空')
  618. reactor.callFromThread(out.callback, item)