pipelines.py 134 KB

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