lanqiu.py 9.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219
  1. # import datetime
  2. # import json
  3. # import pymongo
  4. import time
  5. import logging
  6. # import requests
  7. # from ball_func import fuhao
  8. from ..utils.helper import Helper
  9. from .ball_func import get_pcode, new_time, out_time
  10. class Lanqiupipeline(object):
  11. def process_item(self, item, spider):
  12. # 使用twisted将mysql插入变成异步执行
  13. lq_odds = []
  14. url = 'http://admin.5gogo.com'
  15. logger = logging.getLogger(__name__)
  16. # # logger.warning(query.addErrback(self.handle_error, item, spider))
  17. # 联赛id
  18. league_id = item['league_id']
  19. # 联赛名
  20. league_name = item['league_name']
  21. # result = item['result']
  22. # 比赛id
  23. match_id = item['game_id']
  24. # 球队1
  25. team_home = item['team_home']
  26. # 球队2
  27. team_guest = item['team_guest']
  28. # 数量(97>)
  29. tag_number = item['number']
  30. # 比赛状态
  31. zhuangtai = item['zhuangtai']
  32. # 日期
  33. # data_game = item['data_game']
  34. try:
  35. data_game = item['data_game'].split("/")
  36. month = str(data_game[1].strip())
  37. day = str(data_game[0])
  38. except Exception as e:
  39. logger.warning(e)
  40. data_game = item['data_game'].split(" ")
  41. months = str(data_game[1].strip())
  42. month_dict = {'Jan': '01', 'Feb': '02', 'Mar': '03', 'Apr': '04', 'May': '05', 'Jun': '06', 'Jul': '07',
  43. 'Aug': '08', 'Sep': '09', 'Oct': '10', 'Nov': '11', 'Dec': '12'}
  44. month = month_dict[months]
  45. day = str(data_game[0])
  46. # 比赛时间
  47. time_game = str(item['time_game'])
  48. # 比赛时间,时间戳
  49. us_time = "2019" + "-" + month + "-" + day + " " + time_game + ":00"
  50. r_ctime = "2019" + "-" + month + "-" + day
  51. # 现在时间,时间戳
  52. utime = time.strftime("%Y-%m-%d %H:%M:%S", time.localtime())
  53. expire_time = time.strftime("%Y-%m-%d %H:%M:%S", time.localtime(time.time() + 60))
  54. # 队1分数
  55. score_home = item['score_home']
  56. # 队2分数
  57. score_guest = item['score_guest']
  58. # 第几节
  59. jijie = item['jijie']
  60. # 球队得分
  61. qiudui = item['qiudui']
  62. pt = item['pt']
  63. concedes_dict = item['concede']
  64. concedes_dict_rule = item['concede_rule']
  65. odd_evens_dict = item['odd_even']
  66. odd_evens_dict_rule = item['odd_even_rule']
  67. total_sizes_dict = item['total_size']
  68. total_sizes_dict_rule = item['total_size_rule']
  69. last_numbers_dict = item['last_number']
  70. capots_dict = item['capot']
  71. team_scores_dict = item['team_score']
  72. team_scores_dict_rule = item['team_score_rule']
  73. # 让球
  74. lanqiu = item['lanqiu']
  75. match_date, match_time, time3 = new_time(us_time)
  76. # 让球 数据插入数据库
  77. last_time = '2019-12-31 23:59:59'
  78. league_dict = {"game_code": "lq", "title": "league", "source": "hg3535"}
  79. league_list = []
  80. uuid = Helper.genearte_MD5(league_name + 'hg3535')
  81. league_key = ["name_chinese", "kind", "match_mode", "if_stop", "last_time", "lg_id", "source", "uuid"]
  82. league_value = [league_name, "1", "1", "0", last_time, league_id, "hg3535", uuid]
  83. league_data = dict(zip(league_key, league_value))
  84. league_list.append(league_data)
  85. league_dict['data'] = league_list
  86. response_data = Helper.async_post(url + '/setLeague', league_dict)
  87. print(response_data)
  88. if pt == '3':
  89. is_rollball = 0
  90. is_today = 0
  91. is_morningplate = 0
  92. is_stringscene = 1
  93. elif pt == '2':
  94. is_rollball = 0
  95. is_today = 0
  96. is_morningplate = 1
  97. is_stringscene = 0
  98. else:
  99. is_today = 1
  100. is_rollball = 0
  101. is_morningplate = 0
  102. is_stringscene = 0
  103. # 赛事接口写入
  104. match_dict = {"game_code": "lq", "title": "match", "source": "hg3535"}
  105. match_kay = ["home_team", "guest_team", "lg_id", "status", "match_id", "match_date", "match_time", "tag",
  106. "source", "is_rollball", "is_morningplate", "is_stringscene", "us_time", "uuid", "half_match_id", "is_today"]
  107. match_value = [team_home, team_guest, league_id, 0, match_id, match_date, match_time, tag_number, "hg3535",
  108. is_rollball, is_morningplate, is_stringscene, us_time, uuid, 0, is_today]
  109. match_list = []
  110. match_data = dict(zip(match_kay, match_value))
  111. match_list.append(match_data)
  112. match_dict['data'] = match_list
  113. response_data = Helper.async_post(url + '/setMatch', match_dict)
  114. print(response_data)
  115. # if concedes_dict:
  116. # for key, value in concedes_dict.items():
  117. # two_post(data=value, match_id=game_id, odds_code=key, p_id=1,
  118. # league_id=league_id, p_code='concede', condition=concedes_dict_rule[key], game_code='lq', zq_odds=lq_odds)
  119. # if odd_evens_dict:
  120. # for key, value in odd_evens_dict.items():
  121. # one_post(data=value, match_id=game_id, odds_code=key, p_id=2,
  122. # league_id=league_id, p_code='two_sides', condition=odd_evens_dict_rule[key], game_code='lq', zq_odds=lq_odds)
  123. # # 总分单双 数据插入数据库
  124. # if total_sizes_dict:
  125. # for key, value in total_sizes_dict.items():
  126. # two_post(data=value, match_id=game_id, odds_code=key, p_id=3,
  127. # league_id=league_id, p_code='total_size', condition=total_sizes_dict_rule[key], game_code='lq', zq_odds=lq_odds)
  128. # # 全场总分大小 数据插入数据库
  129. # # 全场总分大小 数据插入数据库
  130. # if team_scores_dict:
  131. # for key, value in team_scores_dict.items():
  132. # two_post(data=value, match_id=game_id, odds_code=key, p_id=6,
  133. # league_id=league_id, p_code='total_size', condition=team_scores_dict_rule[key], game_code='lq', zq_odds=lq_odds)
  134. # lastnumber_dict = {'0或5': '_zero_five', '1或6': '_one_six', '2或7': '_two_seven', '3或8': '_three_eight', '4或9': '_four_nine'}
  135. # if last_numbers_dict['last_home']:
  136. # for key, value in last_numbers_dict['last_home'].items():
  137. # one_post(data=value, match_id=game_id, odds_code="last_home" + lastnumber_dict[key], p_id=4,
  138. # league_id=league_id, p_code='last_number', condition=key, game_code='lq', zq_odds=lq_odds)
  139. # if last_numbers_dict['last_guest']:
  140. # for key, value in last_numbers_dict['last_guest'].items():
  141. # one_post(data=value, match_id=game_id, odds_code="last_guest" + lastnumber_dict[key], p_id=4,
  142. # league_id=league_id, p_code='last_number', condition=key, game_code='lq', zq_odds=lq_odds)
  143. # three_post(data=capots_dict, match_id=game_id, p_id=5, league_id=league_id, p_code='capot', condition="", game_code='lq', zq_odds=lq_odds)
  144. # match_date, match_time, time3 = new_time(ctime)
  145. # n_time = out_time(time3, 1.5)
  146. # us_time = ctime
  147. # if lanqiu == "篮球":
  148. # if pt == 1:
  149. # payload = {
  150. # "game_code": "lq",
  151. # "title": "competition",
  152. # "data": {
  153. # "home_team": team_home,
  154. # "guest_team": team_guest,
  155. # "lg_id": league_id,
  156. # "status": 0,
  157. # "match_id": game_id,
  158. # "match_date": match_date,
  159. # "match_time": match_time,
  160. # "tag": number,
  161. # "source": "hg3535",
  162. # "is_rollball": 0,
  163. # "is_today": 1,
  164. # "is_morningplate": 0,
  165. # "is_stringscene": 0,
  166. # "us_time": us_time
  167. # }
  168. # }
  169. # if pt == 2:
  170. # payload = {
  171. # "game_code": "lq",
  172. # "title": "competition",
  173. # "data": {
  174. # "home_team": team_home,
  175. # "guest_team": team_guest,
  176. # "lg_id": league_id,
  177. # "status": 0,
  178. # "match_id": game_id,
  179. # "match_date": match_date,
  180. # "match_time": match_time,
  181. # "tag": number,
  182. # "source": "hg3535",
  183. # "is_rollball": 0,
  184. # "is_today": 0,
  185. # "is_morningplate": 1,
  186. # "is_stringscene": 0,
  187. # "us_time": us_time
  188. # }
  189. # }
  190. # if pt == 3:
  191. # payload = {
  192. # "game_code": "lq",
  193. # "title": "competition",
  194. # "data": {
  195. # "home_team": team_home,
  196. # "guest_team": team_guest,
  197. # "lg_id": league_id,
  198. # "status": 0,
  199. # "match_id": game_id,
  200. # "match_date": match_date,
  201. # "match_time": match_time,
  202. # "tag": number,
  203. # "source": "hg3535",
  204. # "is_rollball": 0,
  205. # "is_today": 0,
  206. # "is_morningplate": 0,
  207. # "is_stringscene": 1,
  208. # "us_time": us_time
  209. # }
  210. # }
  211. # lq_odds.insert(0, payload)
  212. # r = requests.post(url, data={"data": json.dumps(lq_odds)})
  213. # # logger.warning(r.text)
  214. # print(r.text)
  215. # return item