zuqiu.py 39 KB

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