pipelines.py 83 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702
  1. import json
  2. import time
  3. import logging
  4. import requests
  5. from .ball_func import get_pcode, new_time, out_time, hash_func, fuhao, one_post, \
  6. two_post, three_post, gs_post, go_post, guanl_post, liansai, new_times
  7. # 足球 赔率 赛事---------------------------------------------------------------------------------------------------------
  8. class Zuqiupipeline(object):
  9. def process_item(self, item, spider):
  10. # 使用twisted将mysql插入变成异步执行
  11. # print(item)
  12. zq_odds = []
  13. url = 'http://admin.5gogo.com/setSports'
  14. # zq_competitions = []
  15. logger = logging.getLogger(__name__)
  16. # logger.warning(query.addErrback(self.handle_error, item, spider))
  17. # 比赛日期
  18. try:
  19. data_game = item['data_game'].split("/")
  20. # print(data_game)
  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',
  28. 'Aug': '08', 'Sep': '09', 'Oct': '10', 'Nov': '11', 'Dec': '12'}
  29. month = month_dict[months]
  30. day = str(data_game[0])
  31. # 比赛时间
  32. time_game = str(item['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. competition_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. pt = item['pt']
  52. corner_ball = item['corner_ball']
  53. p_code, p_id = get_pcode(corner_ball, 'goal_size')
  54. # 构建唯一索引
  55. half_size_guest = item["half_size_guest"]
  56. half_size_guest_rule = item["half_size_guest_rule"]
  57. half_size_home = item["half_size_home"]
  58. half_size_home_rule = item["half_size_home_rule"]
  59. zuqiu = item['zuqiu']
  60. two_post(data=half_size_home, match_id=competition_id, odds_code='half_goal_size_big', p_id=p_id, league_id=league_id, p_code=p_code, condition=half_size_home_rule, game_code='zq', zq_odds=zq_odds)
  61. # print(a)
  62. two_post(data=half_size_guest, match_id=competition_id, odds_code='half_goal_size_small', p_id=p_id,
  63. league_id=league_id, p_code=p_code, condition=half_size_guest_rule, game_code='zq', zq_odds=zq_odds)
  64. # 全场场大小
  65. size_guest = item["size_guest"]
  66. size_guest_rule = item["size_guest_rule"]
  67. size_home = item["size_home"]
  68. size_home_rule = item["size_home_rule"]
  69. two_post(data=size_guest, match_id=competition_id, odds_code='goal_size_small', p_id=p_id,
  70. league_id=league_id, p_code=p_code, condition=size_guest_rule, game_code='zq', zq_odds=zq_odds)
  71. two_post(data=size_home, match_id=competition_id, odds_code='goal_size_big', p_id=p_id,
  72. league_id=league_id, p_code=p_code, condition=size_home_rule, game_code='zq', zq_odds=zq_odds)
  73. p_code, p_id = get_pcode(corner_ball, 'concede')
  74. # 上半场大小
  75. half_concede_home_rule = item["half_concede_home_rule"]
  76. half_concede_home = item["half_concede_home"]
  77. half_concede_guest_rule = item["half_concede_guest_rule"]
  78. half_concede_guest = item["half_concede_guest"]
  79. # 上半场让球
  80. two_post(data=half_concede_home, match_id=competition_id, odds_code='half_concede_home', p_id=p_id,
  81. league_id=league_id, p_code=p_code, condition=half_concede_home_rule, game_code='zq', zq_odds=zq_odds)
  82. two_post(data=half_concede_guest, match_id=competition_id, odds_code='half_concede_guest', p_id=p_id,
  83. league_id=league_id, p_code=p_code, condition=half_concede_guest_rule, game_code='zq', zq_odds=zq_odds)
  84. concede_guest = item["concede_guest"]
  85. concede_guest_rule = item["concede_guest_rule"]
  86. concede_home = item["concede_home"]
  87. concede_home_rule = item["concede_home_rule"]
  88. # 全场让球
  89. two_post(data=concede_guest, match_id=competition_id, odds_code='concede_guest', p_id=p_id,
  90. league_id=league_id, p_code=p_code, condition=concede_guest_rule, game_code='zq', zq_odds=zq_odds)
  91. two_post(data=concede_home, match_id=competition_id, odds_code='concede_home', p_id=p_id,
  92. league_id=league_id, p_code=p_code, condition=concede_home_rule, game_code='zq', zq_odds=zq_odds)
  93. # 独赢-------------------------------------------------------------------------------------------------------------------
  94. p_code, p_id = get_pcode(corner_ball, 'capot')
  95. half_capot_home = item["half_capot_home"]
  96. half_capot_guest = item["half_capot_guest"]
  97. half_capot_dogfall = item["half_capot_dogfall"]
  98. capot_home = item["capot_home"]
  99. capot_guest = item["capot_guest"]
  100. capot_dogfall = item["capot_dogfall"]
  101. # 上半场独赢 主队
  102. one_post(data=half_capot_home, match_id=competition_id, odds_code='half_capot_home', p_id=p_id,
  103. league_id=league_id, p_code=p_code, condition=1, game_code='zq', zq_odds=zq_odds)
  104. # 上半场独赢 客队
  105. one_post(data=half_capot_guest, match_id=competition_id, odds_code='half_capot_guest', p_id=p_id,
  106. league_id=league_id, p_code=p_code, condition=2, game_code='zq', zq_odds=zq_odds)
  107. # 上半场独赢 和
  108. one_post(data=half_capot_dogfall, match_id=competition_id, odds_code='half_capot_dogfall', p_id=p_id,
  109. league_id=league_id, p_code=p_code, condition='X', game_code='zq', zq_odds=zq_odds)
  110. # 全场独赢 主队
  111. one_post(data=capot_home, match_id=competition_id, odds_code='capot_home', p_id=p_id,
  112. league_id=league_id, p_code=p_code, condition=1, game_code='zq', zq_odds=zq_odds)
  113. # 全场独赢 客队
  114. one_post(data=capot_guest, match_id=competition_id, odds_code='capot_guest', p_id=p_id,
  115. league_id=league_id, p_code=p_code, condition=2, game_code='zq', zq_odds=zq_odds)
  116. # 全场独赢 和
  117. one_post(data=capot_dogfall, match_id=competition_id, odds_code='capot_dogfall', p_id=p_id,
  118. league_id=league_id, p_code=p_code, condition='X', game_code='zq', zq_odds=zq_odds)
  119. # 入球数单双-------------------------------------------------------------------------------------------------------------
  120. p_code, p_id = get_pcode(corner_ball, 'two_sides')
  121. odd_even_odd = item["odd_even_odd"]
  122. odd_even_even = item["odd_even_even"]
  123. half_odd_even_odd = item["half_odd_even_odd"]
  124. half_odd_even_even = item["half_odd_even_even"]
  125. # 全场入球数 单双
  126. # 上半场入球数 单双
  127. one_post(data=odd_even_odd, match_id=competition_id, odds_code='two_sides_single', p_id=p_id, league_id=league_id, p_code=p_code, condition='单', game_code='zq', zq_odds=zq_odds)
  128. one_post(data=odd_even_even, match_id=competition_id, odds_code='two_sides_double', p_id=p_id,
  129. league_id=league_id, p_code=p_code, condition='双', game_code='zq', zq_odds=zq_odds)
  130. # 全场入球数 单双
  131. one_post(data=half_odd_even_odd, match_id=competition_id, odds_code='half_two_sides_single', p_id=p_id,
  132. league_id=league_id, p_code=p_code, condition='单', game_code='zq', zq_odds=zq_odds)
  133. one_post(data=half_odd_even_even, match_id=competition_id, odds_code='half_two_sides_double', p_id=p_id,
  134. league_id=league_id, p_code=p_code, condition='双', game_code='zq', zq_odds=zq_odds)
  135. # 总入球数 --------------------------------------------------------------------------------------------------------------
  136. p_code, p_id = get_pcode(corner_ball, 'total_goal')
  137. total_goals = item['total_goal']
  138. total_dict = {'total_goal_zero': '0-1', 'total_goal_two': '2-3', 'total_goal_four': '4-6',
  139. 'total_goal_seven': '7或以上', 'half_total_goal_zero': '0', "half_total_goal_one": '1',
  140. "half_total_goal_two": '2', "half_total_goal_three": '3或以上'}
  141. # # 全场入球数 单双
  142. # 上半场入球数 单双
  143. for key, value in total_goals.items():
  144. one_post(data=value, match_id=competition_id, odds_code=key, p_id=p_id,
  145. league_id=league_id, p_code=p_code, condition=total_dict[key], game_code='zq', zq_odds=zq_odds)
  146. # 全场半场 --------------------------------------------------------------------------------------------------------------
  147. half_fulls = item['half_full']
  148. p_code, p_id = get_pcode(corner_ball, 'half_full')
  149. full_dict = {"half_full_home_home": "主主", "half_full_home_dogfall": "主和",
  150. "half_full_home_guest": "主客", "half_full_dogfall_home": "和主",
  151. "half_full_dogfall_dogfall": "和和", "half_full_dogfall_guest": "和客",
  152. "half_full_guest_home": "客主", "half_full_guest_dogfall": "客和",
  153. "half_full_guest_guest": "客客"}
  154. if half_fulls:
  155. for key, value in half_fulls.items():
  156. one_post(data=value, match_id=competition_id, odds_code=key, p_id=p_id,
  157. league_id=league_id, p_code=p_code, condition=full_dict[key], game_code='zq', zq_odds=zq_odds)
  158. # 波胆------------------------------------------------------------------------------------------------------------------
  159. bodan_datas = item['bodan_data']
  160. p_code, p_id = get_pcode(corner_ball, 'bodan')
  161. bodan_dict = {"bodanhome_one_zero": "1-0", "bodanhome_two_zero": "2-0",
  162. "bodanhome_two_one": "2-1", "bodanhome_three_zero": "3-0",
  163. "bodanhome_three_one": "3-1", "bodanhome_three_two": "3-2",
  164. "bodanhome_four_zero": "4-0", "bodanhome_four_one": "4-1",
  165. "bodanhome_four_two": "4-2", "bodanhome_four_three": "4-3",
  166. "bodanguest_one_zero": "0-1", "bodanguest_two_zero": "0-2",
  167. "bodanguest_two_one": "1-2", "bodanguest_three_zero": "0-3",
  168. "bodanguest_three_one": "1-3", "bodanguest_three_two": "2-3",
  169. "bodanguest_four_zero": "0-4", "bodanguest_four_one": "1-4",
  170. "bodanguest_four_two": "2-4", "bodanguest_four_three": "3-4",
  171. "bodandogfall_zero_zero": "0-0", "bodandogfall_one_one": "1-1",
  172. "bodandogfall_two_two": "2-2", "bodandogfall_three_three": "3-3",
  173. "bodandogfall_four_four": "4-4", "bodanother": "其他",
  174. "halfbodanhome_one_zero": "1-0", "halfbodanhome_two_zero": "2-0",
  175. "halfbodanhome_two_one": "2-1", "halfbodanhome_three_zero": "3-0",
  176. "halfbodanhome_three_one": "3-1", "halfbodanhome_three_two": "3-2",
  177. "halfbodanguest_one_zero": "0-1", "halfbodanguest_two_zero": "0-2",
  178. "halfbodanguest_two_one": "1-2", "halfbodanguest_three_zero": "0-3",
  179. "halfbodanguest_three_one": "1-3", "halfbodanguest_three_two": "2-3",
  180. "halfbodandogfall_zero_zero": "0-0", "halfbodandogfall_one_one": "1-1",
  181. "halfbodandogfall_two_two": "2-2", "halfbodandogfall_three_three": "3-3",
  182. "halfbodanother": "其他"}
  183. if bodan_datas:
  184. for key, value in bodan_datas.items():
  185. one_post(data=value, match_id=competition_id, odds_code=key, p_id=p_id,
  186. league_id=league_id, p_code=p_code, condition=bodan_dict[key], game_code='zq', zq_odds=zq_odds)
  187. # 最先进球/最后进球 ------------------------------------------------------------------------------------------------------
  188. first_last_balls = item['first_last_ball']
  189. p_code, p_id = get_pcode(corner_ball, 'first_last_ball')
  190. first_last_dict = {"first_last_ball": "最先进球", "first_ball_home": "最先进球", "first_ball_guest": "最先进球",
  191. "last_ball_home": "最后进球", "last_ball_guest": "最后进球", "not_ball": "没有进球"}
  192. if first_last_balls:
  193. for key, value in first_last_balls.items():
  194. one_post(data=value, match_id=competition_id, odds_code=key, p_id=p_id,
  195. league_id=league_id, p_code=p_code, condition=first_last_dict[key], game_code='zq', zq_odds=zq_odds)
  196. p_code, p_id = get_pcode(corner_ball, 'tema_ball')
  197. full_dicts = item['full_data']
  198. half_dicts = item['half_data']
  199. full_dict_rules = item['full_data_rule']
  200. half_dict_rules = item['half_data_rule']
  201. if full_dicts:
  202. for key, value in full_dicts.items():
  203. one_post(data=value, match_id=competition_id, odds_code=key, p_id=p_id,
  204. league_id=league_id, p_code=p_code, condition=full_dict_rules[key], game_code='zq', zq_odds=zq_odds)
  205. if half_dicts:
  206. for key, value in half_dicts.items():
  207. one_post(data=value, match_id=competition_id, odds_code=key, p_id=p_id,
  208. league_id=league_id, p_code=p_code, condition=half_dict_rules[key], game_code='zq', zq_odds=zq_odds)
  209. match_date, match_time, time3 = new_time(ctime)
  210. n_time = out_time(time3, 1.5)
  211. # 插入st_zq_competition表
  212. if zuqiu == "足球":
  213. if pt == 1:
  214. payload = {
  215. "game_code": "zq",
  216. "title": "competition",
  217. "data": {
  218. "home_team": team_home,
  219. "guest_team": team_guest,
  220. "lg_id": league_id,
  221. "status": 0,
  222. "match_id": competition_id,
  223. "match_date": match_date,
  224. "match_time": match_time,
  225. "tag": number,
  226. "source": "hg3535",
  227. "is_rollball": 0,
  228. "is_today": 1,
  229. "is_morningplate": 0,
  230. "is_stringscene": 0,
  231. "us_time": ctime
  232. }
  233. }
  234. if pt == 2:
  235. payload = {
  236. "game_code": "zq",
  237. "title": "competition",
  238. "data": {
  239. "home_team": team_home,
  240. "guest_team": team_guest,
  241. "lg_id": league_id,
  242. "status": 0,
  243. "match_id": competition_id,
  244. "match_date": match_date,
  245. "match_time": match_time,
  246. "tag": number,
  247. "source": "hg3535",
  248. "is_rollball": 0,
  249. "is_today": 0,
  250. "is_morningplate": 1,
  251. "is_stringscene": 0,
  252. "us_time": ctime
  253. }
  254. }
  255. if pt == 3:
  256. payload = {
  257. "game_code": "zq",
  258. "title": "competition",
  259. "data": {
  260. "home_team": team_home,
  261. "guest_team": team_guest,
  262. "lg_id": league_id,
  263. "status": 0,
  264. "match_id": competition_id,
  265. "match_date": match_date,
  266. "match_time": match_time,
  267. "tag": number,
  268. "source": "hg3535",
  269. "is_rollball": 0,
  270. "is_today": 0,
  271. "is_morningplate": 0,
  272. "is_stringscene": 1,
  273. "us_time": ctime
  274. }
  275. }
  276. zq_odds.append(payload)
  277. # b = json.dumps(zq_odds)
  278. # print(json.dumps(zq_odds))
  279. r = requests.post(url, data={"data": json.dumps(zq_odds)})
  280. print(r.text)
  281. # print(len(zq_odds))
  282. # print(zq_odds)
  283. # print(zq_competitions)
  284. return item
  285. # 篮球 让球大小----------------------------------------------------------------------------------------------------------
  286. class Lanqiupipeline(object):
  287. def process_item(self, item, spider):
  288. # 使用twisted将mysql插入变成异步执行
  289. logger = logging.getLogger(__name__)
  290. # # logger.warning(query.addErrback(self.handle_error, item, spider))
  291. # 联赛id
  292. league_id = item['league_id']
  293. # 联赛名
  294. league_name = item['league_name']
  295. # result = item['result']
  296. # 比赛id
  297. game_id = item['game_id']
  298. # 球队1
  299. team_home = item['team_home']
  300. # 球队2
  301. team_guest = item['team_guest']
  302. # 数量(97>)
  303. number = item['number']
  304. # 比赛状态
  305. zhuangtai = item['zhuangtai']
  306. # 日期
  307. # data_game = item['data_game']
  308. try:
  309. data_game = item['data_game'].split("/")
  310. month = str(data_game[1].strip())
  311. day = str(data_game[0])
  312. except Exception as e:
  313. logger.warning(e)
  314. data_game = item['data_game'].split(" ")
  315. months = str(data_game[1].strip())
  316. month_dict = {'Jan': '01', 'Feb': '02', 'Mar': '03', 'Apr': '04', 'May': '05', 'Jun': '06', 'Jul': '07',
  317. 'Aug': '08', 'Sep': '09', 'Oct': '10', 'Nov': '11', 'Dec': '12'}
  318. month = month_dict[months]
  319. day = str(data_game[0])
  320. # 比赛时间
  321. time_game = str(item['time_game'])
  322. # 比赛时间,时间戳
  323. ctime = "2019" + "-" + month + "-" + day + " " + time_game + ":00"
  324. r_ctime = "2019" + "-" + month + "-" + day
  325. # 现在时间,时间戳
  326. utime = time.strftime("%Y-%m-%d %H:%M:%S", time.localtime())
  327. expire_time = time.strftime("%Y-%m-%d %H:%M:%S", time.localtime(time.time() + 60))
  328. # 队1分数
  329. score_home = item['score_home']
  330. # 队2分数
  331. score_guest = item['score_guest']
  332. # 第几节
  333. jijie = item['jijie']
  334. # 球队得分
  335. qiudui = item['qiudui']
  336. pt = item['pt']
  337. concedes_dict = item['concede']
  338. concedes_dict_rule = item['concede_rule']
  339. odd_evens_dict = item['odd_even']
  340. odd_evens_dict_rule = item['odd_even_rule']
  341. total_sizes_dict = item['total_size']
  342. total_sizes_dict_rule = item['total_size_rule']
  343. last_numbers_dict = item['last_number']
  344. capots_dict = item['capot']
  345. team_scores_dict = item['team_score']
  346. team_scores_dict_rule = item['team_score_rule']
  347. # 让球
  348. lanqiu = item['lanqiu']
  349. # 让球 数据插入数据库
  350. if concedes_dict:
  351. for key, value in concedes_dict.items():
  352. two_post(data=value, match_id=game_id, odds_code=key, p_id=1,
  353. league_id=league_id, p_code='concede', condition=concedes_dict_rule[key], game_code='lq')
  354. if odd_evens_dict:
  355. for key, value in odd_evens_dict.items():
  356. two_post(data=value, match_id=game_id, odds_code=key, p_id=2,
  357. league_id=league_id, p_code='two_sides', condition=odd_evens_dict_rule[key], game_code='lq')
  358. # 总分单双 数据插入数据库
  359. if total_sizes_dict:
  360. for key, value in total_sizes_dict.items():
  361. two_post(data=value, match_id=game_id, odds_code=key, p_id=3,
  362. league_id=league_id, p_code='total_size', condition=total_sizes_dict_rule[key], game_code='lq')
  363. # 全场总分大小 数据插入数据库
  364. # 全场总分大小 数据插入数据库
  365. if team_scores_dict:
  366. for key, value in team_scores_dict.items():
  367. two_post(data=value, match_id=game_id, odds_code=key, p_id=6,
  368. league_id=league_id, p_code='total_size', condition=team_scores_dict_rule[key], game_code='lq')
  369. if last_numbers_dict['last_home']:
  370. for key, value in last_numbers_dict['last_home'].items():
  371. one_post(data=value, match_id=game_id, odds_code="last_home" + key, p_id=4,
  372. league_id=league_id, p_code='team_score', condition=key, game_code='lq')
  373. if last_numbers_dict['last_guest']:
  374. for key, value in last_numbers_dict['last_guest'].items():
  375. one_post(data=value, match_id=game_id, odds_code="last_guest" + key, p_id=4,
  376. league_id=league_id, p_code='team_score', condition=key, game_code='lq')
  377. match_date, match_time, time3 = new_time(ctime)
  378. n_time = out_time(time3, 1.5)
  379. us_time = ctime
  380. if lanqiu == "篮球":
  381. if pt == 1:
  382. payload = {
  383. "game_code": "lq",
  384. "title": "competition",
  385. "data": {
  386. "home_team": team_home,
  387. "guest_team": team_guest,
  388. "lg_id": league_id,
  389. "status": 0,
  390. "match_id": game_id,
  391. "match_date": match_date,
  392. "match_time": match_time,
  393. "tag": number,
  394. "source": "hg3535",
  395. "is_rollball": 0,
  396. "is_today": 1,
  397. "is_morningplate": 0,
  398. "is_stringscene": 0,
  399. "us_time": us_time
  400. }
  401. }
  402. if pt == 2:
  403. payload = {
  404. "game_code": "lq",
  405. "title": "competition",
  406. "data": {
  407. "home_team": team_home,
  408. "guest_team": team_guest,
  409. "lg_id": league_id,
  410. "status": 0,
  411. "match_id": game_id,
  412. "match_date": match_date,
  413. "match_time": match_time,
  414. "tag": number,
  415. "source": "hg3535",
  416. "is_rollball": 0,
  417. "is_today": 0,
  418. "is_morningplate": 1,
  419. "is_stringscene": 0,
  420. "us_time": us_time
  421. }
  422. }
  423. if pt == 3:
  424. payload = {
  425. "game_code": "lq",
  426. "title": "competition",
  427. "data": {
  428. "home_team": team_home,
  429. "guest_team": team_guest,
  430. "lg_id": league_id,
  431. "status": 0,
  432. "match_id": game_id,
  433. "match_date": match_date,
  434. "match_time": match_time,
  435. "tag": number,
  436. "source": "hg3535",
  437. "is_rollball": 0,
  438. "is_today": 0,
  439. "is_morningplate": 0,
  440. "is_stringscene": 1,
  441. "us_time": us_time
  442. }
  443. }
  444. # 网球 让球&大小盘--------------------------------------------------------------------------------------------------------
  445. class Wangqiupipeline(object):
  446. def process_item(self, item, spider):
  447. logger = logging.getLogger(__name__)
  448. url = 'http://sports.5gogo.com/Sports/WriteSports/setSports'
  449. # logger.warning(query.addErrback(self.handle_error, item, spider))
  450. # 联赛id
  451. league_id = item['league_id']
  452. # 联赛名
  453. league_name = item['league_name']
  454. # result = item['result']
  455. # 比赛id
  456. game_id = item['game_id']
  457. print(game_id)
  458. # 球队1
  459. team_home = item['team_home']
  460. # 球队2
  461. team_guest = item['team_guest']
  462. # 数量(97>)
  463. number = item['number']
  464. # 比赛状态
  465. zhuangtai = item['zhuangtai']
  466. # 日期
  467. # data_game = item['data_game']
  468. try:
  469. data_game = item['data_game'].split("/")
  470. month = str(data_game[1].strip())
  471. day = str(data_game[0])
  472. except Exception as e:
  473. logger.warning(e)
  474. data_game = item['data_game'].split(" ")
  475. months = str(data_game[1].strip())
  476. month_dict = {'Jan': '01', 'Feb': '02', 'Mar': '03', 'Apr': '04', 'May': '05', 'Jun': '06', 'Jul': '07',
  477. 'Aug': '08', 'Sep': '09', 'Oct': '10', 'Nov': '11', 'Dec': '12'}
  478. month = month_dict[months]
  479. day = str(data_game[0])
  480. # 比赛时间
  481. time_game = str(item['time_game'])
  482. # 比赛时间,时间戳
  483. ctime = "2019" + "-" + month + "-" + day + " " + time_game + ":00"
  484. r_ctime = "2019" + "-" + month + "-" + day
  485. # 现在时间,时间戳
  486. utime = time.strftime("%Y-%m-%d %H:%M:%S", time.localtime())
  487. expire_time = time.strftime("%Y-%m-%d %H:%M:%S", time.localtime(time.time() + 60))
  488. # 队1分数
  489. score_home = item['score_home']
  490. # 队2分数
  491. score_guest = item['score_guest']
  492. # 第几节
  493. jijie = item['jijie']
  494. # 球队得分
  495. qiudui = item['qiudui']
  496. pt = item['pt']
  497. # 让盘
  498. concedes_dict = item['concedes_dict']
  499. concedes_dict_rule = item['concedes_dict_rule']
  500. # 冠军
  501. kemps_dict = item['kemps_dict']
  502. # 让局
  503. bureaus_dict = item['bureaus_dict']
  504. bureaus_dict_rule = item['bureaus_dict_rule']
  505. # 总局数大小
  506. total_number_dict = item['total_number_dict']
  507. total_number_dict_rule = item['total_number_dict_rule']
  508. # 总局数单双
  509. odd_evens_dict = item['odd_evens_dict']
  510. odd_evens_dict_rule = item['odd_evens_dict_rule']
  511. wangqiu = item['wangqiu']
  512. us_time = ctime
  513. match_date, match_time, time3 = new_time(ctime)
  514. n_time = out_time(time3, 3)
  515. # 插入赛事表
  516. if wangqiu == "网球":
  517. if pt == 1:
  518. payload = {
  519. "game_code": "wq",
  520. "title": "competition",
  521. "data": {
  522. "home_team": team_home,
  523. "guest_team": team_guest,
  524. "lg_id": league_id,
  525. "status": 0,
  526. "match_id": game_id,
  527. "match_date": match_date,
  528. "match_time": match_time,
  529. "tag": number,
  530. "source": "hg3535",
  531. "is_rollball": 0,
  532. "is_today": 1,
  533. "is_morningplate": 0,
  534. "is_stringscene": 0,
  535. "us_time": us_time
  536. }
  537. }
  538. resp = requests.post(url, data={"data": json.dumps(payload)})
  539. print(json.dumps(payload))
  540. print(resp.text)
  541. if pt == 2:
  542. payload = {
  543. "game_code": "wq",
  544. "title": "competition",
  545. "data": {
  546. "home_team": team_home,
  547. "guest_team": team_guest,
  548. "lg_id": league_id,
  549. "status": 0,
  550. "match_id": game_id,
  551. "match_date": match_date,
  552. "match_time": match_time,
  553. "tag": number,
  554. "source": "hg3535",
  555. "is_rollball": 0,
  556. "is_today": 0,
  557. "is_morningplate": 1,
  558. "is_stringscene": 0,
  559. "us_time": us_time
  560. }
  561. }
  562. resp = requests.post(url, data={"data": json.dumps(payload)})
  563. print(json.dumps(payload))
  564. print(resp.text)
  565. if pt == 3:
  566. payload = {
  567. "game_code": "wq",
  568. "title": "competition",
  569. "data": {
  570. "home_team": team_home,
  571. "guest_team": team_guest,
  572. "lg_id": league_id,
  573. "status": 0,
  574. "match_id": game_id,
  575. "match_date": match_date,
  576. "match_time": match_time,
  577. "tag": number,
  578. "source": "hg3535",
  579. "is_rollball": 0,
  580. "is_today": 0,
  581. "is_morningplate": 0,
  582. "is_stringscene": 1,
  583. "us_time": us_time
  584. }
  585. }
  586. resp = requests.post(url, data={"data": json.dumps(payload)})
  587. print(json.dumps(payload))
  588. print(resp.text)
  589. # 让盘
  590. if concedes_dict:
  591. for key, value in concedes_dict.items():
  592. one_post(data=value, match_id=game_id, odds_code=key, p_id=1,
  593. league_id=league_id, p_code='concede', condition=fuhao(str(concedes_dict_rule[key])), game_code='wq')
  594. # 让局
  595. if bureaus_dict:
  596. for key, value in bureaus_dict.items():
  597. one_post(data=value, match_id=game_id, odds_code=key, p_id=3,
  598. league_id=league_id, p_code='bureau', condition=fuhao(str(bureaus_dict_rule[key])), game_code='wq')
  599. if total_number_dict:
  600. for key, value in total_number_dict.items():
  601. one_post(data=value, match_id=game_id, odds_code=key, p_id=4, league_id=league_id, p_code='total_number', condition=key, game_code='wq')
  602. if odd_evens_dict:
  603. for key, value in odd_evens_dict.items():
  604. one_post(data=value, match_id=game_id, odds_code=key, p_id=5, league_id=league_id,
  605. p_code='two_game_sides', condition=key, game_code='wq')
  606. if kemps_dict:
  607. for key, value in kemps_dict.items():
  608. one_post(data=value, match_id=game_id, odds_code=key, p_id=2, league_id=league_id, p_code='kemp', condition=key, game_code='wq')
  609. return item
  610. # 网球 波胆--------------------------------------------------------------------------------------------------------------
  611. class Wqbodanpipeline(object):
  612. def process_item(self, item, spider):
  613. # 使用twisted将mysql插入变成异步执行
  614. url = 'http://sports.5gogo.com/Sports/WriteSports/setSports'
  615. logger = logging.getLogger(__name__)
  616. # logger.warning(query.addErrback(self.handle_error, item, spider))
  617. # 比赛日期
  618. try:
  619. data_game = item['data_game'].split("/")
  620. month = str(data_game[1].strip())
  621. day = str(data_game[0])
  622. except Exception as e:
  623. logger.warning(e)
  624. data_game = item['data_game'].split(" ")
  625. months = str(data_game[1].strip())
  626. month_dict = {'Jan': '01', 'Feb': '02', 'Mar': '03', 'Apr': '04', 'May': '05', 'Jun': '06', 'Jul': '07',
  627. 'Aug': '08', 'Sep': '09', 'Oct': '10', 'Nov': '11', 'Dec': '12'}
  628. month = month_dict[months]
  629. day = str(data_game[0])
  630. # 比赛时间
  631. time_game = str(item['time_game'])
  632. # 比赛时间,时间戳
  633. ctime = "2019" + "-" + month + "-" + day + " " + time_game + ":00"
  634. r_ctime = "2019" + "-" + month + "-" + day
  635. # 现在时间,时间戳
  636. utime = time.strftime("%Y-%m-%d %H:%M:%S", time.localtime())
  637. expire_time = time.strftime("%Y-%m-%d %H:%M:%S", time.localtime(time.time() + 60))
  638. # 比赛id
  639. competition_id = item['game_id']
  640. # 联赛id
  641. league_id = item['league_id']
  642. # 联赛name
  643. league_name = item['league_name']
  644. # 主队
  645. team_home = item['team_home']
  646. # 客队
  647. team_guest = item['team_guest']
  648. # 主队得分
  649. score_home = item['score_home']
  650. # 客队得分
  651. score_guest = item['score_guest']
  652. # number
  653. number = item['number']
  654. corner_ball = item['corner_ball']
  655. half_way = item['half_way']
  656. # 类型早盘,今日,滚球,串场
  657. pt = item['pt']
  658. bodan_datas = item['bodan_data']
  659. p_code = "bodan"
  660. p_id = 7
  661. bodan_dict = {"bodanhome_two_zero": "2-0", "bodanhome_two_one": "2-1",
  662. "bodanhome_three_zero": "3-0", "bodanhome_three_one": "3-1",
  663. "bodanhome_three_two": "3-2",
  664. "bodanhome_four_zero": "4-0", "bodanhome_four_one": "4-1",
  665. "bodanhome_four_two": "4-2", "bodanhome_four_three": "4-3",
  666. "bodanguest_two_zero": "0-2", "bodanguest_two_one": "1-2",
  667. "bodanguest_three_zero": "0-3",
  668. "bodanguest_three_one": "1-3", "bodanguest_three_two": "2-3",
  669. "bodanguest_four_zero": "0-4", "bodanguest_four_one": "1-4",
  670. "bodanguest_four_two": "2-4", "bodanguest_four_three": "3-4"}
  671. if bodan_datas:
  672. for key, value in bodan_datas.items():
  673. one_post(data=value, match_id=competition_id, odds_code=key, p_id=2, league_id=league_id, p_code='bodan',
  674. condition=bodan_dict[key], game_code='wq')
  675. return item
  676. # 棒球 让球&大小盘--------------------------------------------------------------------------------------------------------
  677. class Bangqiupipeline(object):
  678. def process_item(self, item, spider):
  679. # print(item)
  680. logger = logging.getLogger(__name__)
  681. url = 'http://sports.5gogo.com/Sports/WriteSports/setSports'
  682. # logger.warning(query.addErrback(self.handle_error, item, spider))
  683. # 联赛id
  684. league_id = item['league_id']
  685. # 联赛名
  686. league_name = item['league_name']
  687. # result = item['result']
  688. # 比赛id
  689. game_id = item['game_id']
  690. # 球队1
  691. team_home = item['team_home']
  692. # 球队2
  693. team_guest = item['team_guest']
  694. # 数量(97>)
  695. number = item['number']
  696. # 比赛状态
  697. zhuangtai = item['zhuangtai']
  698. # 日期
  699. # data_game = item['data_game']
  700. try:
  701. data_game = item['data_game'].split("/")
  702. month = str(data_game[1].strip())
  703. day = str(data_game[0])
  704. except Exception as e:
  705. logger.warning('data_game字段分割错误')
  706. logger.warning(e)
  707. data_game = item['data_game'].split(" ")
  708. months = str(data_game[1].strip())
  709. month_dict = {'Jan': '01', 'Feb': '02', 'Mar': '03', 'Apr': '04', 'May': '05', 'Jun': '06', 'Jul': '07',
  710. 'Aug': '08', 'Sep': '09', 'Oct': '10', 'Nov': '11', 'Dec': '12'}
  711. month = month_dict[months]
  712. day = str(data_game[0])
  713. # 比赛时间
  714. time_game = str(item['time_game'])
  715. # 比赛时间,时间戳
  716. ctime = "2019" + "-" + month + "-" + day + " " + time_game + ":00"
  717. r_ctime = "2019" + "-" + month + "-" + day
  718. # 现在时间,时间戳
  719. utime = time.strftime("%Y-%m-%d %H:%M:%S", time.localtime())
  720. expire_time = time.strftime("%Y-%m-%d %H:%M:%S", time.localtime(time.time() + 60))
  721. # 队1分数
  722. score_home = item['score_home']
  723. # 队2分数
  724. score_guest = item['score_guest']
  725. # 第几节
  726. jijie = item['jijie']
  727. # 球队得分
  728. qiudui = item['qiudui']
  729. pt = item['pt']
  730. # 让球
  731. concedes_dict = item['concedes_dict']
  732. concedes_dict_rule = item['concedes_dict_rule']
  733. # 独赢
  734. capots_dict = item['capots_dict']
  735. # 总得分大小
  736. total_size_dict = item['total_size_dict']
  737. total_size_dict_rule = item['total_size_dict_rule']
  738. # 总得分单双
  739. odd_evens_dict = item['odd_evens_dict']
  740. odd_evens_dict_rule = item['odd_evens_dict_rule']
  741. bangqiu = item['bangqiu']
  742. match_date, match_time, time3 = new_time(ctime)
  743. us_time = ctime
  744. # 插入赛事表
  745. if bangqiu == '棒球':
  746. if pt == 1:
  747. payload = {
  748. "game_code": "bq",
  749. "title": "competition",
  750. "data": {
  751. "home_team": team_home,
  752. "guest_team": team_guest,
  753. "lg_id": league_id,
  754. "status": 0,
  755. "match_id": game_id,
  756. "match_date": match_date,
  757. "match_time": match_time,
  758. "tag": number,
  759. "source": "hg3535",
  760. "is_rollball": 0,
  761. "is_today": 1,
  762. "is_morningplate": 0,
  763. "is_stringscene": 0,
  764. "us_time": us_time
  765. }
  766. }
  767. resp = requests.post(url, data={"data": json.dumps(payload)})
  768. print(json.dumps(payload))
  769. print(resp.text)
  770. if pt == 2:
  771. payload = {
  772. "game_code": "bq",
  773. "title": "competition",
  774. "data": {
  775. "home_team": team_home,
  776. "guest_team": team_guest,
  777. "lg_id": league_id,
  778. "status": 0,
  779. "match_id": game_id,
  780. "match_date": match_date,
  781. "match_time": match_time,
  782. "tag": number,
  783. "source": "hg3535",
  784. "is_rollball": 0,
  785. "is_today": 0,
  786. "is_morningplate": 1,
  787. "is_stringscene": 0,
  788. "us_time": us_time
  789. }
  790. }
  791. resp = requests.post(url, data={"data": json.dumps(payload)})
  792. print(json.dumps(payload))
  793. print(resp.text)
  794. if pt == 3:
  795. payload = {
  796. "game_code": "bq",
  797. "title": "competition",
  798. "data": {
  799. "home_team": team_home,
  800. "guest_team": team_guest,
  801. "lg_id": league_id,
  802. "status": 0,
  803. "match_id": game_id,
  804. "match_date": match_date,
  805. "match_time": match_time,
  806. "tag": number,
  807. "source": "hg3535",
  808. "is_rollball": 0,
  809. "is_today": 0,
  810. "is_morningplate": 0,
  811. "is_stringscene": 1,
  812. "us_time": us_time
  813. }
  814. }
  815. resp = requests.post(url, data={"data": json.dumps(payload)})
  816. print(json.dumps(payload))
  817. print(resp.text)
  818. # 让球
  819. three_post(data=concedes_dict, match_id=game_id, p_id=1, league_id=league_id, p_code='concede',condition=concedes_dict_rule, game_code='bq')
  820. # 总得分:大/小
  821. three_post(data=total_size_dict, match_id=game_id, p_id=2, league_id=league_id, p_code='total_size',
  822. condition=total_size_dict_rule, game_code='bq')
  823. # 单双
  824. three_post(data=odd_evens_dict, match_id=game_id, p_id=3, league_id=league_id, p_code='two_sides',
  825. condition=odd_evens_dict_rule, game_code='bq')
  826. # 插入独赢
  827. if capots_dict:
  828. for key, value in capots_dict.items():
  829. one_post(data=value, match_id=game_id, odds_code=key, p_id=4, league_id=league_id, p_code='capot', condition=None, game_code='bq')
  830. return item
  831. # 足球 篮球 网球 棒球 冠军------------------------------------------------------------------------------------------------
  832. class Guanjunpipeline(object):
  833. def process_item(self, item, spider):
  834. logger = logging.getLogger(__name__)
  835. data_game = item['data_game'].replace('年', "-").replace('月', "-").replace('日', "")
  836. time_game = item['time_game']
  837. ctime = data_game + " " + time_game + ":00"
  838. utime = time.strftime("%Y-%m-%d %H:%M:%S", time.localtime())
  839. expire_time = time.strftime("%Y-%m-%d %H:%M:%S", time.localtime(time.time() + 60))
  840. league_name = item['league_name']
  841. tema_home = item['tema_home']
  842. league_id = item['league_id']
  843. game_id = item['game_id']
  844. new_league_name = item['new_league_name']
  845. # 冠军赔率
  846. champion_team = item['champion_team']
  847. new_champion = item['new_champion']
  848. # 构建唯一哈希索引
  849. time1 = time.mktime(time.strptime(ctime, '%Y-%m-%d %H:%M:%S')) + 43200
  850. time2 = time.localtime(time1)
  851. time3 = time.strftime('%Y-%m-%d %H:%M:%S', time2)
  852. # data_time = str(time3).split(" ")
  853. # match_date,match_time = new_time(ctime)
  854. pt = item['pt']
  855. new_hash = hash_func(match_id=champion_team, odds_code=new_champion, sort=new_league_name, p_id=tema_home)
  856. ball = item['ball']
  857. # 插入st_zq_odds表
  858. r_hash = hash_func(league_id, new_champion, tema_home, champion_team)
  859. # odds_only = r_hash
  860. # s_hash = hash_func(league_id, league_name, ball, 0)
  861. # url = 'http://sports.5gogo.com/Sports/WriteSports/setSports'
  862. # 冠军赛事
  863. gs_post(ball=ball, league_id=league_id, league_name=league_name, data_game=data_game)
  864. # 冠军赔率
  865. go_post(ball=ball, league_id=league_id, new_champion=new_champion, new_league_name=new_league_name, value=champion_team, r_hash=r_hash, new_hash=new_hash, tema_home=tema_home)
  866. # 冠军联赛
  867. guanl_post(ball=ball, league_name=league_name, league_id=league_id, time3=time3)
  868. # 足球 篮球 网球 棒球 联赛------------------------------------------------------------------------------------------------
  869. class Liansaipipeline(object):
  870. def process_item(self, item, spider):
  871. logger = logging.getLogger(__name__)
  872. area_id = item["area_id"]
  873. area_name = item["area_name"]
  874. st_league = item["st_league"]
  875. name_chinese = item["name_chinese"]
  876. ball = item['ball']
  877. # utime = time.strftime("%Y-%m-%d %H:%M:%S", time.localtime())
  878. area_dict = {"南美洲": 3, "北美洲": 4, "欧洲": 5, "大洋洲": 6, "南极洲": 7, "非洲": 1, "世界": 8, "亚洲": 2}
  879. if ball == "足球":
  880. liansai(area_name=area_name, name_chinese=name_chinese, st_league=st_league, area_dict=area_dict, game_code='zq', qiu='足球')
  881. elif ball == "篮球":
  882. liansai(area_name=area_name, name_chinese=name_chinese, st_league=st_league, area_dict=area_dict, game_code='lq', qiu='篮球')
  883. elif ball == "网球":
  884. liansai(area_name=area_name, name_chinese=name_chinese, st_league=st_league, area_dict=area_dict, game_code='wq', qiu='网球')
  885. elif ball == "棒球":
  886. liansai(area_name=area_name, name_chinese=name_chinese, st_league=st_league, area_dict=area_dict, game_code='bq', qiu='棒球')
  887. return item
  888. # ---------------------------------------------------------滚球---------------------------------------------------------
  889. # 滚球足球 插入
  890. class Roll_Zuqiupipeline(object):
  891. def process_item(self, item, spider):
  892. logger = logging.getLogger(__name__)
  893. # 比赛日期
  894. try:
  895. data_game = item['data_game'].split("/")
  896. month = str(data_game[1].strip())
  897. day = str(data_game[0])
  898. except Exception as e:
  899. logger.warning(e)
  900. data_game = item['data_game'].split(" ")
  901. months = str(data_game[1].strip())
  902. 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'}
  903. month = month_dict[months]
  904. day = str(data_game[0])
  905. # 比赛时间
  906. time_game = str(item['time_game'])
  907. print(time_game)
  908. # 比赛时间,时间戳
  909. ctime = "2019" + "-" + month + "-" + day + "" + time_game + ":00"
  910. r_ctime = "2019" + "-" + month + "-" + day
  911. # 现在时间,时间戳
  912. utime = time.strftime("%Y-%m-%d %H:%M:%S", time.localtime())
  913. expire_time = time.strftime("%Y-%m-%d %H:%M:%S", time.localtime(time.time() + 60))
  914. # 比赛id
  915. competition_id = item['game_id']
  916. # 联赛id
  917. league_id = item['league_id']
  918. # 联赛name
  919. league_name = item['league_name']
  920. # 主队
  921. team_home = item['team_home']
  922. # 客队
  923. team_guest = item['team_guest']
  924. # number
  925. number = item['number']
  926. score_home = item['score_home']
  927. score_guest = item['score_guest']
  928. half_way = item['half_way']
  929. pt = item['pt']
  930. match_score = "{}:{}".format(score_home,score_guest)
  931. corner_ball = item['corner_ball']
  932. p_code, p_id = get_pcode(corner_ball, 'goal_size')
  933. # 构建唯一索引
  934. half_size_guest = item["half_size_guest"]
  935. half_size_guest_rule = item["half_size_guest_rule"]
  936. half_size_home = item["half_size_home"]
  937. half_size_home_rule = item["half_size_home_rule"]
  938. try:
  939. # 让球 数据插入数据库
  940. two_post(data=half_size_home, match_id=competition_id, odds_code='half_goal_size_big', p_id=p_id, league_id=league_id, p_code=p_code, condition=half_size_home_rule, game_code='zq')
  941. # 让球 数据插入数据库
  942. two_post(data=half_size_guest, match_id=competition_id, odds_code='half_goal_size_small', p_id=p_id, league_id=league_id, p_code=p_code, condition=half_size_guest_rule, game_code='zq')
  943. # 全场场大小
  944. size_guest = item["size_guest"]
  945. size_guest_rule = item["size_guest_rule"]
  946. size_home = item["size_home"]
  947. size_home_rule = item["size_home_rule"]
  948. two_post(data=size_guest, match_id=competition_id, odds_code='goal_size_small', p_id=p_id, league_id=league_id, p_code=p_code, condition=size_guest_rule, game_code='zq')
  949. two_post(data=size_home, match_id=competition_id, odds_code='goal_size_big', p_id=p_id, league_id=league_id, p_code=p_code, condition=size_home_rule, game_code='zq')
  950. p_code, p_id = get_pcode(corner_ball, 'concede')
  951. # 上半场让球
  952. half_concede_home_rule = item["half_concede_home_rule"]
  953. half_concede_home = item["half_concede_home"]
  954. half_concede_guest_rule = item["half_concede_guest_rule"]
  955. half_concede_guest = item["half_concede_guest"]
  956. # 上半场让球
  957. two_post(data=half_concede_home, match_id=competition_id, odds_code='half_concede_home', p_id=p_id, league_id=league_id, p_code=p_code, condition=half_concede_home_rule, game_code='zq')
  958. two_post(data=half_concede_guest, match_id=competition_id, odds_code='half_concede_guest', p_id=p_id, league_id=league_id, p_code=p_code, condition=half_concede_guest_rule, game_code='zq')
  959. concede_guest = item["concede_guest"]
  960. concede_guest_rule = item["concede_guest_rule"]
  961. concede_home = item["concede_home"]
  962. concede_home_rule = item["concede_home_rule"]
  963. # 全场让球
  964. two_post(data=concede_guest, match_id=competition_id, odds_code='concede_guest', p_id=p_id, league_id=league_id, p_code=p_code, condition=concede_guest_rule, game_code='zq')
  965. two_post(data=concede_home, match_id=competition_id, odds_code='concede_home', p_id=p_id, league_id=league_id, p_code=p_code, condition=concede_home_rule, game_code='zq')
  966. p_code, p_id = get_pcode(corner_ball, 'capot')
  967. # 独赢-------------------------------------------------------------------------------------------------------------------
  968. half_capot_home = item["half_capot_home"]
  969. half_capot_guest = item["half_capot_guest"]
  970. half_capot_dogfall = item["half_capot_dogfall"]
  971. capot_home = item["capot_home"]
  972. capot_guest = item["capot_guest"]
  973. capot_dogfall = item["capot_dogfall"]
  974. # 上半场独赢 主队
  975. one_post(data=half_capot_home, match_id=competition_id, odds_code='half_capot_home', p_id=p_id,
  976. league_id=league_id, p_code=p_code, condition=1, game_code='zq')
  977. # 上半场独赢 客队
  978. one_post(data=half_capot_guest, match_id=competition_id, odds_code='half_capot_guest', p_id=p_id,
  979. league_id=league_id, p_code=p_code, condition=2, game_code='zq')
  980. # 上半场独赢 和
  981. one_post(data=half_capot_dogfall, match_id=competition_id, odds_code='half_capot_dogfall', p_id=p_id,
  982. league_id=league_id, p_code=p_code, condition='X', game_code='zq')
  983. # 全场独赢 主队
  984. one_post(data=capot_home, match_id=competition_id, odds_code='capot_home', p_id=p_id,
  985. league_id=league_id, p_code=p_code, condition=1, game_code='zq')
  986. # 全场独赢 客队
  987. one_post(data=capot_guest, match_id=competition_id, odds_code='capot_guest', p_id=p_id,
  988. league_id=league_id, p_code=p_code, condition=2, game_code='zq')
  989. # 全场独赢 和
  990. one_post(data=capot_dogfall, match_id=competition_id, odds_code='capot_dogfall', p_id=p_id,
  991. league_id=league_id, p_code=p_code, condition='X', game_code='zq')
  992. # 入球数单双-------------------------------------------------------------------------------------------------------------
  993. p_code, p_id = get_pcode(corner_ball, 'two_sides')
  994. odd_even_odd = item["odd_even_odd"]
  995. odd_even_even = item["odd_even_even"]
  996. half_odd_even_odd = item["half_odd_even_odd"]
  997. half_odd_even_even = item["half_odd_even_even"]
  998. # 全场入球数 单双
  999. # 上半场入球数 单双
  1000. one_post(data=odd_even_odd, match_id=competition_id, odds_code='two_sides_single', p_id=p_id,
  1001. league_id=league_id, p_code=p_code, condition='单', game_code='zq')
  1002. one_post(data=odd_even_even, match_id=competition_id, odds_code='two_sides_double', p_id=p_id,
  1003. league_id=league_id, p_code=p_code, condition='双', game_code='zq')
  1004. # 全场入球数 单双
  1005. one_post(data=half_odd_even_odd, match_id=competition_id, odds_code='half_two_sides_single', p_id=p_id,
  1006. league_id=league_id, p_code=p_code, condition='双', game_code='zq')
  1007. one_post(data=half_odd_even_even, match_id=competition_id, odds_code='half_two_sides_double', p_id=p_id,
  1008. league_id=league_id, p_code=p_code, condition='双', game_code='zq')
  1009. # 总入球数 --------------------------------------------------------------------------------------------------------------
  1010. p_code, p_id = get_pcode(corner_ball, 'total_goal')
  1011. total_goals = item['total_goal']
  1012. total_dict = {'total_goal_zero': '0-1', 'total_goal_two': '2-3', 'total_goal_four': '4-6',
  1013. 'total_goal_seven': '7或以上', 'half_total_goal_zero': '0', "half_total_goal_one": '1',
  1014. "half_total_goal_two": '2', "half_total_goal_three": '3或以上'}
  1015. for key, value in total_goals.items():
  1016. one_post(data=value, match_id=competition_id, odds_code=key, p_id=p_id,
  1017. league_id=league_id, p_code=p_code, condition=total_dict[key], game_code='zq')
  1018. # 全场半场 --------------------------------------------------------------------------------------------------------------
  1019. half_fulls = item['half_full']
  1020. p_code, p_id = get_pcode(corner_ball, 'half_full')
  1021. full_dict = {"half_full_home_home": "主主", "half_full_home_dogfall": "主和",
  1022. "half_full_home_guest": "主客", "half_full_dogfall_home": "和主",
  1023. "half_full_dogfall_dogfall": "和和", "half_full_dogfall_guest": "和客",
  1024. "half_full_guest_home": "客主", "half_full_guest_dogfall": "客和",
  1025. "half_full_guest_guest": "客客"}
  1026. if half_fulls:
  1027. for key, value in half_fulls.items():
  1028. # if value:
  1029. one_post(data=value, match_id=competition_id, odds_code=key, p_id=p_id, league_id=league_id, p_code=p_code, condition=full_dict[key], game_code='zq')
  1030. # 波胆------------------------------------------------------------------------------------------------------------------
  1031. bodan_datas = item['bodan_data']
  1032. p_code, p_id = get_pcode(corner_ball, 'bodan')
  1033. bodan_dict = {"bodanhome_one_zero": "1-0", "bodanhome_two_zero": "2-0",
  1034. "bodanhome_two_one": "2-1", "bodanhome_three_zero": "3-0",
  1035. "bodanhome_three_one": "3-1", "bodanhome_three_two": "3-2",
  1036. "bodanhome_four_zero": "4-0", "bodanhome_four_one": "4-1",
  1037. "bodanhome_four_two": "4-2", "bodanhome_four_three": "4-3",
  1038. "bodanguest_one_zero": "0-1", "bodanguest_two_zero": "0-2",
  1039. "bodanguest_two_one": "1-2", "bodanguest_three_zero": "0-3",
  1040. "bodanguest_three_one": "1-3", "bodanguest_three_two": "2-3",
  1041. "bodanguest_four_zero": "0-4", "bodanguest_four_one": "1-4",
  1042. "bodanguest_four_two": "2-4", "bodanguest_four_three": "3-4",
  1043. "bodandogfall_zero_zero": "0-0", "bodandogfall_one_one": "1-1",
  1044. "bodandogfall_two_two": "2-2", "bodandogfall_three_three": "3-3",
  1045. "bodandogfall_four_four": "4-4", "bodanother": "其他",
  1046. "halfbodanhome_one_zero": "1-0", "halfbodanhome_two_zero": "2-0",
  1047. "halfbodanhome_two_one": "2-1", "halfbodanhome_three_zero": "3-0",
  1048. "halfbodanhome_three_one": "3-1", "halfbodanhome_three_two": "3-2",
  1049. "halfbodanguest_one_zero": "0-1", "halfbodanguest_two_zero": "0-2",
  1050. "halfbodanguest_two_one": "1-2", "halfbodanguest_three_zero": "0-3",
  1051. "halfbodanguest_three_one": "1-3", "halfbodanguest_three_two": "2-3",
  1052. "halfbodandogfall_zero_zero": "0-0", "halfbodandogfall_one_one": "1-1",
  1053. "halfbodandogfall_two_two": "2-2", "halfbodandogfall_three_three": "3-3",
  1054. "halfbodanother": "其他"}
  1055. if bodan_datas:
  1056. for key, value in bodan_datas.items():
  1057. one_post(data=value, match_id=competition_id, odds_code=key, p_id=p_id, league_id=league_id, p_code=p_code, condition=bodan_dict[key], game_code='zq')
  1058. # 最先进球/最后进球 ------------------------------------------------------------------------------------------------------
  1059. first_last_balls = item['first_last_ball']
  1060. p_code, p_id = get_pcode(corner_ball, 'first_last_ball')
  1061. first_last_dict = {"first_last_ball": "最先进球", "first_ball_home": "最先进球", "first_ball_guest": "最先进球",
  1062. "last_ball_home": "最后进球", "last_ball_guest": "最后进球", "not_ball": "没有进球"}
  1063. if first_last_balls:
  1064. for key, value in first_last_balls.items():
  1065. # 构建唯一索引
  1066. one_post(data=value, match_id=competition_id, odds_code=key, p_id=p_id, league_id=league_id, p_code=p_code, condition=first_last_dict[key], game_code='zq')
  1067. p_code, p_id = get_pcode(corner_ball, 'tema_ball')
  1068. full_dicts = item['full_data']
  1069. half_dicts = item['half_data']
  1070. full_dict_rules = item['full_data_rule']
  1071. half_dict_rules = item['half_data_rule']
  1072. if full_dicts:
  1073. for key, value in full_dicts.items():
  1074. one_post(data=value, match_id=competition_id, odds_code=key, p_id=p_id, league_id=league_id, p_code=p_code, condition=full_dict_rules[key], game_code='zq')
  1075. if half_dicts:
  1076. for key, value in half_dicts.items():
  1077. one_post(data=value, match_id=competition_id, odds_code=key, p_id=p_id, league_id=league_id, p_code=p_code, condition=half_dict_rules[key], game_code='zq')
  1078. zq_competition = {
  1079. "game_code": "zq",
  1080. "title": "competition",
  1081. "data": {
  1082. "home_team": team_home,
  1083. "guest_team": team_guest,
  1084. "lg_id": league_id,
  1085. "status": 1,
  1086. "match_id": competition_id,
  1087. "match_date": r_ctime,
  1088. "match_time": None,
  1089. "tag": number,
  1090. "source": "hg3535",
  1091. "is_rollball": 1,
  1092. "is_today": 0,
  1093. "is_morningplate": 0,
  1094. "is_stringscene": 0,
  1095. "us_time": None
  1096. }
  1097. }
  1098. zq_match_result = {
  1099. "game_code": "zq",
  1100. "title": "match_result",
  1101. "data": {
  1102. "home_team": team_home,
  1103. "guest_team": team_home,
  1104. "lg_id": league_id,
  1105. "home_rate": None,
  1106. "guest_rate": None,
  1107. "home_score": score_home,
  1108. "guest_score": score_guest,
  1109. "all_goal": None,
  1110. "status": 1,
  1111. "first_score": None,
  1112. "last_score": None,
  1113. "match_score": match_score,
  1114. "match_winer": None,
  1115. "match_time": time_game,
  1116. "match_process": half_way,
  1117. "tag": number,
  1118. "match_id": competition_id,
  1119. "u_home_score": None,
  1120. "u_guest_score": None,
  1121. "p_code": p_code,
  1122. "source": "hg3535"
  1123. }
  1124. }
  1125. except Exception as e:
  1126. logger.warning(e)
  1127. return item
  1128. # 滚球篮球 插入
  1129. class Roll_Lanqiupipeline(object):
  1130. def process_item(self, item, spider):
  1131. # 使用twisted将mysql插入变成异步执行
  1132. logger = logging.getLogger(__name__)
  1133. # 联赛id
  1134. league_id = item['league_id']
  1135. # 联赛名
  1136. league_name = item['league_name']
  1137. # result = item['result']
  1138. # 比赛id
  1139. game_id = item['game_id']
  1140. # 球队1 #home_team
  1141. team_home = item['team_home']
  1142. # 球队2 # guest_team
  1143. team_guest = item['team_guest']
  1144. # 数量(97>)
  1145. number = item['number']
  1146. # 比赛状态
  1147. zhuangtai = item['zhuangtai']
  1148. # 日期
  1149. # data_game = item['data_game']
  1150. try:
  1151. data_game = item['data_game'].split("/")
  1152. month = str(data_game[1].strip())
  1153. day = str(data_game[0])
  1154. except Exception as e:
  1155. logger.warning(e)
  1156. data_game = item['data_game'].split(" ")
  1157. months = str(data_game[1].strip())
  1158. 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'}
  1159. month = month_dict[months]
  1160. day = str(data_game[0])
  1161. # 比赛时间
  1162. time_game = str(item['time_game'])
  1163. # 比赛时间,时间戳
  1164. ctime = "2019" + "-" + month + "-" + day + "" + time_game + ":00"
  1165. r_ctime = "2019" + "-" + month + "-" + day
  1166. expire_time = time.strftime("%Y-%m-%d %H:%M:%S", time.localtime(time.time() + 60))#过期时间
  1167. # 现在时间,时间戳
  1168. utime = time.strftime("%Y-%m-%d %H:%M:%S", time.localtime())
  1169. # 队1分数
  1170. score_home = item['score_home']
  1171. # 队2分数
  1172. score_guest = item['score_guest']
  1173. # 第几节
  1174. jijie = item['jijie']
  1175. # 球队得分
  1176. qiudui = item['qiudui']
  1177. pt = item['pt']
  1178. match_score = "{}:{}".format(score_home,score_guest)
  1179. concedes_dict = item['concede']
  1180. concedes_dict_rule = item['concede_rule']
  1181. odd_evens_dict = item['odd_even']
  1182. odd_evens_dict_rule = item['odd_even_rule']
  1183. total_sizes_dict = item['total_size']
  1184. total_sizes_dict_rule = item['total_size_rule']
  1185. last_numbers_dict = item['last_number']
  1186. capots_dict = item['capot']
  1187. team_scores_dict = item['team_score']
  1188. team_scores_dict_rule = item['team_score_rule']
  1189. try:
  1190. if concedes_dict:
  1191. for key, value in concedes_dict.items():
  1192. two_post(data=value, match_id=game_id, odds_code=key, p_id=1, league_id=league_id, p_code='concede', condition=concedes_dict_rule[key], game_code='lq')
  1193. if odd_evens_dict:
  1194. for key, value in odd_evens_dict.items():
  1195. two_post(data=value, match_id=game_id, odds_code=key, p_id=2, league_id=league_id, p_code='two_sides',
  1196. condition=odd_evens_dict_rule[key], game_code='lq')
  1197. if total_sizes_dict:
  1198. for key, value in total_sizes_dict.items():
  1199. two_post(data=value, match_id=game_id, odds_code=key, p_id=3, league_id=league_id, p_code='total_size',
  1200. condition=total_sizes_dict_rule[key], game_code='lq')
  1201. last_home = last_numbers_dict['last_home']
  1202. if last_home:
  1203. for key, value in last_home.items():
  1204. one_post(data=value, match_id=game_id, odds_code="last_home" + key, p_id=4, league_id=league_id, p_code='last_home', condition=key, game_code='lq')
  1205. last_guest = last_numbers_dict['last_guest']
  1206. if last_guest:
  1207. for key, value in last_guest.items():
  1208. one_post(data=value, match_id=game_id, odds_code="last_guest" + key, p_id=4, league_id=league_id,
  1209. p_code='last_guest', condition=key, game_code='lq')
  1210. if capots_dict:
  1211. for key, value in capots_dict.items():
  1212. one_post(data=value, match_id=game_id, odds_code=key, p_id=5, league_id=league_id,
  1213. p_code='capot', condition=None, game_code='lq')
  1214. if team_scores_dict:
  1215. for key, value in team_scores_dict.items():
  1216. one_post(data=value, match_id=game_id, odds_code=key, p_id=6, league_id=league_id,
  1217. p_code='team_score', condition=team_scores_dict_rule[key], game_code='lq')
  1218. lq_competition = {
  1219. "game_code": "lq",
  1220. "title": "competition",
  1221. "data": {
  1222. "home_team": team_home,
  1223. "guest_team": team_guest,
  1224. "lg_id": league_id,
  1225. "status": 1,
  1226. "match_id": game_id,
  1227. "match_date": r_ctime,
  1228. "match_time": None,
  1229. "tag": number,
  1230. "source": 'hg3535',
  1231. "is_rollball": 1,
  1232. "is_today": 0,
  1233. "is_morningplate": 0,
  1234. "is_stringscene": 0,
  1235. "us_time": None
  1236. }
  1237. }
  1238. lq_match_result = {
  1239. "game_code": "lq",
  1240. "title": "match_result",
  1241. "data": {
  1242. "home_team": team_home,
  1243. "guest_team": team_home,
  1244. "lg_id": league_id,
  1245. "home_rate": None,
  1246. "guest_rate": None,
  1247. "home_score": score_home,
  1248. "guest_score": score_guest,
  1249. "all_goal": None,
  1250. "status": 1,
  1251. "first_score": None,
  1252. "last_score": None,
  1253. "match_score": match_score,
  1254. "match_winer": None,
  1255. "match_time": time_game,
  1256. "match_process": jijie,
  1257. "tag": number,
  1258. "match_id": game_id,
  1259. "u_home_score": None,
  1260. "u_guest_score": None,
  1261. "p_code": None,
  1262. "source": "hg3535"
  1263. }
  1264. }
  1265. except:
  1266. pass
  1267. return item
  1268. # 滚球网球 插入
  1269. class Roll_Wangqiupipeline(object):
  1270. def process_item(self, item, spider):
  1271. logger = logging.getLogger(__name__)
  1272. # 联赛id
  1273. league_id = item['league_id']
  1274. # 联赛名
  1275. league_name = item['league_name']
  1276. # result = item['result']
  1277. # 比赛id
  1278. game_id = item['game_id']
  1279. # 球队1
  1280. team_home = item['team_home']
  1281. # 球队2
  1282. team_guest = item['team_guest']
  1283. # 数量(97>)
  1284. number = item['number']
  1285. # 比赛状态
  1286. zhuangtai = item['zhuangtai']
  1287. # 日期
  1288. # data_game = item['data_game']
  1289. try:
  1290. data_game = item['data_game'].split("/")
  1291. month = str(data_game[1].strip())
  1292. day = str(data_game[0])
  1293. except Exception as e:
  1294. logger.warning(e)
  1295. data_game = item['data_game'].split(" ")
  1296. months = str(data_game[1].strip())
  1297. 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'}
  1298. month = month_dict[months]
  1299. day = str(data_game[0])
  1300. # 比赛时间
  1301. time_game = str(item['time_game'])
  1302. # 比赛时间,时间戳
  1303. ctime = "2019" + "-" + month + "-" + day + "" + time_game + ":00"
  1304. r_ctime = "2019" + "-" + month + "-" + day
  1305. # 现在时间,时间戳
  1306. utime = time.strftime("%Y-%m-%d %H:%M:%S", time.localtime())
  1307. # 队1分数
  1308. score_home = item['score_home']
  1309. # 队2分数
  1310. score_guest = item['score_guest']
  1311. # 第几节
  1312. jijie = item['jijie']
  1313. # 球队得分
  1314. qiudui = item['qiudui']
  1315. pt = item['pt']
  1316. #取不到 暂时注掉
  1317. match_date, match_time = new_times(ctime)
  1318. # 让盘
  1319. concedes_dict = item['concedes_dict']
  1320. concedes_dict_rule = item['concedes_dict_rule']
  1321. # 冠军 独赢
  1322. kemps_dict = item['kemps_dict']
  1323. # 让局
  1324. bureaus_dict = item['bureaus_dict']
  1325. bureaus_dict_rule = item['bureaus_dict_rule']
  1326. # 总局数大小
  1327. total_number_dict = item['total_number_dict']
  1328. total_number_dict_rule = item['total_number_dict_rule']
  1329. # 总局数单双
  1330. odd_evens_dict = item['odd_evens_dict']
  1331. odd_evens_dict_rule = item['odd_evens_dict_rule']
  1332. if concedes_dict:
  1333. for key, value in concedes_dict.items():
  1334. one_post(data=value, match_id=game_id, odds_code=key, p_id=6, league_id=league_id,
  1335. p_code='dishes', condition=concedes_dict_rule[key], game_code='wq')
  1336. if kemps_dict:
  1337. for key, value in kemps_dict.items():
  1338. one_post(data=value, match_id=game_id, odds_code=key, p_id=2, league_id=league_id,
  1339. p_code='kemp', condition=None, game_code='wq')
  1340. if bureaus_dict:
  1341. for key, value in bureaus_dict.items():
  1342. one_post(data=value, match_id=game_id, odds_code=key, p_id=3, league_id=league_id,
  1343. p_code='bureau', condition=None, game_code='wq')
  1344. if total_number_dict:
  1345. for key, value in total_number_dict.items():
  1346. one_post(data=value, match_id=game_id, odds_code=key, p_id=3, league_id=league_id,
  1347. p_code='total_number', condition=total_number_dict_rule[key], game_code='wq')
  1348. if odd_evens_dict:
  1349. for key, value in odd_evens_dict.items():
  1350. one_post(data=value, match_id=game_id, odds_code=key, p_id=5, league_id=league_id,
  1351. p_code='two_sides', condition=odd_evens_dict_rule[key], game_code='wq')
  1352. wq_competition = {
  1353. "game_code": "wq",
  1354. "title": "competition",
  1355. "data": {
  1356. "home_team": team_home,
  1357. "guest_team": team_guest,
  1358. "lg_id": league_id,
  1359. "status": 1,
  1360. "match_id": game_id,
  1361. "match_date": r_ctime,
  1362. "match_time": None,
  1363. "tag": number,
  1364. "source": 'hg3535',
  1365. "is_rollball": 1,
  1366. "is_today": 0,
  1367. "is_morningplate": 0,
  1368. "is_stringscene": 0,
  1369. "us_time": None
  1370. }
  1371. }
  1372. wq_match_result = {
  1373. "game_code": "wq",
  1374. "title": "match_result",
  1375. "data": {
  1376. "home_team": team_home,
  1377. "guest_team": team_home,
  1378. "lg_id": league_id,
  1379. "home_rate": None,
  1380. "guest_rate": None,
  1381. "home_score": score_home,
  1382. "guest_score": score_guest,
  1383. "all_goal": None,
  1384. "status": 1,
  1385. "first_score": None,
  1386. "last_score": None,
  1387. "match_score": None,
  1388. "match_winer": None,
  1389. "match_time": time_game,
  1390. "match_process": jijie,
  1391. "tag": number,
  1392. "match_id": game_id,
  1393. "u_home_score": None,
  1394. "u_guest_score": None,
  1395. "p_code": None,
  1396. "source": "hg3535"
  1397. }
  1398. }
  1399. return item
  1400. # 滚球棒球 插入
  1401. class Roll_Banqiupipeline(object):
  1402. def process_item(self, item, spider):
  1403. # 使用twisted将mysql插入变成异步执行
  1404. # 联赛id
  1405. league_id = item['league_id']
  1406. # 联赛名
  1407. league_name = item['league_name']
  1408. # result = item['result']
  1409. # 比赛id
  1410. game_id = item['game_id']
  1411. # 球队1
  1412. team_home = item['team_home']
  1413. # 球队2
  1414. team_guest = item['team_guest']
  1415. # 数量(97>)
  1416. number = item['number']
  1417. #新增 match_score_dict
  1418. match_score_dict = item['match_score_dict']
  1419. # 比赛状态
  1420. zhuangtai = item['zhuangtai']
  1421. # 日期
  1422. # data_game = item['data_game']
  1423. data_game = item['data_game'].split("/")
  1424. month = str(data_game[1].strip())
  1425. day = str(data_game[0])
  1426. # 比赛时间
  1427. # time_game = str(item['time_game'])
  1428. # 比赛时间,时间戳
  1429. # ctime = "2019" + "-" + month + "-" + day + "" + time_game + ":00".strip()
  1430. r_ctime = "2019" + "-" + month + "-" + day
  1431. # 现在时间,时间戳
  1432. utime = time.strftime("%Y-%m-%d %H:%M:%S", time.localtime())
  1433. expire_time = time.strftime("%Y-%m-%d %H:%M:%S", time.localtime(time.time() + 60))
  1434. # 队1分数
  1435. score_home = item['score_home']
  1436. # 队2分数
  1437. score_guest = item['score_guest']
  1438. # 第几节
  1439. jijie = item['jijie']
  1440. # 球队得分
  1441. qiudui = item['qiudui']
  1442. pt = item['pt']
  1443. #滚球这个位置获取不到这些字段
  1444. # match_date, match_time = new_time(ctime)
  1445. # 让球
  1446. concedes_dict = item['concedes_dict']
  1447. concedes_dict_rule = item['concedes_dict_rule']
  1448. # 独赢
  1449. capots_dict = item['capots_dict']
  1450. # 总得分大小
  1451. total_size_dict = item['total_size_dict']
  1452. total_size_dict_rule = item['total_size_dict_rule']
  1453. # 总得分单双
  1454. odd_evens_dict = item['odd_evens_dict']
  1455. odd_evens_dict_rule = item['odd_evens_dict_rule']
  1456. # 让球
  1457. concede = {'league_id': league_id, 'game_id': game_id, 'utime': utime, 'p_id': 1, 'p_code': "concede",
  1458. 'source': "hg3535", 'expire_time': expire_time, 'sort': 0}
  1459. # bqone_intodb(data1=concedes_dict, data2=concede, data3=concedes_dict_rule, cursor=self.cursor)
  1460. # 总得分:大/小
  1461. total_size = {'league_id': league_id, 'game_id': game_id, 'utime': utime, 'p_id': 2, 'p_code': "total_size",
  1462. 'source': "hg3535", 'expire_time': expire_time, 'sort': 0}
  1463. # bqone_intodb(data1=total_size_dict, data2=total_size, data3=total_size_dict_rule, cursor=self.cursor)
  1464. odd_even = {'league_id': league_id, 'game_id': game_id, 'utime': utime, 'p_id': 3, 'p_code': "two_sides",
  1465. 'source': "hg3535", 'expire_time': expire_time, 'sort': 0}
  1466. # 赛事失效时间
  1467. # n_time = out_time(ctime, 3.5)
  1468. # 插入独赢
  1469. if capots_dict:
  1470. for key, value in capots_dict.items():
  1471. one_post(data=value, match_id=game_id, odds_code=key, p_id=2, league_id=league_id,
  1472. p_code='capot', condition=None, game_code='bq')
  1473. #让球
  1474. if concedes_dict:
  1475. for key, value in concedes_dict.items():
  1476. one_post(data=value, match_id=game_id, odds_code=key, p_id=1, league_id=league_id,
  1477. p_code='concede', condition=concedes_dict_rule[key], game_code='bq')
  1478. if total_size_dict:
  1479. for key, value in total_size_dict.items():
  1480. one_post(data=value, match_id=game_id, odds_code=key, p_id=1, league_id=league_id,
  1481. p_code='total_size', condition=total_size_dict_rule[key], game_code='bq')
  1482. if odd_evens_dict:
  1483. for key, value in odd_evens_dict.items():
  1484. one_post(data=value, match_id=game_id, odds_code=key, p_id=1, league_id=league_id,
  1485. p_code='two_sides', condition=odd_evens_dict_rule[key], game_code='bq')
  1486. bq_competition = {
  1487. "game_code": "bq",
  1488. "title": "competition",
  1489. "data": {
  1490. "home_team": team_home,
  1491. "guest_team": team_guest,
  1492. "lg_id": league_id,
  1493. "status": 1,
  1494. "match_id": game_id,
  1495. "match_date": None,
  1496. "match_time": None,
  1497. "tag": number,
  1498. "source": 'hg3535',
  1499. "is_rollball": 1,
  1500. "is_today": 0,
  1501. "is_morningplate": 0,
  1502. "is_stringscene": 0,
  1503. "us_time": None
  1504. }
  1505. }
  1506. bq_match_result = {
  1507. "game_code": "bq",
  1508. "title": "match_result",
  1509. "data": {
  1510. "home_team": team_home,
  1511. "guest_team": team_home,
  1512. "lg_id": league_id,
  1513. "home_rate": None,
  1514. "guest_rate": None,
  1515. "home_score": score_home,
  1516. "guest_score": score_guest,
  1517. "all_goal": None,
  1518. "status": 1,
  1519. "first_score": None,
  1520. "last_score": None,
  1521. "match_score": None,
  1522. "match_winer": None,
  1523. "match_time": r_ctime,
  1524. "match_process": jijie,
  1525. "tag": number,
  1526. "match_id": game_id,
  1527. "u_home_score": None,
  1528. "u_guest_score": None,
  1529. "p_code": None,
  1530. "source": "hg3535",
  1531. 'match_score_t': match_score_dict
  1532. }
  1533. }
  1534. return item
  1535. # 足球 赛事结束 结果插入--------------------------------------------------------------------------------------------------
  1536. # class Zujieshuqiupipeline(object):
  1537. # def open_spider(self, spider):
  1538. # self.conn = psycopg2.connect(host=settings["POST_HOST"], port=settings['POST_PORT'], user=settings["POST_USER"], password=settings["POST_PASSWORD"], database=settings["POST_DATABASE"])
  1539. # self.cursor = self.conn.cursor(cursor_factory=psycopg2.extras.DictCursor)
  1540. # def process_item(self, item, spider):
  1541. # logger = logging.getLogger(__name__)
  1542. # ctime = time.strftime("%Y-%m-%d %H:%M:%S", time.localtime())
  1543. # # 赛事id
  1544. # match_id = item['id_score'][0]
  1545. # # 全场比分
  1546. # score = item['id_score'][1]
  1547. # status = 0
  1548. # game_code = 'zq'
  1549. # try:
  1550. # sql = "insert into comendnotice(status, game_code, match_id, ctime) values (%s, %s, %s, %s) on conflict(match_id) do update set ctime = %s"
  1551. # self.cursor.execute(sql, (status, game_code, match_id, ctime, ctime))
  1552. # self.cursor.execute("update st_zq_result set status=2 where match_id={}".format(match_id))
  1553. # # self.cursor.execute("update st_zq_result_record set status=2 where match_id={}".format(match_id))
  1554. # self.cursor.execute("update st_zq_competition set status=2 where match_id={}".format(match_id))
  1555. # except Exception as e:
  1556. # logger.warning('足球 赛事结束 结果插入错误')
  1557. # logger.warning(e)
  1558. # return item
  1559. # # 篮球 赛事结束 结果插入--------------------------------------------------------------------------------------------------
  1560. # class Lanjieshuqiupipeline(object):
  1561. # def open_spider(self, spider):
  1562. # self.conn = psycopg2.connect(host=settings["POST_HOST"], port=settings['POST_PORT'], user=settings["POST_USER"], password=settings["POST_PASSWORD"], database=settings["POST_DATABASE"])
  1563. # self.cursor = self.conn.cursor(cursor_factory=psycopg2.extras.DictCursor)
  1564. #
  1565. # def process_item(self, item, spider):
  1566. # logger = logging.getLogger(__name__)
  1567. # ctime = time.strftime("%Y-%m-%d %H:%M:%S", time.localtime())
  1568. # # 赛事id
  1569. # match_id = item['id_score'][0]
  1570. # # 全场比分
  1571. # score = item['id_score'][1]
  1572. # status = 0
  1573. # game_code = 'lq'
  1574. # try:
  1575. # sql = "insert into comendnotice(status, game_code, match_id, ctime) values (%s, %s, %s, %s) on conflict(match_id) do update set ctime = %s"
  1576. # self.cursor.execute(sql, (status, game_code, match_id, ctime, ctime))
  1577. # self.cursor.execute("update st_lq_result set status=2 where match_id={}".format(match_id))
  1578. # # self.cursor.execute("update st_zq_result_record set status=2 where match_id={}".format(match_id))
  1579. # self.cursor.execute("update st_lq_competition set status=2 where match_id={}".format(match_id))
  1580. # except Exception as e:
  1581. # logger.warning('篮球 赛事结束 结果插入错误')
  1582. # logger.warning(e)
  1583. # return item
  1584. #
  1585. # def close_spider(self, spider):
  1586. # self.conn.commit()
  1587. # self.conn.close()
  1588. #
  1589. #
  1590. # # 棒球 赛事结束 结果插入--------------------------------------------------------------------------------------------------
  1591. # class Bangjieshuqiupipeline(object):
  1592. # def open_spider(self, spider):
  1593. # self.conn = psycopg2.connect(host=settings["POST_HOST"], port=settings['POST_PORT'], user=settings["POST_USER"],
  1594. # password=settings["POST_PASSWORD"], database=settings["POST_DATABASE"])
  1595. # self.cursor = self.conn.cursor(cursor_factory=psycopg2.extras.DictCursor)
  1596. #
  1597. # def process_item(self, item, spider):
  1598. # logger = logging.getLogger(__name__)
  1599. # ctime = time.strftime("%Y-%m-%d %H:%M:%S", time.localtime())
  1600. # # 赛事id
  1601. # match_id = item['id_score'][0]
  1602. # # 全场比分
  1603. # score = item['id_score'][1]
  1604. # status = 0
  1605. # game_code = 'lq'
  1606. # try:
  1607. # sql = "insert into comendnotice(status, game_code, match_id, ctime) values (%s, %s, %s, %s) on conflict(match_id) do update set ctime = %s"
  1608. # self.cursor.execute(sql, (status, game_code, match_id, ctime, ctime))
  1609. # self.cursor.execute("update st_bq_result set status=2 where match_id={}".format(match_id))
  1610. # # self.cursor.execute("update st_zq_result_record set status=2 where match_id={}".format(match_id))
  1611. # self.cursor.execute("update st_bq_competition set status=2 where match_id={}".format(match_id))
  1612. # except Exception as e:
  1613. # logger.warning('棒球 赛事结束 结果插入错误')
  1614. # logger.warning(e)
  1615. # return item
  1616. #
  1617. # def close_spider(self, spider):
  1618. # self.conn.commit()
  1619. # self.conn.close()
  1620. #
  1621. #
  1622. # # 网球 赛事结束 结果插入--------------------------------------------------------------------------------------------------
  1623. # class Wangjieshuqiupipeline(object):
  1624. # def open_spider(self, spider):
  1625. # self.conn = psycopg2.connect(host=settings["POST_HOST"], port=settings['POST_PORT'], user=settings["POST_USER"],
  1626. # password=settings["POST_PASSWORD"], database=settings["POST_DATABASE"])
  1627. # self.cursor = self.conn.cursor(cursor_factory=psycopg2.extras.DictCursor)
  1628. #
  1629. # def process_item(self, item, spider):
  1630. # logger = logging.getLogger(__name__)
  1631. # ctime = time.strftime("%Y-%m-%d %H:%M:%S", time.localtime())
  1632. # # 赛事id
  1633. # match_id = item['id_score'][0]
  1634. # # 全场比分
  1635. # score = item['id_score'][1]
  1636. # status = 0
  1637. # game_code = 'lq'
  1638. # try:
  1639. # sql = "insert into comendnotice(status, game_code, match_id, ctime) values (%s, %s, %s, %s) on conflict(match_id) do update set ctime = %s"
  1640. # self.cursor.execute(sql, (status, game_code, match_id, ctime, ctime))
  1641. # self.cursor.execute("update st_wq_result set status=2 where match_id={}".format(match_id))
  1642. # # self.cursor.execute("update st_zq_result_record set status=2 where match_id={}".format(match_id))
  1643. # self.cursor.execute("update st_wq_competition set status=2 where match_id={}".format(match_id))
  1644. # except Exception as e:
  1645. # logger.warning('网球 赛事结束 结果插入错误')
  1646. # logger.warning(e)
  1647. # return item
  1648. #
  1649. # def close_spider(self, spider):
  1650. # self.conn.commit()
  1651. # self.conn.close()