pipelines.py 83 KB

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