roll_zuqiu.py 23 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449
  1. # -*- coding: utf-8 -*-
  2. # import copy
  3. import datetime
  4. import json
  5. # import jsonpath
  6. import redis
  7. import scrapy
  8. from scrapy.http import Request
  9. from ..items import Roll_Zuqiu
  10. class ZuqiuSpider(scrapy.Spider):
  11. name = 'roll_zuqiu'
  12. to_day = datetime.datetime.now()
  13. allowed_domains = ['hg3535z.com']
  14. custom_settings = {
  15. "ITEM_PIPELINES":{
  16. 'hg3535.pipeline.roll_zuqiu.Roll_Zuqiupipeline': 200,
  17. },
  18. # 'LOG_LEVEL': 'DEBUG',
  19. # 'LOG_FILE': "../hg3535/log/roll_zuqiu_{}_{}_{}.log".format(to_day.year, to_day.month,to_day.day)
  20. }
  21. start_urls = ['https://odata.jiushan6688.com/odds6i/d/getodds/zh-cn/sid/1/pt/4/ubt/am/pn/0/sb/2/dc/null/pid/0']
  22. rls = redis.Redis(host='192.168.2.200', port=6379, db=1, password=123456)
  23. def parse(self, response):
  24. responses = json.loads(response.text)
  25. try:
  26. datas = responses["i-ot"]
  27. except:
  28. print("暂无滚球篮球数据")
  29. return
  30. if datas:
  31. for data in datas:
  32. egs = data.get('egs')
  33. if egs:
  34. for es in egs:
  35. es = es['es']
  36. for e in es:
  37. match_id = str(e['i'][16])
  38. self.rls.sadd('hg3535.gunqiu.ids', match_id)
  39. url = 'https://odata.jiushan6688.com/odds6i/d/getamodds/zh-cn/eid/{}/iip/true/ubt/am/isp/false'.format(match_id)
  40. yield Request(url=url, callback=self.parse_each, dont_filter=True)
  41. self.rls.close()
  42. else:
  43. print('足球滚球数据为空')
  44. else:
  45. print("暂无滚球足球数据")
  46. return
  47. def parse_each(self, response):
  48. # 球队进球数 大小
  49. try:
  50. datas = json.loads(response.text)['eg']['es']
  51. league_id = json.loads(response.text)['eg']['c']['k']
  52. # 联赛名
  53. league_name = json.loads(response.text)['eg']['c']['n']
  54. except:
  55. datas = ""
  56. league_id = ""
  57. # 联赛名
  58. league_name = ""
  59. if datas:
  60. item = Roll_Zuqiu()
  61. full_dict = {}
  62. half_dict = {}
  63. full_dict_rule = {}
  64. half_dict_rule = {}
  65. for data in datas:
  66. try:
  67. new_data = data['pci']['ctid']
  68. except:
  69. new_data = ""
  70. if new_data == 0:
  71. # 比赛id
  72. game_id = str(data['k'])
  73. # 球队1
  74. team_home = data['i'][0]
  75. # 球队2
  76. team_guest = data['i'][1]
  77. # 数量(97>)
  78. number = data['i'][2]
  79. # 下半场
  80. half_way = data['i'][12]
  81. # 角球或者其他
  82. corner_ball = data['pci'].get('ctn', "")
  83. # 日期
  84. data_game = data['i'][4]
  85. # 开赛时间
  86. time_game = data['i'][5]
  87. #这个地方的值不准确 需要再次确认
  88. score_home = data['i'][10] # 队一分数
  89. score_guest = data['i'][11] # 队二分数
  90. # half_way = new_result['i'][12] #下半场
  91. # 让球------------------------------------------------------------------------------------------------------------------
  92. try:
  93. concedes = data['o']['ah']['v']
  94. new_concedes = [concedes[i] for i in range(len(concedes)) if i % 2 == 1]
  95. concede_homes = [new_concedes[i] for i in range(len(new_concedes)) if i % 2 == 0]
  96. concede_home_rule = [concede_homes[i] for i in range(len(concede_homes)) if i % 2 == 0]
  97. concede_home = [concede_homes[i] for i in range(len(concede_homes)) if i % 2 is 1]
  98. concede_guests = [new_concedes[i] for i in range(len(new_concedes)) if i % 2 is 1]
  99. # concede_guest_rule
  100. # concede_guest
  101. concede_guest_rule = [concede_guests[i] for i in range(len(concede_guests)) if i % 2 == 0]
  102. concede_guest = [concede_guests[i] for i in range(len(concede_guests)) if i % 2 is 1]
  103. except:
  104. concede_guest = ""
  105. concede_guest_rule = ""
  106. concede_home = ""
  107. concede_home_rule = ""
  108. # 上半场让球half_concede-------------------------------------------------------------------------------------------------
  109. try:
  110. half_concedes = data['o']['ah1st']['v']
  111. new_half_concedes = [half_concedes[i] for i in range(len(half_concedes)) if i % 2 is 1]
  112. new_half_concede_homes = [new_half_concedes[i] for i in range(len(new_half_concedes)) if
  113. i % 2 is 0]
  114. half_concede_guest_rule = [new_half_concede_homes[i] for i in range(len(new_half_concede_homes)) if i % 2 == 0]
  115. # concede_home
  116. half_concede_home = [new_half_concede_homes[i] for i in range(len(new_half_concede_homes)) if i % 2 is 1]
  117. half_concede_guests = [new_half_concedes[i] for i in range(len(new_half_concedes)) if i % 2 is 1]
  118. half_concede_home_rule = [half_concede_guests[i] for i in range(len(half_concede_guests)) if i % 2 == 0]
  119. # concede_guest
  120. half_concede_guest = [half_concede_guests[i] for i in range(len(half_concede_guests)) if
  121. i % 2 is 1]
  122. except:
  123. half_concede_home_rule = ""
  124. half_concede_home = ""
  125. half_concede_guest_rule = ""
  126. half_concede_guest = ""
  127. # 全场大小size 进球大小---------------------------------------------------------------------------------------------------
  128. try:
  129. sizes = data['o']['ou']['v']
  130. new_sizes = [sizes[i] for i in range(len(sizes)) if i % 2 is 1]
  131. size_homes = [new_sizes[i] for i in range(len(new_sizes)) if i % 2 is 0]
  132. # size_home_rule
  133. size_home_rule = [size_homes[i] for i in range(len(size_homes)) if i % 2 is 0]
  134. # size_home
  135. size_home = [size_homes[i] for i in range(len(size_homes)) if i % 2 is 1]
  136. size_guests = [new_sizes[i] for i in range(len(new_sizes)) if i % 2 is 1]
  137. # size_guest_rule
  138. size_guest_rule = [size_guests[i] for i in range(len(size_guests)) if i % 2 is 0]
  139. # csize_guest
  140. size_guest = [size_guests[i] for i in range(len(size_guests)) if i % 2 is 1]
  141. except:
  142. size_guest = ""
  143. size_guest_rule = ""
  144. size_home = ""
  145. size_home_rule = ""
  146. # 上半场大小 进球大小 half_size-------------------------------------------------------------------------------------------
  147. try:
  148. half_sizes = data['o']['ou1st']['v']
  149. new_half_sizes = [half_sizes[i] for i in range(len(half_sizes)) if i % 2 is 1]
  150. half_size_homes = [new_half_sizes[i] for i in range(len(new_half_sizes)) if i % 2 is 0]
  151. # size_home_rule
  152. half_size_home_rule = [half_size_homes[i] for i in range(len(half_size_homes)) if i % 2 is 0]
  153. # half_size_home 主队
  154. half_size_home = [half_size_homes[i] for i in range(len(half_size_homes)) if i % 2 is 1]
  155. half_size_guests = [new_half_sizes[i] for i in range(len(new_half_sizes)) if i % 2 is 1]
  156. # half_size_guest_rule 客队
  157. half_size_guest_rule = [half_size_guests[i] for i in range(len(half_size_guests)) if i % 2 is 0]
  158. # half_size_guest
  159. half_size_guest = [half_size_guests[i] for i in range(len(half_size_guests)) if
  160. i % 2 is 1]
  161. except:
  162. half_size_guest = ""
  163. half_size_guest_rule = ""
  164. half_size_home = ""
  165. half_size_home_rule = ""
  166. # 全场总进球 total_goal--------------------------------------------------------------------------------------------------
  167. total_goal = {}
  168. try:
  169. total_goals = data['o']['tg']['v']
  170. new_total_goals = [total_goals[i] for i in range(len(total_goals)) if i % 2 is 1]
  171. total_goal["tg0"] = round(float(new_total_goals[0]) - 1, 2)
  172. total_goal["tg1"] = round(float(new_total_goals[1]) - 1, 2)
  173. total_goal["tg2"] = round(float(new_total_goals[2]) - 1, 2)
  174. total_goal["tg3"] = round(float(new_total_goals[3]) - 1, 2)
  175. except:
  176. total_goal["tg0"] = ""
  177. total_goal["tg1"] = ""
  178. total_goal["tg2"] = ""
  179. total_goal["tg3"] = ""
  180. # 总进球上半场 half_total_goal-------------------------------------------------------------------------------------------
  181. try:
  182. half_total_goals = data['o']['tg1st']['v']
  183. new_half_total_goals = [half_total_goals[i] for i in range(len(half_total_goals)) if i % 2 is 1]
  184. total_goal["tg0_h"] = round(float(new_half_total_goals[0]) - 1, 2)
  185. total_goal["tg1_h"] = round(float(new_half_total_goals[1]) - 1, 2)
  186. total_goal["tg2_h"] = round(float(new_half_total_goals[2]) - 1, 2)
  187. total_goal["tg3_h"] = round(float(new_half_total_goals[3]) - 1, 2)
  188. except:
  189. total_goal["tg0_h"] = ""
  190. total_goal["tg1_h"] = ""
  191. total_goal["tg2_h"] = ""
  192. total_goal["tg3_h"] = ""
  193. # 早盘 半场/全场---------------------------------------------------------------------------------------------------------
  194. half_full = {}
  195. new_lists = ["hfhh", "hfhd", "hfhg", "hfdh", "hfdd", "hfdg", "hfgh", "hfgd", "hfgg"]
  196. # 早盘 半场/全场
  197. try:
  198. half_fulls = data['o']['hf']['v']
  199. new_half_fulls = [half_fulls[i] for i in range(len(half_fulls)) if i % 2 is 1]
  200. for index, value in enumerate(new_lists):
  201. half_full[value] = round(float(new_half_fulls[index]) - 1, 2)
  202. except:
  203. for index, value in enumerate(new_lists):
  204. half_full[value] = ""
  205. # 早盘 最先/最后进球 最先进球 ---------------------------------------------------------------------------------------------
  206. first_last_ball = {}
  207. try:
  208. first_balls = data['o']['ttslast']['v']
  209. first_ball = [first_balls[i] for i in range(len(first_balls)) if i % 2 is 1]
  210. first_last_ball['flbfh'] = round(float(first_ball[0]) - 1, 2)
  211. first_last_ball['flbfg'] = round(float(first_ball[1]) - 1, 2)
  212. except:
  213. pass
  214. # 早盘 最先/最后进球 最后进球
  215. try:
  216. last_balls = data['o']['tts1st']['v']
  217. last_ball = [last_balls[i] for i in range(len(last_balls)) if i % 2 is 1]
  218. first_last_ball['flblh'] = round(float(last_ball[0]) - 1, 2)
  219. first_last_ball['flblg'] = round(float(last_ball[1]) - 1, 2)
  220. first_last_ball['flbn'] = round(float(last_ball[2]) - 1, 2)
  221. except:
  222. pass
  223. # 全场独赢capot ---------------------------------------------------------------------------------------------------------
  224. try:
  225. capots = data['o']['1x2']['v']
  226. new_capots = [capots[i] for i in range(len(capots)) if i % 2 is 1]
  227. capot_home = round(float(new_capots[0]) - 1, 2)
  228. capot_guest = round(float(new_capots[1]) - 1, 2)
  229. capot_dogfall = round(float(new_capots[2]) - 1, 2)
  230. except:
  231. capot_home = ""
  232. capot_guest = ""
  233. capot_dogfall = ""
  234. # 上半场独赢capot
  235. try:
  236. half_capots = data['o']['1x21st']['v']
  237. new_half_capots = [half_capots[i] for i in range(len(half_capots)) if i % 2 is 1]
  238. half_capot_home = round(float(new_half_capots[0]) - 1, 2)
  239. half_capot_guest = round(float(new_half_capots[1]) - 1, 2)
  240. half_capot_dogfall = round(float(new_half_capots[2]) - 1, 2)
  241. except:
  242. half_capot_home = ""
  243. half_capot_guest = ""
  244. half_capot_dogfall = ""
  245. # 全场入球:单/双 odd_even------------------------------------------------------------------------------------------------
  246. try:
  247. odd_evens = data['o']['oe']['v']
  248. new_odd_evens = [odd_evens[i] for i in range(len(odd_evens)) if i % 2 is 1]
  249. odd_even_odd = new_odd_evens[0]
  250. odd_even_even = new_odd_evens[1]
  251. except:
  252. odd_even_odd = ""
  253. odd_even_even = ""
  254. # 半场入球:单/双 half_odd_even
  255. try:
  256. half_odd_evens = data['o']['oe1st']['v']
  257. new_half_odd_evens = [half_odd_evens[i] for i in range(len(half_odd_evens)) if i % 2 is 1]
  258. half_odd_even_odd = new_half_odd_evens[0]
  259. half_odd_even_even = new_half_odd_evens[1]
  260. except:
  261. half_odd_even_odd = ""
  262. half_odd_even_even = ""
  263. bodan_data = {}
  264. # 波胆------------------------------------------------------------------------------------------------------------------
  265. try:
  266. bodans = data['o']['cs']['v']
  267. one_list = ["b10", "b20", "b21", "b30", "b31", "b32", "b40", "b41", "b42", "b43"]
  268. two_list = ["b01", "b02", "b12", "b03", "b13", "b23", "b04", "b14", "b24", "b34"]
  269. three_list = ["b00", "b11", "b22", "b33", "b44"]
  270. new_bodans = [bodans[i] for i in range(len(bodans)) if i % 2 is 1]
  271. new_bodan = new_bodans[0:20]
  272. # 主队bodan_home
  273. bodan_home = [new_bodan[i] for i in range(len(new_bodan)) if i % 2 is 0]
  274. for index, t in enumerate(one_list):
  275. bodan_data[t] = round(float(bodan_home[index]) - 1, 2)
  276. # 客队bodan_guest
  277. bodan_guest = [new_bodan[i] for i in range(len(new_bodan)) if i % 2 is 1]
  278. for y, z in enumerate(two_list):
  279. bodan_data[z] = round(float(bodan_guest[y]) - 1, 2)
  280. bodan_dogfall = new_bodans[-7:-2]
  281. for a, b in enumerate(three_list):
  282. bodan_data[b] = round(float(bodan_dogfall[a]) - 1, 2)
  283. # 其他bodan_other
  284. bodan_data['bo'] = round(float(new_bodans[-1]) - 1, 2)
  285. except:
  286. pass
  287. try:
  288. half_bodans = data['o']['cs1st']['v']
  289. new_half_bodans = [half_bodans[i] for i in range(len(half_bodans)) if i % 2 is 1]
  290. new_one = ["b10_h", "b20_h", "b21_h", "b30_h", "b31_h", "b32_h"]
  291. new_two = ["b01_h", "b02_h", "b12_h", "b03_h", "b13_h", "b23_h"]
  292. new_three = ["b00_h", "b11_h", "b22_h", "b33_h"]
  293. halfbodan = new_half_bodans[0:12]
  294. half_bodan_home = [halfbodan[i] for i in range(len(halfbodan)) if i % 2 is 0]
  295. # 队1
  296. for index, t in enumerate(new_one):
  297. bodan_data[t] = round(float(half_bodan_home[index]) - 1, 2)
  298. # 队2
  299. half_bodan_guest = [halfbodan[i] for i in range(len(halfbodan)) if i % 2 is 1]
  300. for y, z in enumerate(new_two):
  301. bodan_data[z] = round(float(half_bodan_guest[y]) - 1, 2)
  302. # 和/平
  303. half_bodan_dogfall = new_half_bodans[-6:-2]
  304. for a, b in enumerate(new_three):
  305. bodan_data[b] = round(float(half_bodan_dogfall[a]) - 1, 2)
  306. # 其他
  307. bodan_data['bo_h'] = round(float(new_half_bodans[-1]) - 1, 2)
  308. except:
  309. pass
  310. if new_data == 12:
  311. try:
  312. home_data = data['o']['ou']['v']
  313. # 球队进球 大条件
  314. full_dict_rule['tbhb'] = home_data[1]
  315. # 球队进球小条件
  316. full_dict_rule['tbhs'] = home_data[3]
  317. # 球队进球大赔率
  318. full_dict['tbhb'] = home_data[5]
  319. # 球队进球小赔率
  320. full_dict['tbhs'] = home_data[7]
  321. except:
  322. full_dict['tbhs'] = ""
  323. full_dict_rule['tbhs'] = ""
  324. full_dict['tbhb'] = ""
  325. full_dict_rule['tbhb'] = ""
  326. try:
  327. half_home_data = data['o']['ou1st']['v']
  328. half_dict_rule['tbhb_h'] = half_home_data[1]
  329. half_dict_rule['tbhs_h'] = half_home_data[3]
  330. half_dict['tbhb_h'] = half_home_data[5]
  331. half_dict['tbhs_h'] = half_home_data[7]
  332. except:
  333. half_dict_rule['tbhb_h'] = ""
  334. half_dict['tbhb_h'] = ""
  335. half_dict_rule['tbhs_h'] = ""
  336. half_dict['tbhs_h'] = ""
  337. if new_data == 13:
  338. try:
  339. guest_data = data['o']['ou']['v']
  340. full_dict_rule['tbgb'] = guest_data[1]
  341. full_dict_rule['tbgs'] = guest_data[3]
  342. full_dict['tbgb'] = guest_data[5]
  343. full_dict['tbgs'] = guest_data[7]
  344. except:
  345. full_dict_rule['tbgb'] = ""
  346. full_dict['tbgb'] = ""
  347. full_dict_rule['tbgs'] = ""
  348. full_dict['tbgs'] = ''
  349. try:
  350. half_guest_data = data['o']['ou1st']['v']
  351. half_dict_rule['tbgb_h'] = half_guest_data[1]
  352. half_dict_rule['tbgs_h'] = half_guest_data[3]
  353. half_dict['tbgb_h'] = half_guest_data[5]
  354. half_dict['tbgs_h'] = half_guest_data[7]
  355. except:
  356. half_dict_rule['tbgb_h'] = ""
  357. half_dict['tbgb_h'] = ""
  358. half_dict_rule['tbgs_h'] = ""
  359. half_dict['tbgs_h'] = ""
  360. item['league_id'] = league_id
  361. item['league_name'] = league_name
  362. item['game_id'] = game_id
  363. item['team_home'] = team_home
  364. item['team_guest'] = team_guest
  365. item['number'] = number
  366. item['data_game'] = data_game
  367. item['time_game'] = time_game
  368. item['corner_ball'] = corner_ball
  369. # 波胆
  370. item['bodan_data'] = bodan_data
  371. # 早盘入球数单双
  372. item["odd_even_odd"] = odd_even_odd
  373. item["odd_even_even"] = odd_even_even
  374. item["half_odd_even_odd"] = half_odd_even_odd
  375. item["half_odd_even_even"] = half_odd_even_even
  376. item['total_goal'] = total_goal
  377. item["half_capot_home"] = half_capot_home
  378. item["half_capot_guest"] = half_capot_guest
  379. item["half_capot_dogfall"] = half_capot_dogfall
  380. item["capot_home"] = capot_home
  381. item["capot_guest"] = capot_guest
  382. item["capot_dogfall"] = capot_dogfall
  383. item["first_last_ball"] = first_last_ball
  384. item["half_full"] = half_full
  385. item["half_size_guest"] = half_size_guest
  386. item["half_size_guest_rule"] = half_size_guest_rule
  387. item["half_size_home"] = half_size_home
  388. item["half_size_home_rule"] = half_size_home_rule
  389. # 全场大小
  390. item["size_guest"] = size_guest
  391. item["size_guest_rule"] = size_guest_rule
  392. item["size_home"] = size_home
  393. item["size_home_rule"] = size_home_rule
  394. # 上半场让球
  395. item["half_concede_home_rule"] = half_concede_home_rule
  396. item["half_concede_home"] = half_concede_home
  397. item["half_concede_guest_rule"] = half_concede_guest_rule
  398. item["half_concede_guest"] = half_concede_guest
  399. # 全场让球
  400. item["concede_guest"] = concede_guest
  401. item["concede_guest_rule"] = concede_guest_rule
  402. item["concede_home"] = concede_home
  403. item["concede_home_rule"] = concede_home_rule
  404. item['score_home'] = score_home
  405. item['score_guest'] = score_guest
  406. item['full_data'] = full_dict
  407. item['half_data'] = half_dict
  408. item['full_data_rule'] = full_dict_rule
  409. item['half_data_rule'] = half_dict_rule
  410. item['half_way'] = half_way
  411. yield item