roll_zuqiu.py 35 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614
  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
  8. # 滚球足球 插入
  9. class Roll_Zuqiupipeline(object):
  10. def open_spider(self, spider):
  11. self.mongo = pymongo.MongoClient(host="192.168.2.200", username="kaiyou", password="kaiyou", port=27017)
  12. self.db = self.mongo['kaiyou']
  13. def process_item(self, item, spider):
  14. logger = logging.getLogger(__name__)
  15. url = 'http://admin.5gogo.com'
  16. pt = 4
  17. roll_zq = []
  18. # 比赛日期
  19. try:
  20. data_game = item['data_game'].split("/")
  21. month = str(data_game[1].strip())
  22. day = str(data_game[0])
  23. except Exception as e:
  24. logger.warning(e)
  25. data_game = item['data_game'].split(" ")
  26. months = str(data_game[1].strip())
  27. month_dict = {'Jan': '01', 'Feb': '02', 'Mar': '03', 'Apr': '04', 'May': '05', 'Jun': '06', 'Jul': '07', 'Aug': '08', 'Sep': '09', 'Oct': '10', 'Nov': '11', 'Dec': '12'}
  28. month = month_dict[months]
  29. day = str(data_game[0])
  30. # 比赛时间
  31. time_game = str(item['time_game'])
  32. # print(time_game)
  33. # 比赛时间,时间戳
  34. ctime = "2019" + "-" + month + "-" + day + "" + time_game + ":00"
  35. r_ctime = "2019" + "-" + month + "-" + day
  36. # 现在时间,时间戳
  37. utime = time.strftime("%Y-%m-%d %H:%M:%S", time.localtime())
  38. expire_time = time.strftime("%Y-%m-%d %H:%M:%S", time.localtime(time.time() + 60))
  39. # 比赛id
  40. match_id = item['game_id']
  41. # 联赛id
  42. league_id = item['league_id']
  43. # 联赛name
  44. league_name = item['league_name']
  45. # 主队
  46. team_home = item['team_home']
  47. # 客队
  48. team_guest = item['team_guest']
  49. # number
  50. number = item['number']
  51. score_home = item['score_home']
  52. score_guest = item['score_guest']
  53. all_goal = int(score_home) + int(score_guest)
  54. half_way = item['half_way']
  55. # pt = item['pt']
  56. match_score = "{}:{}".format(score_home,score_guest)
  57. corner_ball = item['corner_ball']
  58. last_time = '2019-12-31 23:59:59'
  59. league_dict = {"game_code": "zq", "title": "league", "source": "hg3535"}
  60. league_list = []
  61. uuid = Helper.genearte_MD5(league_name + 'hg3535')
  62. league_key = ["name_chinese", "kind", "match_mode", "if_stop", "last_time", "lg_id", "source", "uuid"]
  63. league_value = [league_name, "1", "1", "0", last_time, league_id, "hg3535", uuid]
  64. league_data = dict(zip(league_key, league_value))
  65. league_list.append(league_data)
  66. league_dict['data'] = league_list
  67. if self.db.hg3535_zq_league.find({'league_id': league_id}).count() < 1:
  68. response_data = Helper.async_post(url + '/setLeague', league_dict)
  69. print('足球联赛请求成功', response_data)
  70. if "成功" in response_data:
  71. self.db.hg3535_zq_league.insert(league_list)
  72. competition = self.db.hg3535_zq_competition.find_one({"match_id": match_id})
  73. match_list = []
  74. if competition:
  75. print('赛事已存在,修改赛事四状态')
  76. is_morningplate = competition['is_morningplate']
  77. is_rollball = competition['is_rollball']
  78. is_stringscene = competition['is_stringscene']
  79. is_today = competition['is_today']
  80. status = competition['status']
  81. match_date = competition['match_date']
  82. match_time = competition['match_time']
  83. us_time = competition['us_time']
  84. # if pt == '3':
  85. if is_rollball != 1 or status != 1:
  86. match_dict = {"game_code": "zq", "title": "match", "source": "hg3535"}
  87. match_kay = ["home_team", "guest_team", "lg_id", "status", "match_id", "match_date", "match_time",
  88. "tag", "source", "is_rollball", "is_morningplate", "is_stringscene", "us_time", "uuid",
  89. "half_match_id", "is_today"]
  90. match_value = [team_home, team_guest, league_id, 1, match_id, match_date, match_time, number,
  91. "hg3535", 1, is_morningplate, is_stringscene, us_time, uuid, 0, is_today]
  92. match_data = dict(zip(match_kay, match_value))
  93. match_list.append(match_data)
  94. match_dict['data'] = match_list
  95. print(match_dict)
  96. response_data = Helper.async_post(url + '/setMatch', match_dict)
  97. print('足球赛事请求成功', response_data)
  98. if "成功" in response_data:
  99. self.db.hg3535_zq_competition.update({'match_id': match_id}, {"$set": {"is_rollball": 1, "status": 1}},
  100. upsert=True)
  101. else:
  102. print("赛事已存在,赛事状态时间为改变,不做修改")
  103. else:
  104. is_rollball = 1
  105. is_today = 0
  106. is_morningplate = 0
  107. is_stringscene = 0
  108. # 赛事接口写入
  109. match_dict = {"game_code": "zq", "title": "match", "source": "hg3535"}
  110. match_kay = ["home_team", "guest_team", "lg_id", "status", "match_id", "match_date", "match_time", "tag",
  111. "source", "is_rollball", "is_morningplate", "is_stringscene", "us_time", "uuid",
  112. "half_match_id", "is_today"]
  113. match_value = [team_home, team_guest, league_id, 1, match_id, r_ctime, "00:00", number, "hg3535",
  114. is_rollball, is_morningplate, is_stringscene, utime, uuid, 0, is_today]
  115. match_data = dict(zip(match_kay, match_value))
  116. match_list.append(match_data)
  117. match_dict['data'] = match_list
  118. response_data = Helper.async_post(url + '/setMatch', match_dict)
  119. print(match_dict)
  120. print('足球赛事请求成功', response_data)
  121. if "成功" in response_data:
  122. self.db.hg3535_zq_competition.insert(match_list)
  123. # print(response_data)
  124. # 赔率
  125. try:
  126. result = self.db.hg3535_zq_odds.find_one({'match_id': match_id, 'pt': pt})
  127. uuid_list = result['odds_only']
  128. except:
  129. uuid_list = []
  130. result = ''
  131. # p_code, p_id = get_pcode(corner_ball, 'goal_size')
  132. p_code = "GS"
  133. # 构建唯一索引
  134. half_size_guest = item["half_size_guest"]
  135. half_size_guest_rule = item["half_size_guest_rule"]
  136. half_size_home = item["half_size_home"]
  137. half_size_home_rule = item["half_size_home_rule"]
  138. # zuqiu = item['zuqiu']
  139. data_list = []
  140. odds_onlys = []
  141. # half_size_guest
  142. for index, value in enumerate(half_size_guest):
  143. hash_str = p_code + "gss_h" + str(index) + str(half_size_guest_rule[index]) + str(
  144. value) + "hg3535" + str(match_id)
  145. sole_str = p_code + "gss_h" + str(index) + str(match_id) + "hg3535"
  146. odds_only = Helper.genearte_MD5(hash_str)
  147. sole = Helper.genearte_MD5(sole_str)
  148. odds_onlys.append(odds_only)
  149. half_size_guest_key = ["match_id", "lg_id", "odds_code", "status", "sort", "p_code", "odds", "condition",
  150. "odds_only", "sole", "source", "type", "team"]
  151. condition = fuhao(half_size_guest_rule[index])
  152. half_size_guest_value = [match_id, league_id, "gss_h", "0", index, p_code, value, condition,
  153. odds_only, sole, "hg3535", "0", ""]
  154. half_size_guest_data = dict(zip(half_size_guest_key, half_size_guest_value))
  155. if odds_only not in uuid_list:
  156. data_list.append(half_size_guest_data)
  157. # half_size_home
  158. for index, value in enumerate(half_size_home):
  159. hash_str = p_code + "gsb_h" + str(index) + str(half_size_home_rule[index]) + str(
  160. value) + "hg3535" + str(match_id)
  161. sole_str = p_code + "gsb_h" + str(index) + str(match_id) + "hg3535"
  162. odds_only = Helper.genearte_MD5(hash_str)
  163. sole = Helper.genearte_MD5(sole_str)
  164. odds_onlys.append(odds_only)
  165. half_size_home_key = ["match_id", "lg_id", "odds_code", "status", "sort", "p_code", "odds", "condition",
  166. "odds_only", "sole", "source", "type", "team"]
  167. condition = fuhao(half_size_home_rule[index])
  168. half_size_home_value = [match_id, league_id, "gsb_h", "0", index, p_code, value, condition,
  169. odds_only, sole, "hg3535", "0", ""]
  170. half_size_home_data = dict(zip(half_size_home_key, half_size_home_value))
  171. if odds_only not in uuid_list:
  172. data_list.append(half_size_home_data)
  173. # 全场场大小
  174. size_guest = item["size_guest"]
  175. size_guest_rule = item["size_guest_rule"]
  176. size_home = item["size_home"]
  177. size_home_rule = item["size_home_rule"]
  178. # size_home
  179. for index, value in enumerate(size_home):
  180. hash_str = p_code + "gsb" + str(index) + str(size_home_rule[index]) + str(value) + "hg3535" + str(
  181. match_id)
  182. sole_str = p_code + "gsb" + str(index) + str(match_id) + "hg3535"
  183. odds_only = Helper.genearte_MD5(hash_str)
  184. sole = Helper.genearte_MD5(sole_str)
  185. odds_onlys.append(odds_only)
  186. size_home_key = ["match_id", "lg_id", "odds_code", "status", "sort", "p_code", "odds", "condition",
  187. "odds_only", "sole", "source", "type", "team"]
  188. condition = fuhao(size_home_rule[index])
  189. size_home_value = [match_id, league_id, "gsb", "0", index, p_code, value, condition, odds_only,
  190. sole, "hg3535", "0", ""]
  191. size_home_data = dict(zip(size_home_key, size_home_value))
  192. if odds_only not in uuid_list:
  193. data_list.append(size_home_data)
  194. # size_guest
  195. for index, value in enumerate(size_guest):
  196. hash_str = p_code + "gss" + str(index) + str(size_guest_rule[index]) + str(value) + "hg3535" + str(
  197. match_id)
  198. sole_str = p_code + "gss" + str(index) + str(match_id) + "hg3535"
  199. odds_only = Helper.genearte_MD5(hash_str)
  200. sole = Helper.genearte_MD5(sole_str)
  201. odds_onlys.append(odds_only)
  202. size_guest_key = ["match_id", "lg_id", "odds_code", "status", "sort", "p_code", "odds", "condition",
  203. "odds_only", "sole", "source", "type", "team"]
  204. condition = fuhao(size_guest_rule[index])
  205. size_guest_value = [match_id, league_id, "gss", "0", index, p_code, value, condition, odds_only,
  206. sole, "hg3535", "0", ""]
  207. size_home_data = dict(zip(size_guest_key, size_guest_value))
  208. if odds_only not in uuid_list:
  209. data_list.append(size_home_data)
  210. # p_code, p_id = get_pcode(corner_ball, 'concede')
  211. p_code = 'CO'
  212. half_concede_home_rule = item["half_concede_home_rule"]
  213. half_concede_home = item["half_concede_home"]
  214. half_concede_guest_rule = item["half_concede_guest_rule"]
  215. half_concede_guest = item["half_concede_guest"]
  216. # half_concede_home
  217. for index, value in enumerate(half_concede_guest):
  218. hash_str = p_code + "cog_h" + str(index) + str(half_concede_guest_rule[index]) + str(
  219. value) + "hg3535" + str(match_id)
  220. sole_str = p_code + "cog_h" + str(index) + str(match_id) + "hg3535"
  221. odds_only = Helper.genearte_MD5(hash_str)
  222. sole = Helper.genearte_MD5(sole_str)
  223. odds_onlys.append(odds_only)
  224. half_concede_guest_key = ["match_id", "lg_id", "odds_code", "status", "sort", "p_code", "odds", "condition",
  225. "odds_only", "sole", "source", "type", "team"]
  226. condition = fuhao(half_concede_guest_rule[index])
  227. half_concede_guest_value = [match_id, league_id, "cog_h", "0", index, p_code, value, condition,
  228. odds_only, sole, "hg3535", "0", ""]
  229. half_concede_guest_data = dict(zip(half_concede_guest_key, half_concede_guest_value))
  230. if odds_only not in uuid_list:
  231. data_list.append(half_concede_guest_data)
  232. # half_concede_home
  233. for index, value in enumerate(half_concede_home):
  234. hash_str = p_code + "coh_h" + str(index) + str(half_concede_home_rule[index]) + str(
  235. value) + "hg3535" + str(match_id)
  236. sole_str = p_code + "coh_h" + str(index) + str(match_id) + "hg3535"
  237. odds_only = Helper.genearte_MD5(hash_str)
  238. sole = Helper.genearte_MD5(sole_str)
  239. odds_onlys.append(odds_only)
  240. half_concede_home_key = ["match_id", "lg_id", "odds_code", "status", "sort", "p_code", "odds", "condition",
  241. "odds_only", "sole", "source", "type", "team"]
  242. condition = fuhao(half_concede_home_rule[index])
  243. half_concede_home_value = [match_id, league_id, "coh_h", "0", index, p_code, value, condition,
  244. odds_only, sole, "hg3535", "0", ""]
  245. half_concede_home_data = dict(zip(half_concede_home_key, half_concede_home_value))
  246. if odds_only not in uuid_list:
  247. data_list.append(half_concede_home_data)
  248. concede_guest = item["concede_guest"]
  249. concede_guest_rule = item["concede_guest_rule"]
  250. concede_home = item["concede_home"]
  251. concede_home_rule = item["concede_home_rule"]
  252. # concede_guest
  253. for index, value in enumerate(concede_guest):
  254. hash_str = p_code + "cog" + str(index) + str(concede_guest_rule[index]) + str(
  255. value) + "hg3535" + str(match_id)
  256. sole_str = p_code + "cog" + str(index) + str(match_id) + "hg3535"
  257. odds_only = Helper.genearte_MD5(hash_str)
  258. sole = Helper.genearte_MD5(sole_str)
  259. odds_onlys.append(odds_only)
  260. concede_guest_key = ["match_id", "lg_id", "odds_code", "status", "sort", "p_code", "odds", "condition",
  261. "odds_only", "sole", "source", "type", "team"]
  262. condition = fuhao(concede_guest[index])
  263. concede_guest_value = [match_id, league_id, "cog", "0", index, p_code, value, condition,
  264. odds_only, sole, "hg3535", "0", ""]
  265. concede_guest_data = dict(zip(concede_guest_key, concede_guest_value))
  266. if odds_only not in uuid_list:
  267. data_list.append(concede_guest_data)
  268. # concede_home
  269. for index, value in enumerate(concede_home):
  270. hash_str = p_code + "coh" + str(index) + str(concede_home_rule[index]) + str(
  271. value) + "hg3535" + str(match_id)
  272. sole_str = p_code + "coh" + str(index) + str(match_id) + "hg3535"
  273. odds_only = Helper.genearte_MD5(hash_str)
  274. sole = Helper.genearte_MD5(sole_str)
  275. odds_onlys.append(odds_only)
  276. concede_home_key = ["match_id", "lg_id", "odds_code", "status", "sort", "p_code", "odds", "condition",
  277. "odds_only", "sole", "source", "type", "team"]
  278. condition = fuhao(concede_home_rule[index])
  279. concede_home_value = [match_id, league_id, "coh", "0", index, p_code, value, condition, odds_only,
  280. sole, "hg3535", "0", ""]
  281. concede_guest_data = dict(zip(concede_home_key, concede_home_value))
  282. if odds_only not in uuid_list:
  283. data_list.append(concede_guest_data)
  284. # 独赢----------------------------------------------------------------------------------------------------------
  285. # p_code, p_id = get_pcode(corner_ball, 'capot')
  286. p_code = 'C'
  287. half_capot_home = item["half_capot_home"]
  288. half_capot_guest = item["half_capot_guest"]
  289. half_capot_dogfall = item["half_capot_dogfall"]
  290. capot_home = item["capot_home"]
  291. capot_guest = item["capot_guest"]
  292. capot_dogfall = item["capot_dogfall"]
  293. # half_capot_home
  294. hash_str = p_code + "ch_h" + '0' + '1' + str(half_capot_home) + "hg3535" + str(match_id)
  295. sole_str = p_code + "ch_h" + '0' + str(match_id) + "hg3535"
  296. odds_only = Helper.genearte_MD5(hash_str)
  297. sole = Helper.genearte_MD5(sole_str)
  298. odds_onlys.append(odds_only)
  299. half_capot_home_key = ["match_id", "lg_id", "odds_code", "status", "sort", "p_code", "odds", "condition",
  300. "odds_only", "sole", "source", "type", "team"]
  301. half_capot_home_value = [match_id, league_id, "ch_h", "0", 0, p_code, half_capot_home, '1',
  302. odds_only, sole, "hg3535", "0", ""]
  303. half_capot_homet_data = dict(zip(half_capot_home_key, half_capot_home_value))
  304. if odds_only not in uuid_list:
  305. data_list.append(half_capot_homet_data)
  306. # half_capot_guest
  307. hash_str = p_code + "cg_h" + '0' + '2' + str(half_capot_guest) + "hg3535" + str(match_id)
  308. sole_str = p_code + "cg_h" + '0' + str(match_id) + "hg3535"
  309. odds_only = Helper.genearte_MD5(hash_str)
  310. sole = Helper.genearte_MD5(sole_str)
  311. odds_onlys.append(odds_only)
  312. half_capot_guest_key = ["match_id", "lg_id", "odds_code", "status", "sort", "p_code", "odds", "condition",
  313. "odds_only", "sole", "source", "type", "team"]
  314. half_capot_guest_value = [match_id, league_id, "cg_h", "0", 0, p_code, half_capot_guest, '2',
  315. odds_only, sole, "hg3535", "0", ""]
  316. half_capot_guest_data = dict(zip(half_capot_guest_key, half_capot_guest_value))
  317. if odds_only not in uuid_list:
  318. data_list.append(half_capot_guest_data)
  319. # half_capot_dogfall
  320. hash_str = p_code + "cd_h" + '0' + 'X' + str(half_capot_dogfall) + "hg3535" + str(match_id)
  321. sole_str = p_code + "cd_h" + '0' + str(match_id) + "hg3535"
  322. odds_only = Helper.genearte_MD5(hash_str)
  323. sole = Helper.genearte_MD5(sole_str)
  324. odds_onlys.append(odds_only)
  325. half_capot_dogfall_key = ["match_id", "lg_id", "odds_code", "status", "sort", "p_code", "odds", "condition",
  326. "odds_only", "sole", "source", "type", "team"]
  327. half_capot_dogfall_value = [match_id, league_id, "cd_h", "0", 0, p_code, half_capot_dogfall, 'X',
  328. odds_only, sole, "hg3535", "0", ""]
  329. half_capot_dogfall_data = dict(zip(half_capot_dogfall_key, half_capot_dogfall_value))
  330. if odds_only not in uuid_list:
  331. data_list.append(half_capot_dogfall_data)
  332. # capot_dogfall
  333. hash_str = p_code + "cd" + '0' + 'X' + str(capot_dogfall) + "hg3535" + str(match_id)
  334. sole_str = p_code + "cd" + '0' + str(match_id) + "hg3535"
  335. odds_only = Helper.genearte_MD5(hash_str)
  336. sole = Helper.genearte_MD5(sole_str)
  337. odds_onlys.append(odds_only)
  338. capot_dogfall_key = ["match_id", "lg_id", "odds_code", "status", "sort", "p_code", "odds", "condition",
  339. "odds_only", "sole", "source", "type", "team"]
  340. capot_dogfall_value = [match_id, league_id, "cd", "0", 0, p_code, capot_dogfall, 'X', odds_only,
  341. sole, "hg3535", "0", ""]
  342. capot_dogfall_data = dict(zip(capot_dogfall_key, capot_dogfall_value))
  343. if odds_only not in uuid_list:
  344. data_list.append(capot_dogfall_data)
  345. # capot_home
  346. hash_str = p_code + "ch" + '0' + '1' + str(capot_home) + "hg3535" + str(match_id)
  347. sole_str = p_code + "ch" + '0' + str(match_id) + "hg3535"
  348. odds_only = Helper.genearte_MD5(hash_str)
  349. sole = Helper.genearte_MD5(sole_str)
  350. odds_onlys.append(odds_only)
  351. capot_home_key = ["match_id", "lg_id", "odds_code", "status", "sort", "p_code", "odds", "condition",
  352. "odds_only", "sole", "source", "type", "team"]
  353. capot_home_value = [match_id, league_id, "ch", "0", 0, p_code, capot_home, '1',
  354. odds_only, sole, "hg3535", "0", ""]
  355. capot_homet_data = dict(zip(capot_home_key, capot_home_value))
  356. if odds_only not in uuid_list:
  357. data_list.append(capot_homet_data)
  358. # capot_guest
  359. hash_str = p_code + "cg" + '0' + '2' + str(capot_guest) + "hg3535" + str(match_id)
  360. sole_str = p_code + "cg" + '0' + str(match_id) + "hg3535"
  361. odds_only = Helper.genearte_MD5(hash_str)
  362. sole = Helper.genearte_MD5(sole_str)
  363. odds_onlys.append(odds_only)
  364. capot_guest_key = ["match_id", "lg_id", "odds_code", "status", "sort", "p_code", "odds", "condition",
  365. "odds_only", "sole", "source", "type", "team"]
  366. capot_guest_value = [match_id, league_id, "cg", "0", 0, p_code, capot_home, '2',
  367. odds_only, sole, "hg3535", "0", ""]
  368. capot_guest_data = dict(zip(capot_guest_key, capot_guest_value))
  369. if odds_only not in uuid_list:
  370. data_list.append(capot_guest_data)
  371. # 入球数单双-----------------------------------------------------------------------------------------------------
  372. # p_code, p_id = get_pcode(corner_ball, 'two_sides')
  373. p_code = 'TS'
  374. odd_even_odd = item["odd_even_odd"]
  375. odd_even_even = item["odd_even_even"]
  376. half_odd_even_odd = item["half_odd_even_odd"]
  377. half_odd_even_even = item["half_odd_even_even"]
  378. # odd_even_odd
  379. hash_str = p_code + "tss" + '0' + '单' + str(odd_even_odd) + "hg3535" + str(match_id)
  380. sole_str = p_code + "tss" + '0' + str(match_id) + "hg3535"
  381. odds_only = Helper.genearte_MD5(hash_str)
  382. sole = Helper.genearte_MD5(sole_str)
  383. odds_onlys.append(odds_only)
  384. single_key = ["match_id", "lg_id", "odds_code", "status", "sort", "p_code", "odds", "condition",
  385. "odds_only", "sole", "source", "type", "team"]
  386. single_value = [match_id, league_id, "tss", "0", 0, p_code, odd_even_odd, '单',
  387. odds_only, sole, "hg3535", "0", ""]
  388. single_data = dict(zip(single_key, single_value))
  389. if odds_only not in uuid_list:
  390. data_list.append(single_data)
  391. # odd_even_even
  392. hash_str = p_code + "tsd" + '0' + '双' + str(odd_even_even) + "hg3535" + str(match_id)
  393. sole_str = p_code + "tss" + '0' + str(match_id) + "hg3535"
  394. odds_only = Helper.genearte_MD5(hash_str)
  395. sole = Helper.genearte_MD5(sole_str)
  396. odds_onlys.append(odds_only)
  397. double_key = ["match_id", "lg_id", "odds_code", "status", "sort", "p_code", "odds", "condition",
  398. "odds_only", "sole", "source", "type", "team"]
  399. double_value = [match_id, league_id, "tss", "0", 0, p_code, odd_even_even, '双',
  400. odds_only, sole, "hg3535", "0", ""]
  401. double_data = dict(zip(double_key, double_value))
  402. if odds_only not in uuid_list:
  403. data_list.append(double_data)
  404. # half_odd_even_even
  405. hash_str = p_code + "tsd_h" + '0' + '双' + str(half_odd_even_even) + "hg3535" + str(match_id)
  406. sole_str = p_code + "tsd_h" + '0' + str(match_id) + "hg3535"
  407. odds_only = Helper.genearte_MD5(hash_str)
  408. sole = Helper.genearte_MD5(sole_str)
  409. odds_onlys.append(odds_only)
  410. half_double_key = ["match_id", "lg_id", "odds_code", "status", "sort", "p_code", "odds", "condition",
  411. "odds_only", "sole", "source", "type", "team"]
  412. half_double_value = [match_id, league_id, "tsd_h", "0", 0, p_code, half_odd_even_even, '双',
  413. odds_only, sole, "hg3535", "0", ""]
  414. half_double_data = dict(zip(half_double_key, half_double_value))
  415. if odds_only not in uuid_list:
  416. data_list.append(half_double_data)
  417. # half_odd_even_odd
  418. hash_str = p_code + "tss_h" + '0' + '单' + str(half_odd_even_odd) + "hg3535" + str(match_id)
  419. sole_str = p_code + "tss_h" + '0' + str(match_id) + "hg3535"
  420. odds_only = Helper.genearte_MD5(hash_str)
  421. sole = Helper.genearte_MD5(sole_str)
  422. odds_onlys.append(odds_only)
  423. half_single_key = ["match_id", "lg_id", "odds_code", "status", "sort", "p_code", "odds", "condition",
  424. "odds_only", "sole", "source", "type", "team"]
  425. half_single_value = [match_id, league_id, "tss_h", "0", 0, p_code, half_odd_even_odd, '单', odds_only,
  426. sole, "hg3535", "0", ""]
  427. half_single_data = dict(zip(half_single_key, half_single_value))
  428. if odds_only not in uuid_list:
  429. data_list.append(half_single_data)
  430. # 总入球数 ------------------------------------------------------------------------------------------------------
  431. # p_code, p_id = get_pcode(corner_ball, 'total_goal')
  432. total_goals = item['total_goal']
  433. total_dict = {'tg0': '0-1', 'tg1': '2-3', 'tg2': '4-6','tg3': '7或以上', 'tg0_h': '0', "tg1_h": '1',
  434. "tg2_h": '2', "tg3_h": '3或以上'}
  435. # 全场入球数 单双
  436. # 上半场入球数 单双
  437. for key, value in total_goals.items():
  438. hash_str = p_code + key + '0' + total_dict[key] + str(value) + "hg3535" + str(match_id)
  439. sole_str = p_code + key + '0' + str(match_id) + "hg3535"
  440. odds_only = Helper.genearte_MD5(hash_str)
  441. sole = Helper.genearte_MD5(sole_str)
  442. odds_onlys.append(odds_only)
  443. total_goals_key = ["match_id", "lg_id", "odds_code", "status", "sort", "p_code", "odds", "condition",
  444. "odds_only", "sole", "source", "type", "team"]
  445. total_goals_value = [match_id, league_id, key, "0", 0, p_code, value, total_dict[key], odds_only,
  446. sole, "hg3535", "0", ""]
  447. total_goals_data = dict(zip(total_goals_key, total_goals_value))
  448. if odds_only not in uuid_list:
  449. data_list.append(total_goals_data)
  450. # 全场半场 ------------------------------------------------------------------------------------------------------
  451. half_fulls = item['half_full']
  452. # p_code, p_id = get_pcode(corner_ball, 'half_full')
  453. p_code = 'HF'
  454. full_dict = {"hfhh": "主主", "hfhd": "主和", "hfhg": "主客", "hfdh": "和主",
  455. "hfdd": "和和", "hfdg": "和客", "hfgh": "客主", "hfgd": "客和", "hfgg": "客客"}
  456. if half_fulls:
  457. for key, value in half_fulls.items():
  458. hash_str = p_code + key + '0' + full_dict[key] + str(value) + "hg3535" + str(match_id)
  459. sole_str = p_code + key + '0' + str(match_id) + "hg3535"
  460. odds_only = Helper.genearte_MD5(hash_str)
  461. sole = Helper.genearte_MD5(sole_str)
  462. odds_onlys.append(odds_only)
  463. half_fulls_key = ["match_id", "lg_id", "odds_code", "status", "sort", "p_code", "odds", "condition",
  464. "odds_only", "sole", "source", "type", "team"]
  465. half_fulls_value = [match_id, league_id, key, "0", 0, p_code, value, full_dict[key], odds_only,
  466. sole, "hg3535", "0", ""]
  467. half_fulls_data = dict(zip(half_fulls_key, half_fulls_value))
  468. if odds_only not in uuid_list:
  469. data_list.append(half_fulls_data)
  470. # 波胆------------------------------------------------------------------------------------------------------------------
  471. bodan_datas = item['bodan_data']
  472. p_code, p_id = get_pcode(corner_ball, 'bodan')
  473. bodan_dict = {"b10": "1-0", "b20": "2-0", "b21": "2-1", "b30": "3-0", "b31": "3-1", "b32": "3-2",
  474. "b40": "4-0", "b41": "4-1", "b42": "4-2", "b43": "4-3", "b01": "0-1", "b02": "0-2",
  475. "b12": "1-2", "b03": "0-3", "b13": "1-3", "b23": "2-3", "b04": "0-4", "b14": "1-4",
  476. "b24": "2-4", "b34": "3-4", "b00": "0-0", "b11": "1-1", "b22": "2-2", "b33": "3-3",
  477. "b44": "4-4", "bo": "其他", "b10_h": "1-0", "b20_h": "2-0", "b21_h": "2-1", "b30_h": "3-0",
  478. "b31_h": "3-1", "b32_h": "3-2", "b01_h": "0-1", "b02_h": "0-2", "b12_h": "1-2", "b03_h": "0-3",
  479. "b13_h": "1-3", "b23_h": "2-3", "b00_h": "0-0", "b11_h": "1-1", "b22_h": "2-2", "b33_h": "3-3",
  480. "bo_h": "其他"}
  481. if bodan_datas:
  482. for key, value in bodan_datas.items():
  483. hash_str = p_code + key + '0' + bodan_dict[key] + str(value) + "hg3535" + str(match_id)
  484. sole_str = p_code + key + '0' + str(match_id) + "hg3535"
  485. odds_only = Helper.genearte_MD5(hash_str)
  486. sole = Helper.genearte_MD5(sole_str)
  487. odds_onlys.append(odds_only)
  488. bodan_dict_key = ["match_id", "lg_id", "odds_code", "status", "sort", "p_code", "odds", "condition",
  489. "odds_only", "sole", "source", "type", "team"]
  490. bodan_dict_value = [match_id, league_id, key, "0", 0, p_code, value, bodan_dict[key], odds_only,
  491. sole, "hg3535", "0", ""]
  492. bodan_dict_data = dict(zip(bodan_dict_key, bodan_dict_value))
  493. if odds_only not in uuid_list:
  494. data_list.append(bodan_dict_data)
  495. # 最先进球/最后进球 ----------------------------------------------------------------------------------------------
  496. first_last_balls = item['first_last_ball']
  497. # p_code, p_id = get_pcode(corner_ball, 'first_last_ball')
  498. p_code = 'FLB'
  499. first_last_dict = {"flbfh": "最先进球", "flbfg": "最先进球", "flblh": "最后进球", "flblg": "最后进球", "flbn": "没有进球"}
  500. if first_last_balls:
  501. for key, value in first_last_balls.items():
  502. hash_str = p_code + key + '0' + first_last_dict[key] + str(value) + "hg3535" + str(match_id)
  503. sole_str = p_code + key + '0' + str(match_id) + "hg3535"
  504. odds_only = Helper.genearte_MD5(hash_str)
  505. sole = Helper.genearte_MD5(sole_str)
  506. odds_onlys.append(odds_only)
  507. first_last_balls_key = ["match_id", "lg_id", "odds_code", "status", "sort", "p_code", "odds",
  508. "condition",
  509. "odds_only", "sole", "source", "type", "team"]
  510. first_last_balls_value = [match_id, league_id, key, "0", 0, p_code, value, first_last_dict[key],
  511. odds_only,
  512. sole, "hg3535", "0", ""]
  513. first_last_balls_data = dict(zip(first_last_balls_key, first_last_balls_value))
  514. if odds_only not in uuid_list:
  515. data_list.append(first_last_balls_data)
  516. # p_code, p_id = get_pcode(corner_ball, 'tema_ball')
  517. p_code = 'TB'
  518. # 球队得分全场,上半场
  519. full_dicts = item['full_data']
  520. half_dicts = item['half_data']
  521. full_dict_rules = item['full_data_rule']
  522. half_dict_rules = item['half_data_rule']
  523. if full_dicts:
  524. for key, value in full_dicts.items():
  525. hash_str = p_code + key + '0' + full_dict_rules[key] + str(value) + "hg3535" + str(match_id)
  526. sole_str = p_code + key + '0' + str(match_id) + "hg3535"
  527. odds_only = Helper.genearte_MD5(hash_str)
  528. sole = Helper.genearte_MD5(sole_str)
  529. odds_onlys.append(odds_only)
  530. full_dict_rules_key = ["match_id", "lg_id", "odds_code", "status", "sort", "p_code", "odds",
  531. "condition", "odds_only", "sole", "source", "type", "team"]
  532. full_dict_rules_value = [match_id, league_id, key, "0", 0, p_code, value, full_dict_rules[key],
  533. odds_only, sole, "hg3535", "0", ""]
  534. full_dict_rules_data = dict(zip(full_dict_rules_key, full_dict_rules_value))
  535. if odds_only not in uuid_list:
  536. data_list.append(full_dict_rules_data)
  537. if half_dicts:
  538. for key, value in half_dicts.items():
  539. hash_str = p_code + key + '0' + half_dict_rules[key] + str(value) + "hg3535" + str(match_id)
  540. sole_str = p_code + key + '0' + str(match_id) + "hg3535"
  541. odds_only = Helper.genearte_MD5(hash_str)
  542. sole = Helper.genearte_MD5(sole_str)
  543. odds_onlys.append(odds_only)
  544. half_dicts_key = ["match_id", "lg_id", "odds_code", "status", "sort", "p_code", "odds",
  545. "condition", "odds_only", "sole", "source", "type", "team"]
  546. half_dicts_value = [match_id, league_id, key, "0", 0, p_code, value, half_dict_rules[key],
  547. odds_only, sole, "hg3535", "0", ""]
  548. half_dicts_data = dict(zip(half_dicts_key, half_dicts_value))
  549. if odds_only not in uuid_list:
  550. data_list.append(half_dicts_data)
  551. odds_key = ["game_code", "title", "match_id", "lg_id", "data", "source", "odds_only", "tag", "uuid",
  552. "is_stringscene", "utime", "pt"]
  553. odds_value = ["zq", "odds", match_id, league_id, data_list, "hg3535", odds_onlys, number, uuid,
  554. 0, utime, pt]
  555. odds_dict = dict(zip(odds_key, odds_value))
  556. if data_list:
  557. # print(odds_dict)
  558. response_data = Helper.async_post(url + '/setOdds', odds_dict)
  559. # print(response_data)
  560. print('足球赔率请求成功', response_data)
  561. if "成功" in response_data:
  562. if result:
  563. self.db.hg3535_zq_odds.update({'match_id': match_id, 'pt': pt}, {
  564. '$set': {"data": data_list, "odds_only": odds_onlys, "utime": utime}}, upsert=True)
  565. else:
  566. self.db.hg3535_zq_odds.insert(odds_dict)
  567. data_list = []
  568. zq_rball = {"home_team": team_home, "guest_team": team_guest,
  569. "lg_id": league_id, "home_rate": 0,
  570. "guest_rate": 0, "home_score": score_home,
  571. "guest_score": score_guest, "all_goal": all_goal, "status": 1,
  572. "first_score": "", "last_score": "", "match_score": match_score, "uuid": uuid,
  573. "match_winer": "", "match_time": time_game,
  574. "match_process": half_way, "tag": number,
  575. "match_id": match_id, "p_code": ""}
  576. data_list.append(zq_rball)
  577. r_data_dict = {
  578. "game_code": "zq",
  579. "title": "match_result_r",
  580. "source": "hg3535",
  581. "data": data_list
  582. }
  583. if data_list:
  584. try:
  585. response_data = Helper.async_post(url + '/setMatchResult', r_data_dict)
  586. print(r_data_dict)
  587. print("滚球赛事结果post提交", response_data)
  588. except Exception as e:
  589. logger.warning('滚球数据接口异常,提交失败')
  590. logger.warning(e)