zuqiu.py 38 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636
  1. import datetime
  2. import pymongo
  3. import time
  4. import logging
  5. from ball_func import fuhao
  6. from ..utils.helper import Helper
  7. from .ball_func import get_pcode, new_time
  8. from concurrent.futures import ThreadPoolExecutor
  9. from requests_futures.sessions import FuturesSession
  10. class Zuqiupipeline(object):
  11. def open_spider(self, spider):
  12. self.mongo = pymongo.MongoClient(host="192.168.2.200", username="kaiyou", password="kaiyou", port=27017)
  13. self.db = self.mongo['kaiyou']
  14. self.session = FuturesSession(executor=ThreadPoolExecutor(max_workers=10))
  15. def process_item(self, item, spider):
  16. zq_odds = []
  17. # url = 'http://192.168.2.200:9093'
  18. url = 'http://admin.5gogo.com'
  19. # zq_competitions = []
  20. logger = logging.getLogger(__name__)
  21. # 比赛日期
  22. try:
  23. data_game = item['data_game'].split("/")
  24. # print(data_game)
  25. month = str(data_game[1].strip())
  26. day = str(data_game[0])
  27. except Exception as e:
  28. logger.warning(e)
  29. data_game = item['data_game'].split(" ")
  30. months = str(data_game[1].strip())
  31. month_dict = {'Jan': '01', 'Feb': '02', 'Mar': '03', 'Apr': '04', 'May': '05', 'Jun': '06', 'Jul': '07',
  32. 'Aug': '08', 'Sep': '09', 'Oct': '10', 'Nov': '11', 'Dec': '12'}
  33. month = month_dict[months]
  34. day = str(data_game[0])
  35. # 比赛时间
  36. time_game = str(item['time_game'])
  37. # 比赛时间,时间戳
  38. # datetime.datetime.now().year
  39. us_time = str(datetime.datetime.now().year) + "-" + month + "-" + day + " " + time_game + ":00"
  40. r_ctime = str(datetime.datetime.now().year) + "-" + month + "-" + day
  41. # 现在时间,时间戳
  42. utime = time.strftime("%Y-%m-%d %H:%M:%S", time.localtime())
  43. expire_time = time.strftime("%Y-%m-%d %H:%M:%S", time.localtime(time.time() + 60))
  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 = '2019-12-31 23:59:59'
  61. league_dict = {"game_code": "zq", "title": "league", "source": "hg3535"}
  62. league_list = []
  63. uuid = Helper.genearte_MD5(league_name + 'hg3535')
  64. league_key = ["name_chinese", "kind", "match_mode", "if_stop", "last_time", "lg_id", "source", "uuid"]
  65. league_value = [league_name, "1", "1", "0", last_time, league_id, "hg3535", uuid]
  66. league_data = dict(zip(league_key, league_value))
  67. league_list.append(league_data)
  68. league_dict['data'] = league_list
  69. if self.db.hg3535_zq_league.find({'lg_id': league_id}).count() < 1:
  70. response_data = Helper.async_post(url + '/setLeague', league_dict)
  71. print(response_data)
  72. self.db.hg3535_zq_league.insert(league_list)
  73. competition = self.db.hg3535_zq_competition.find_one({"match_id": str(match_id)})
  74. match_list = []
  75. if competition:
  76. print('赛事已存在,修改赛事四状态')
  77. is_morningplate = competition['is_morningplate']
  78. is_rollball = competition['is_rollball']
  79. is_stringscene = competition['is_stringscene']
  80. is_today = competition['is_today']
  81. lmtime = competition['match_time']
  82. if pt == '3':
  83. if is_stringscene != 1 or lmtime != match_time:
  84. match_dict = {"game_code": "zq", "title": "match", "source": "hg3535"}
  85. match_kay = ["home_team", "guest_team", "lg_id", "status", "match_id", "match_date", "match_time",
  86. "tag","source", "is_rollball", "is_morningplate", "is_stringscene", "us_time", "uuid",
  87. "half_match_id", "is_today"]
  88. match_value = [team_home, team_guest, league_id, 0, match_id, match_date, match_time, tag_number,
  89. "hg3535",is_rollball, is_morningplate, 1, us_time, uuid, 0, is_today]
  90. match_data = dict(zip(match_kay, match_value))
  91. match_list.append(match_data)
  92. match_dict['data'] = match_list
  93. response_data = Helper.async_post(url + '/setMatch', match_dict)
  94. print(response_data)
  95. self.db.hg3535_zq_competition.update({'match_id': str(match_id)}, {"$set": {"is_stringscene": 1, "match_time": match_time}}, upsert=True)
  96. if pt == '2':
  97. if is_morningplate != 1 or lmtime != match_time:
  98. match_dict = {"game_code": "zq", "title": "match", "source": "hg3535"}
  99. match_kay = ["home_team", "guest_team", "lg_id", "status", "match_id", "match_date", "match_time",
  100. "tag","source", "is_rollball", "is_morningplate", "is_stringscene", "us_time", "uuid",
  101. "half_match_id", "is_today"]
  102. match_value = [team_home, team_guest, league_id, 0, match_id, match_date, match_time, tag_number,
  103. "hg3535",is_rollball, 1, is_stringscene, us_time, uuid, 0, is_today]
  104. match_data = dict(zip(match_kay, match_value))
  105. match_list.append(match_data)
  106. match_dict['data'] = match_list
  107. response_data = Helper.async_post(url + '/setMatch', match_dict)
  108. print(response_data)
  109. self.db.hg3535_zq_competition.update({'match_id': str(match_id)}, {"$set": {"is_morningplate": 1, "match_time": match_time}}, upsert=True)
  110. if pt == '1':
  111. if is_today != 1 or lmtime != match_time:
  112. match_dict = {"game_code": "zq", "title": "match", "source": "hg3535"}
  113. match_kay = ["home_team", "guest_team", "lg_id", "status", "match_id", "match_date", "match_time",
  114. "tag","source", "is_rollball", "is_morningplate", "is_stringscene", "us_time", "uuid",
  115. "half_match_id", "is_today"]
  116. match_value = [team_home, team_guest, league_id, 0, match_id, match_date, match_time, tag_number,
  117. "hg3535",is_rollball, is_morningplate, is_stringscene, us_time, uuid, 0, 1]
  118. match_data = dict(zip(match_kay, match_value))
  119. match_list.append(match_data)
  120. match_dict['data'] = match_list
  121. response_data = Helper.async_post(url + '/setMatch', match_dict)
  122. print(response_data)
  123. self.db.hg3535_zq_competition.update({'match_id': str(match_id)}, {"$set": {"is_today": 1, "match_time": match_time}}, upsert=True)
  124. else:
  125. print("赛事已存在,赛事状态时间为改变,不做修改")
  126. else:
  127. if pt == '3':
  128. is_rollball = 0
  129. is_today = 0
  130. is_morningplate = 0
  131. is_stringscene = 1
  132. elif pt == '2':
  133. is_rollball = 0
  134. is_today = 0
  135. is_morningplate = 1
  136. is_stringscene = 0
  137. else:
  138. is_today = 1
  139. is_rollball = 0
  140. is_morningplate = 0
  141. is_stringscene = 0
  142. # 赛事接口写入
  143. match_dict = {"game_code": "zq", "title": "match", "source": "hg3535"}
  144. match_kay = ["home_team", "guest_team", "lg_id", "status", "match_id", "match_date", "match_time", "tag",
  145. "source", "is_rollball", "is_morningplate", "is_stringscene", "us_time", "uuid",
  146. "half_match_id", "is_today"]
  147. match_value = [team_home, team_guest, league_id, 0, match_id, match_date, match_time, tag_number, "hg3535",
  148. is_rollball, is_morningplate, is_stringscene, us_time, uuid, 0, is_today]
  149. match_data = dict(zip(match_kay, match_value))
  150. match_list.append(match_data)
  151. match_dict['data'] = match_list
  152. response_data = Helper.async_post(url + '/setMatch', match_dict)
  153. self.db.hg3535_zq_competition.insert(match_list)
  154. print(response_data)
  155. # 赔率
  156. try:
  157. result = self.db.hg3535_zq_odds.find_one({'match_id': match_id, 'pt': pt})
  158. uuid_list = result['odds_only']
  159. except:
  160. uuid_list = []
  161. result = ''
  162. p_code, p_id = get_pcode(corner_ball, 'goal_size')
  163. # 构建唯一索引
  164. half_size_guest = item["half_size_guest"]
  165. half_size_guest_rule = item["half_size_guest_rule"]
  166. half_size_home = item["half_size_home"]
  167. half_size_home_rule = item["half_size_home_rule"]
  168. zuqiu = item['zuqiu']
  169. data_list = []
  170. odds_onlys = []
  171. # half_size_guest
  172. for index, value in enumerate(half_size_guest):
  173. hash_str = p_code + "half_size_guest" + str(index) + str(half_size_guest_rule[index]) + str(
  174. value) + "hg3535" + str(match_id)
  175. sole_str = p_code + "half_size_guest" + str(index) + str(match_id) + "hg3535"
  176. odds_only = Helper.genearte_MD5(hash_str)
  177. sole = Helper.genearte_MD5(sole_str)
  178. odds_onlys.append(odds_only)
  179. half_size_guest_key = ["match_id", "lg_id", "odds_code", "status", "sort", "p_code", "odds", "condition",
  180. "odds_only", "sole", "source", "type", "team"]
  181. condition = fuhao(half_size_guest_rule[index])
  182. half_size_guest_value = [match_id, league_id, "half_size_guest", "0", index, p_code, value, condition,
  183. odds_only, sole, "hg3535", "0", ""]
  184. half_size_guest_data = dict(zip(half_size_guest_key, half_size_guest_value))
  185. if odds_only not in uuid_list:
  186. data_list.append(half_size_guest_data)
  187. # half_size_home
  188. for index, value in enumerate(half_size_home):
  189. hash_str = p_code + "half_size_home" + str(index) + str(half_size_home_rule[index]) + str(
  190. value) + "hg3535" + str(match_id)
  191. sole_str = p_code + "half_size_home" + str(index) + str(match_id) + "hg3535"
  192. odds_only = Helper.genearte_MD5(hash_str)
  193. sole = Helper.genearte_MD5(sole_str)
  194. odds_onlys.append(odds_only)
  195. half_size_home_key = ["match_id", "lg_id", "odds_code", "status", "sort", "p_code", "odds", "condition",
  196. "odds_only", "sole", "source", "type", "team"]
  197. condition = fuhao(half_size_home_rule[index])
  198. half_size_home_value = [match_id, league_id, "half_size_guest", "0", index, p_code, value, condition,
  199. odds_only, sole, "hg3535", "0", ""]
  200. half_size_home_data = dict(zip(half_size_home_key, half_size_home_value))
  201. # if uid_num < 1:
  202. if odds_only not in uuid_list:
  203. data_list.append(half_size_home_data)
  204. # 全场场大小
  205. size_guest = item["size_guest"]
  206. size_guest_rule = item["size_guest_rule"]
  207. size_home = item["size_home"]
  208. size_home_rule = item["size_home_rule"]
  209. # size_home
  210. for index, value in enumerate(size_home):
  211. hash_str = p_code + "size_home" + str(index) + str(size_home_rule[index]) + str(value) + "hg3535" + str(
  212. match_id)
  213. sole_str = p_code + "size_home" + str(index) + str(match_id) + "hg3535"
  214. odds_only = Helper.genearte_MD5(hash_str)
  215. sole = Helper.genearte_MD5(sole_str)
  216. odds_onlys.append(odds_only)
  217. size_home_key = ["match_id", "lg_id", "odds_code", "status", "sort", "p_code", "odds", "condition",
  218. "odds_only", "sole", "source", "type", "team"]
  219. condition = fuhao(size_home_rule[index])
  220. size_home_value = [match_id, league_id, "size_home", "0", index, p_code, value, condition, odds_only,
  221. sole, "hg3535", "0", ""]
  222. size_home_data = dict(zip(size_home_key, size_home_value))
  223. if odds_only not in uuid_list:
  224. data_list.append(size_home_data)
  225. # size_guest
  226. for index, value in enumerate(size_guest):
  227. hash_str = p_code + "size_guest" + str(index) + str(size_guest_rule[index]) + str(value) + "hg3535" + str(
  228. match_id)
  229. sole_str = p_code + "size_guest" + str(index) + str(match_id) + "hg3535"
  230. odds_only = Helper.genearte_MD5(hash_str)
  231. sole = Helper.genearte_MD5(sole_str)
  232. odds_onlys.append(odds_only)
  233. size_guest_key = ["match_id", "lg_id", "odds_code", "status", "sort", "p_code", "odds", "condition",
  234. "odds_only", "sole", "source", "type", "team"]
  235. condition = fuhao(size_guest_rule[index])
  236. size_guest_value = [match_id, league_id, "size_guest", "0", index, p_code, value, condition, odds_only,
  237. sole, "hg3535", "0", ""]
  238. size_home_data = dict(zip(size_guest_key, size_guest_value))
  239. if odds_only not in uuid_list:
  240. data_list.append(size_home_data)
  241. p_code, p_id = get_pcode(corner_ball, 'concede')
  242. half_concede_home_rule = item["half_concede_home_rule"]
  243. half_concede_home = item["half_concede_home"]
  244. half_concede_guest_rule = item["half_concede_guest_rule"]
  245. half_concede_guest = item["half_concede_guest"]
  246. # half_concede_home
  247. for index, value in enumerate(half_concede_guest):
  248. hash_str = p_code + "half_concede_guest" + str(index) + str(half_concede_guest_rule[index]) + str(
  249. value) + "hg3535" + str(match_id)
  250. sole_str = p_code + "half_concede_guest" + str(index) + str(match_id) + "hg3535"
  251. odds_only = Helper.genearte_MD5(hash_str)
  252. sole = Helper.genearte_MD5(sole_str)
  253. odds_onlys.append(odds_only)
  254. half_concede_guest_key = ["match_id", "lg_id", "odds_code", "status", "sort", "p_code", "odds", "condition",
  255. "odds_only", "sole", "source", "type", "team"]
  256. condition = fuhao(half_concede_guest_rule[index])
  257. half_concede_guest_value = [match_id, league_id, "half_concede_guest", "0", index, p_code, value, condition,
  258. odds_only, sole, "hg3535", "0", ""]
  259. half_concede_guest_data = dict(zip(half_concede_guest_key, half_concede_guest_value))
  260. # if uid_num < 1:
  261. if odds_only not in uuid_list:
  262. data_list.append(half_concede_guest_data)
  263. # half_concede_home
  264. for index, value in enumerate(half_concede_home):
  265. hash_str = p_code + "half_concede_home" + str(index) + str(half_concede_home_rule[index]) + str(
  266. value) + "hg3535" + str(match_id)
  267. sole_str = p_code + "half_concede_home" + str(index) + str(match_id) + "hg3535"
  268. odds_only = Helper.genearte_MD5(hash_str)
  269. sole = Helper.genearte_MD5(sole_str)
  270. odds_onlys.append(odds_only)
  271. half_concede_home_key = ["match_id", "lg_id", "odds_code", "status", "sort", "p_code", "odds", "condition",
  272. "odds_only", "sole", "source", "type", "team"]
  273. condition = fuhao(half_concede_home_rule[index])
  274. half_concede_home_value = [match_id, league_id, "half_concede_home", "0", index, p_code, value, condition,
  275. odds_only, sole, "hg3535", "0", ""]
  276. half_concede_home_data = dict(zip(half_concede_home_key, half_concede_home_value))
  277. if odds_only not in uuid_list:
  278. data_list.append(half_concede_home_data)
  279. concede_guest = item["concede_guest"]
  280. concede_guest_rule = item["concede_guest_rule"]
  281. concede_home = item["concede_home"]
  282. concede_home_rule = item["concede_home_rule"]
  283. # concede_guest
  284. for index, value in enumerate(concede_guest):
  285. hash_str = p_code + "concede_guest" + str(index) + str(concede_guest_rule[index]) + str(
  286. value) + "hg3535" + str(match_id)
  287. sole_str = p_code + "concede_guest" + str(index) + str(match_id) + "hg3535"
  288. odds_only = Helper.genearte_MD5(hash_str)
  289. sole = Helper.genearte_MD5(sole_str)
  290. odds_onlys.append(odds_only)
  291. concede_guest_key = ["match_id", "lg_id", "odds_code", "status", "sort", "p_code", "odds", "condition",
  292. "odds_only", "sole", "source", "type", "team"]
  293. condition = fuhao(concede_guest[index])
  294. concede_guest_value = [match_id, league_id, "concede_guest", "0", index, p_code, value, condition,
  295. odds_only, sole, "hg3535", "0", ""]
  296. concede_guest_data = dict(zip(concede_guest_key, concede_guest_value))
  297. if odds_only not in uuid_list:
  298. data_list.append(concede_guest_data)
  299. # concede_home
  300. for index, value in enumerate(concede_home):
  301. hash_str = p_code + "concede_home" + str(index) + str(concede_home_rule[index]) + str(
  302. value) + "hg3535" + str(match_id)
  303. sole_str = p_code + "concede_home" + str(index) + str(match_id) + "hg3535"
  304. odds_only = Helper.genearte_MD5(hash_str)
  305. sole = Helper.genearte_MD5(sole_str)
  306. odds_onlys.append(odds_only)
  307. concede_home_key = ["match_id", "lg_id", "odds_code", "status", "sort", "p_code", "odds", "condition",
  308. "odds_only", "sole", "source", "type", "team"]
  309. condition = fuhao(concede_home_rule[index])
  310. concede_home_value = [match_id, league_id, "concede_home", "0", index, p_code, value, condition, odds_only,
  311. sole, "hg3535", "0", ""]
  312. concede_guest_data = dict(zip(concede_home_key, concede_home_value))
  313. if odds_only not in uuid_list:
  314. data_list.append(concede_guest_data)
  315. # 独赢----------------------------------------------------------------------------------------------------------
  316. p_code, p_id = get_pcode(corner_ball, 'capot')
  317. half_capot_home = item["half_capot_home"]
  318. half_capot_guest = item["half_capot_guest"]
  319. half_capot_dogfall = item["half_capot_dogfall"]
  320. capot_home = item["capot_home"]
  321. capot_guest = item["capot_guest"]
  322. capot_dogfall = item["capot_dogfall"]
  323. # half_capot_home
  324. hash_str = p_code + "half_capot_home" + '0' + '1' + str(half_capot_home) + "hg3535" + str(match_id)
  325. sole_str = p_code + "half_capot_home" + '0' + str(match_id) + "hg3535"
  326. odds_only = Helper.genearte_MD5(hash_str)
  327. sole = Helper.genearte_MD5(sole_str)
  328. odds_onlys.append(odds_only)
  329. half_capot_home_key = ["match_id", "lg_id", "odds_code", "status", "sort", "p_code", "odds", "condition",
  330. "odds_only", "sole", "source", "type", "team"]
  331. half_capot_home_value = [match_id, league_id, "half_capot_home", "0", 0, p_code, half_capot_home, '1',
  332. odds_only, sole, "hg3535", "0", ""]
  333. half_capot_homet_data = dict(zip(half_capot_home_key, half_capot_home_value))
  334. if odds_only not in uuid_list:
  335. data_list.append(half_capot_homet_data)
  336. # half_capot_guest
  337. hash_str = p_code + "half_capot_guest" + '0' + '2' + str(half_capot_guest) + "hg3535" + str(match_id)
  338. sole_str = p_code + "half_capot_guest" + '0' + str(match_id) + "hg3535"
  339. odds_only = Helper.genearte_MD5(hash_str)
  340. sole = Helper.genearte_MD5(sole_str)
  341. odds_onlys.append(odds_only)
  342. half_capot_guest_key = ["match_id", "lg_id", "odds_code", "status", "sort", "p_code", "odds", "condition",
  343. "odds_only", "sole", "source", "type", "team"]
  344. half_capot_guest_value = [match_id, league_id, "half_capot_guest", "0", 0, p_code, half_capot_guest, '2',
  345. odds_only, sole, "hg3535", "0", ""]
  346. half_capot_guest_data = dict(zip(half_capot_guest_key, half_capot_guest_value))
  347. if odds_only not in uuid_list:
  348. data_list.append(half_capot_guest_data)
  349. # half_capot_dogfall
  350. hash_str = p_code + "half_capot_dogfall" + '0' + 'X' + str(half_capot_dogfall) + "hg3535" + str(match_id)
  351. sole_str = p_code + "half_capot_dogfall" + '0' + str(match_id) + "hg3535"
  352. odds_only = Helper.genearte_MD5(hash_str)
  353. sole = Helper.genearte_MD5(sole_str)
  354. odds_onlys.append(odds_only)
  355. half_capot_dogfall_key = ["match_id", "lg_id", "odds_code", "status", "sort", "p_code", "odds", "condition",
  356. "odds_only", "sole", "source", "type", "team"]
  357. half_capot_dogfall_value = [match_id, league_id, "half_capot_guest", "0", 0, p_code, half_capot_dogfall, 'X',
  358. odds_only, sole, "hg3535", "0", ""]
  359. half_capot_dogfall_data = dict(zip(half_capot_dogfall_key, half_capot_dogfall_value))
  360. if odds_only not in uuid_list:
  361. data_list.append(half_capot_dogfall_data)
  362. # capot_dogfall
  363. hash_str = p_code + "capot_dogfall" + '0' + 'X' + str(capot_dogfall) + "hg3535" + str(match_id)
  364. sole_str = p_code + "capot_dogfall" + '0' + str(match_id) + "hg3535"
  365. odds_only = Helper.genearte_MD5(hash_str)
  366. sole = Helper.genearte_MD5(sole_str)
  367. odds_onlys.append(odds_only)
  368. capot_dogfall_key = ["match_id", "lg_id", "odds_code", "status", "sort", "p_code", "odds", "condition",
  369. "odds_only", "sole", "source", "type", "team"]
  370. capot_dogfall_value = [match_id, league_id, "half_capot_guest", "0", 0, p_code, capot_dogfall, 'X', odds_only,
  371. sole, "hg3535", "0", ""]
  372. capot_dogfall_data = dict(zip(capot_dogfall_key, capot_dogfall_value))
  373. if odds_only not in uuid_list:
  374. data_list.append(capot_dogfall_data)
  375. # capot_home
  376. hash_str = p_code + "capot_home" + '0' + '1' + str(capot_home) + "hg3535" + str(match_id)
  377. sole_str = p_code + "capot_home" + '0' + str(match_id) + "hg3535"
  378. odds_only = Helper.genearte_MD5(hash_str)
  379. sole = Helper.genearte_MD5(sole_str)
  380. odds_onlys.append(odds_only)
  381. capot_home_key = ["match_id", "lg_id", "odds_code", "status", "sort", "p_code", "odds", "condition",
  382. "odds_only", "sole", "source", "type", "team"]
  383. capot_home_value = [match_id, league_id, "half_capot_home", "0", 0, p_code, capot_home, '1',
  384. odds_only, sole, "hg3535", "0", ""]
  385. capot_homet_data = dict(zip(capot_home_key, capot_home_value))
  386. if odds_only not in uuid_list:
  387. data_list.append(capot_homet_data)
  388. # capot_guest
  389. hash_str = p_code + "capot_guest" + '0' + '2' + str(capot_guest) + "hg3535" + str(match_id)
  390. sole_str = p_code + "capot_guest" + '0' + str(match_id) + "hg3535"
  391. odds_only = Helper.genearte_MD5(hash_str)
  392. sole = Helper.genearte_MD5(sole_str)
  393. odds_onlys.append(odds_only)
  394. capot_guest_key = ["match_id", "lg_id", "odds_code", "status", "sort", "p_code", "odds", "condition",
  395. "odds_only", "sole", "source", "type", "team"]
  396. capot_guest_value = [match_id, league_id, "half_capot_guest", "0", 0, p_code, capot_home, '2',
  397. odds_only, sole, "hg3535", "0", ""]
  398. capot_guest_data = dict(zip(capot_guest_key, capot_guest_value))
  399. if odds_only not in uuid_list:
  400. data_list.append(capot_guest_data)
  401. # 入球数单双-----------------------------------------------------------------------------------------------------
  402. p_code, p_id = get_pcode(corner_ball, 'two_sides')
  403. odd_even_odd = item["odd_even_odd"]
  404. odd_even_even = item["odd_even_even"]
  405. half_odd_even_odd = item["half_odd_even_odd"]
  406. half_odd_even_even = item["half_odd_even_even"]
  407. # odd_even_odd
  408. hash_str = p_code + "two_sides_single" + '0' + '单' + str(odd_even_odd) + "hg3535" + str(match_id)
  409. sole_str = p_code + "two_sides_single" + '0' + str(match_id) + "hg3535"
  410. odds_only = Helper.genearte_MD5(hash_str)
  411. sole = Helper.genearte_MD5(sole_str)
  412. odds_onlys.append(odds_only)
  413. single_key = ["match_id", "lg_id", "odds_code", "status", "sort", "p_code", "odds", "condition",
  414. "odds_only", "sole", "source", "type", "team"]
  415. single_value = [match_id, league_id, "two_sides_single", "0", 0, p_code, odd_even_odd, '单',
  416. odds_only, sole, "hg3535", "0", ""]
  417. single_data = dict(zip(single_key, single_value))
  418. if odds_only not in uuid_list:
  419. data_list.append(single_data)
  420. # odd_even_even
  421. hash_str = p_code + "two_sides_double" + '0' + '双' + str(odd_even_even) + "hg3535" + str(match_id)
  422. sole_str = p_code + "two_sides_double" + '0' + str(match_id) + "hg3535"
  423. odds_only = Helper.genearte_MD5(hash_str)
  424. sole = Helper.genearte_MD5(sole_str)
  425. odds_onlys.append(odds_only)
  426. double_key = ["match_id", "lg_id", "odds_code", "status", "sort", "p_code", "odds", "condition",
  427. "odds_only", "sole", "source", "type", "team"]
  428. double_value = [match_id, league_id, "two_sides_double", "0", 0, p_code, odd_even_even, '双',
  429. odds_only, sole, "hg3535", "0", ""]
  430. double_data = dict(zip(double_key, double_value))
  431. if odds_only not in uuid_list:
  432. data_list.append(double_data)
  433. # half_odd_even_even
  434. hash_str = p_code + "two_sides_double" + '0' + '双' + str(half_odd_even_even) + "hg3535" + str(match_id)
  435. sole_str = p_code + "two_sides_double" + '0' + str(match_id) + "hg3535"
  436. odds_only = Helper.genearte_MD5(hash_str)
  437. sole = Helper.genearte_MD5(sole_str)
  438. odds_onlys.append(odds_only)
  439. half_double_key = ["match_id", "lg_id", "odds_code", "status", "sort", "p_code", "odds", "condition",
  440. "odds_only", "sole", "source", "type", "team"]
  441. half_double_value = [match_id, league_id, "two_sides_double", "0", 0, p_code, half_odd_even_even, '双',
  442. odds_only, sole, "hg3535", "0", ""]
  443. half_double_data = dict(zip(half_double_key, half_double_value))
  444. if odds_only not in uuid_list:
  445. data_list.append(half_double_data)
  446. # half_odd_even_odd
  447. hash_str = p_code + "two_sides_single" + '0' + '单' + str(half_odd_even_odd) + "hg3535" + str(match_id)
  448. sole_str = p_code + "two_sides_single" + '0' + str(match_id) + "hg3535"
  449. odds_only = Helper.genearte_MD5(hash_str)
  450. sole = Helper.genearte_MD5(sole_str)
  451. odds_onlys.append(odds_only)
  452. half_single_key = ["match_id", "lg_id", "odds_code", "status", "sort", "p_code", "odds", "condition",
  453. "odds_only", "sole", "source", "type", "team"]
  454. half_single_value = [match_id, league_id, "two_sides_single", "0", 0, p_code, half_odd_even_odd, '单', odds_only,
  455. sole, "hg3535", "0", ""]
  456. half_single_data = dict(zip(half_single_key, half_single_value))
  457. if odds_only not in uuid_list:
  458. data_list.append(half_single_data)
  459. # 总入球数 ------------------------------------------------------------------------------------------------------
  460. p_code, p_id = get_pcode(corner_ball, 'total_goal')
  461. total_goals = item['total_goal']
  462. total_dict = {'total_goal_zero': '0-1', 'total_goal_two': '2-3', 'total_goal_four': '4-6',
  463. 'total_goal_seven': '7或以上', 'half_total_goal_zero': '0', "half_total_goal_one": '1',
  464. "half_total_goal_two": '2', "half_total_goal_three": '3或以上'}
  465. # 全场入球数 单双
  466. # 上半场入球数 单双
  467. for key, value in total_goals.items():
  468. hash_str = p_code + key + '0' + total_dict[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)
  471. sole = Helper.genearte_MD5(sole_str)
  472. odds_onlys.append(odds_only)
  473. total_goals_key = ["match_id", "lg_id", "odds_code", "status", "sort", "p_code", "odds", "condition",
  474. "odds_only", "sole", "source", "type", "team"]
  475. total_goals_value = [match_id, league_id, key, "0", 0, p_code, value, total_dict[key], odds_only,
  476. sole, "hg3535", "0", ""]
  477. total_goals_data = dict(zip(total_goals_key, total_goals_value))
  478. if odds_only not in uuid_list:
  479. data_list.append(total_goals_data)
  480. # 全场半场 ------------------------------------------------------------------------------------------------------
  481. half_fulls = item['half_full']
  482. p_code, p_id = get_pcode(corner_ball, 'half_full')
  483. full_dict = {"half_full_home_home": "主主", "half_full_home_dogfall": "主和",
  484. "half_full_home_guest": "主客", "half_full_dogfall_home": "和主",
  485. "half_full_dogfall_dogfall": "和和", "half_full_dogfall_guest": "和客",
  486. "half_full_guest_home": "客主", "half_full_guest_dogfall": "客和",
  487. "half_full_guest_guest": "客客"}
  488. if half_fulls:
  489. for key, value in half_fulls.items():
  490. hash_str = p_code + key + '0' + full_dict[key] + str(value) + "hg3535" + str(match_id)
  491. sole_str = p_code + key + '0' + str(match_id) + "hg3535"
  492. odds_only = Helper.genearte_MD5(hash_str)
  493. sole = Helper.genearte_MD5(sole_str)
  494. odds_onlys.append(odds_only)
  495. half_fulls_key = ["match_id", "lg_id", "odds_code", "status", "sort", "p_code", "odds", "condition",
  496. "odds_only", "sole", "source", "type", "team"]
  497. half_fulls_value = [match_id, league_id, key, "0", 0, p_code, value, full_dict[key], odds_only,
  498. sole, "hg3535", "0", ""]
  499. half_fulls_data = dict(zip(half_fulls_key, half_fulls_value))
  500. if odds_only not in uuid_list:
  501. data_list.append(half_fulls_data)
  502. # 波胆------------------------------------------------------------------------------------------------------------------
  503. bodan_datas = item['bodan_data']
  504. p_code, p_id = get_pcode(corner_ball, 'bodan')
  505. bodan_dict = {"bodanhome_one_zero": "1-0", "bodanhome_two_zero": "2-0",
  506. "bodanhome_two_one": "2-1", "bodanhome_three_zero": "3-0",
  507. "bodanhome_three_one": "3-1", "bodanhome_three_two": "3-2",
  508. "bodanhome_four_zero": "4-0", "bodanhome_four_one": "4-1",
  509. "bodanhome_four_two": "4-2", "bodanhome_four_three": "4-3",
  510. "bodanguest_one_zero": "0-1", "bodanguest_two_zero": "0-2",
  511. "bodanguest_two_one": "1-2", "bodanguest_three_zero": "0-3",
  512. "bodanguest_three_one": "1-3", "bodanguest_three_two": "2-3",
  513. "bodanguest_four_zero": "0-4", "bodanguest_four_one": "1-4",
  514. "bodanguest_four_two": "2-4", "bodanguest_four_three": "3-4",
  515. "bodandogfall_zero_zero": "0-0", "bodandogfall_one_one": "1-1",
  516. "bodandogfall_two_two": "2-2", "bodandogfall_three_three": "3-3",
  517. "bodandogfall_four_four": "4-4", "bodanother": "其他",
  518. "halfbodanhome_one_zero": "1-0", "halfbodanhome_two_zero": "2-0",
  519. "halfbodanhome_two_one": "2-1", "halfbodanhome_three_zero": "3-0",
  520. "halfbodanhome_three_one": "3-1", "halfbodanhome_three_two": "3-2",
  521. "halfbodanguest_one_zero": "0-1", "halfbodanguest_two_zero": "0-2",
  522. "halfbodanguest_two_one": "1-2", "halfbodanguest_three_zero": "0-3",
  523. "halfbodanguest_three_one": "1-3", "halfbodanguest_three_two": "2-3",
  524. "halfbodandogfall_zero_zero": "0-0", "halfbodandogfall_one_one": "1-1",
  525. "halfbodandogfall_two_two": "2-2", "halfbodandogfall_three_three": "3-3",
  526. "halfbodanother": "其他"}
  527. if bodan_datas:
  528. for key, value in bodan_datas.items():
  529. hash_str = p_code + key + '0' + bodan_dict[key] + str(value) + "hg3535" + str(match_id)
  530. sole_str = p_code + key + '0' + str(match_id) + "hg3535"
  531. odds_only = Helper.genearte_MD5(hash_str)
  532. sole = Helper.genearte_MD5(sole_str)
  533. odds_onlys.append(odds_only)
  534. bodan_dict_key = ["match_id", "lg_id", "odds_code", "status", "sort", "p_code", "odds", "condition",
  535. "odds_only", "sole", "source", "type", "team"]
  536. bodan_dict_value = [match_id, league_id, key, "0", 0, p_code, value, bodan_dict[key], odds_only,
  537. sole, "hg3535", "0", ""]
  538. bodan_dict_data = dict(zip(bodan_dict_key, bodan_dict_value))
  539. if odds_only not in uuid_list:
  540. data_list.append(bodan_dict_data)
  541. # 最先进球/最后进球 ----------------------------------------------------------------------------------------------
  542. first_last_balls = item['first_last_ball']
  543. p_code, p_id = get_pcode(corner_ball, 'first_last_ball')
  544. first_last_dict = {"first_last_ball": "最先进球", "first_ball_home": "最先进球", "first_ball_guest": "最先进球",
  545. "last_ball_home": "最后进球", "last_ball_guest": "最后进球", "not_ball": "没有进球"}
  546. if first_last_balls:
  547. for key, value in first_last_balls.items():
  548. hash_str = p_code + key + '0' + first_last_dict[key] + str(value) + "hg3535" + str(match_id)
  549. sole_str = p_code + key + '0' + str(match_id) + "hg3535"
  550. odds_only = Helper.genearte_MD5(hash_str)
  551. sole = Helper.genearte_MD5(sole_str)
  552. odds_onlys.append(odds_only)
  553. first_last_balls_key = ["match_id", "lg_id", "odds_code", "status", "sort", "p_code", "odds", "condition",
  554. "odds_only", "sole", "source", "type", "team"]
  555. first_last_balls_value = [match_id, league_id, key, "0", 0, p_code, value, first_last_dict[key], odds_only,
  556. sole, "hg3535", "0", ""]
  557. first_last_balls_data = dict(zip(first_last_balls_key, first_last_balls_value))
  558. if odds_only not in uuid_list:
  559. data_list.append(first_last_balls_data)
  560. p_code, p_id = get_pcode(corner_ball, 'tema_ball')
  561. full_dicts = item['full_data']
  562. half_dicts = item['half_data']
  563. full_dict_rules = item['full_data_rule']
  564. half_dict_rules = item['half_data_rule']
  565. if full_dicts:
  566. for key, value in full_dicts.items():
  567. hash_str = p_code + key + '0' + full_dict_rules[key] + str(value) + "hg3535" + str(match_id)
  568. sole_str = p_code + key + '0' + str(match_id) + "hg3535"
  569. odds_only = Helper.genearte_MD5(hash_str)
  570. sole = Helper.genearte_MD5(sole_str)
  571. odds_onlys.append(odds_only)
  572. full_dict_rules_key = ["match_id", "lg_id", "odds_code", "status", "sort", "p_code", "odds",
  573. "condition", "odds_only", "sole", "source", "type", "team"]
  574. full_dict_rules_value = [match_id, league_id, key, "0", 0, p_code, value, full_dict_rules[key],
  575. odds_only,sole, "hg3535", "0", ""]
  576. full_dict_rules_data = dict(zip(full_dict_rules_key, full_dict_rules_value))
  577. if odds_only not in uuid_list:
  578. data_list.append(full_dict_rules_data)
  579. #
  580. if half_dicts:
  581. for key, value in half_dicts.items():
  582. hash_str = p_code + key + '0' + half_dict_rules[key] + str(value) + "hg3535" + str(match_id)
  583. sole_str = p_code + key + '0' + str(match_id) + "hg3535"
  584. odds_only = Helper.genearte_MD5(hash_str)
  585. sole = Helper.genearte_MD5(sole_str)
  586. odds_onlys.append(odds_only)
  587. half_dicts_key = ["match_id", "lg_id", "odds_code", "status", "sort", "p_code", "odds",
  588. "condition","odds_only", "sole", "source", "type", "team"]
  589. half_dicts_value = [match_id, league_id, key, "0", 0, p_code, value, half_dict_rules[key],
  590. odds_only, sole, "hg3535", "0", ""]
  591. half_dicts_data = dict(zip(half_dicts_key, half_dicts_value))
  592. if odds_only not in uuid_list:
  593. data_list.append(half_dicts_data)
  594. if pt == '3':
  595. ris_stringscene = 1
  596. else:
  597. ris_stringscene = 0
  598. odds_key = ["game_code", "title", "match_id", "lg_id", "data", "source", "odds_only", "tag", "uuid", "is_stringscene", "utime", "pt"]
  599. odds_value = ["zq", "odds", match_id, league_id, data_list, "hg3535", odds_onlys, tag_number, uuid, ris_stringscene, utime, pt]
  600. odds_dict = dict(zip(odds_key, odds_value))
  601. if data_list:
  602. # print(odds_dict)
  603. response_data = Helper.async_post(url + '/setOdds', odds_dict)
  604. print(response_data)
  605. if "成功" in response_data:
  606. if result:
  607. self.db.hg3535_zq_odds.update({'match_id': match_id, 'pt': pt}, {'$set': {"data": data_list, "odds_only": odds_onlys, "utime": utime}}, upsert=True)
  608. else:
  609. self.db.hg3535_zq_odds.insert(odds_dict)