pipelines.py 85 KB

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