pipelines.py 84 KB

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