zuqiu.py 65 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061
  1. import datetime
  2. # import threading
  3. import time
  4. import logging
  5. import pymongo
  6. from twisted.internet import defer, reactor
  7. # from .ball_func import fuhao
  8. from ..utils.helper import Helper
  9. from .ball_func import new_time
  10. from ..settings import M_HOST, M_USER, M_PASSWORD, M_POST, M_DB, LEAGUE_URL, ODDS_URL, MATCH_URL, MATCH_RESULT
  11. class Zuqiupipeline(object):
  12. def open_spider(self, spider):
  13. # self.connection = AsyncIOMotorClient("mongodb://{}:{}@{}:{}/database?authSource={}".format('kaiyou', 'kaiyou', '192.168.2.200', 27017, 'kaiyou'))
  14. # session = aiohttp.ClientSession()
  15. self.mongo = pymongo.MongoClient(host=M_HOST, username=M_USER, password=M_PASSWORD, port=M_POST, authSource='kaiyou')
  16. self.db = self.mongo[M_DB]
  17. # self.lock = threading.RLock()
  18. @defer.inlineCallbacks
  19. def process_item(self, item, spider):
  20. out = defer.Deferred()
  21. reactor.callInThread(self._do_calculation, item, out)
  22. yield out
  23. defer.returnValue(item)
  24. # def process_item(self, item, spider):
  25. def _do_calculation(self, item, out):
  26. # with self.lock:
  27. logger = logging.getLogger(__name__)
  28. # 比赛日期
  29. try:
  30. data_game = item['data_game'].split("/")
  31. month = str(data_game[1].strip())
  32. day = str(data_game[0])
  33. except Exception as e:
  34. logger.warning(e)
  35. data_game = item['data_game'].split(" ")
  36. months = str(data_game[1].strip())
  37. month_dict = {'Jan': '01', 'Feb': '02', 'Mar': '03', 'Apr': '04', 'May': '05', 'Jun': '06', 'Jul': '07',
  38. 'Aug': '08', 'Sep': '09', 'Oct': '10', 'Nov': '11', 'Dec': '12'}
  39. month = month_dict[months]
  40. day = str(data_game[0])
  41. # 比赛时间
  42. time_game = str(item['time_game'])
  43. # 比赛时间,时间戳
  44. us_time = str(datetime.datetime.now().year) + "-" + month + "-" + day + " " + time_game + ":00"
  45. # 现在时间,时间戳
  46. utime = time.strftime("%Y-%m-%d %H:%M:%S", time.localtime())
  47. # 比赛id
  48. match_id = item['game_id']
  49. # 联赛id
  50. league_id = item['league_id']
  51. # 联赛name
  52. league_name = item['league_name']
  53. # # 主队
  54. team_home = item['team_home']
  55. # 客队
  56. team_guest = item['team_guest']
  57. # number
  58. tag_number = item['number']
  59. pt = str(item['pt'])
  60. corner_ball = item['corner_ball']
  61. match_date, match_time, time3 = new_time(us_time)
  62. # 联赛接口写入
  63. last_time = '{}-12-31 23:59:59'.format(datetime.datetime.now().year)
  64. league_list = []
  65. uuid = Helper.genearte_uuid(league_name + 'hg3535')
  66. if self.db.zq_league35.find({'lg_id': league_id}).count() < 1:
  67. league_dict = {"game_code": "zq", "title": "league", "source": "hg3535"}
  68. league_key = ["name_chinese", "kind", "match_mode", "if_stop", "last_time", "lg_id", "source", "uuid"]
  69. league_value = [league_name, "1", "1", "0", last_time, league_id, "hg3535", uuid]
  70. league_data = dict(zip(league_key, league_value))
  71. league_list.append(league_data)
  72. league_dict['data'] = league_list
  73. res = Helper.async_post(LEAGUE_URL, league_dict)
  74. if res:
  75. if "成功" in res:
  76. self.db.zq_league35.insert(league_list)
  77. else:
  78. logging.warning('足球详细赔率接口异常, {}'.format(res))
  79. else:
  80. logging.info('{},联赛已存在, 不提交'.format(league_name))
  81. pt_dict = {'1': 'is_today', '2': 'is_morningplate', '3': 'is_stringscene', '4': 'is_rollball'}
  82. pt_status = pt_dict[pt]
  83. if pt == '3':
  84. is_rollball = 0
  85. is_today = 0
  86. is_morningplate = 0
  87. is_stringscene = 1
  88. elif pt == '2':
  89. is_rollball = 0
  90. is_today = 0
  91. is_morningplate = 1
  92. is_stringscene = 0
  93. else:
  94. is_today = 1
  95. is_rollball = 0
  96. is_morningplate = 0
  97. is_stringscene = 0
  98. match_list = []
  99. if self.db.zq_competition35.find({'match_id': match_id, pt_status: 1}).count() < 1:
  100. match_dict = {"game_code": "zq", "title": "match", "source": "hg3535"}
  101. match_kay = ["home_team", "guest_team", "lg_id", "status", "match_id", "match_date", "match_time",
  102. "tag", "source", "is_rollball", "is_morningplate", "is_stringscene", "us_time", "uuid",
  103. "half_match_id", "is_today", "is_horn"]
  104. match_value = [team_home, team_guest, league_id, 0, match_id, match_date, match_time, tag_number,
  105. "hg3535", is_rollball, is_morningplate, is_stringscene, us_time, uuid, 0, is_today, 0]
  106. match_data = dict(zip(match_kay, match_value))
  107. match_list.append(match_data)
  108. match_dict['data'] = match_list
  109. res = Helper.async_post(MATCH_URL, match_dict)
  110. if res:
  111. if "成功" in res:
  112. self.db.zq_competition35.insert(match_data)
  113. else:
  114. logger.warning('足球赛事表提交失败, {}'.format(res))
  115. logger.warning(match_dict)
  116. else:
  117. logger.warning('足球赛事接口异常提交失败, {}'.format(res))
  118. logger.warning(match_dict)
  119. else:
  120. logger.info('足球赛事已存在,不提交')
  121. p_code = "GS"
  122. half_size_guest = item["half_size_guest"]
  123. half_size_guest_rule = item["half_size_guest_rule"]
  124. half_size_home = item["half_size_home"]
  125. half_size_home_rule = item["half_size_home_rule"]
  126. # # zuqiu = item['zuqiu']
  127. data_list = []
  128. odds_onlys = []
  129. # half_size_guest
  130. for index, value in enumerate(half_size_guest):
  131. hash_str = p_code + "gss_h" + str(index) + str(half_size_guest_rule[index]) + str(
  132. value) + "hg3535" + str(match_id)
  133. sole_str = p_code + "gss_h" + str(index) + str(match_id) + "hg3535"
  134. odds_only = Helper.genearte_MD5(hash_str, pt)
  135. sole = Helper.genearte_MD5(sole_str, pt)
  136. half_size_guest_key = ["match_id", "lg_id", "odds_code", "status", "sort", "p_code", "odds", "condition",
  137. "odds_only", "sole", "source", "type", "team"]
  138. condition = half_size_guest_rule[index]
  139. half_size_guest_value = [match_id, league_id, "gss_h", "0", index, p_code, value, condition,
  140. odds_only, sole, "hg3535", "0", ""]
  141. half_size_guest_data = dict(zip(half_size_guest_key, half_size_guest_value))
  142. data_list.append(half_size_guest_data)
  143. # half_size_home
  144. for index, value in enumerate(half_size_home):
  145. hash_str = p_code + "gsb_h" + str(index) + str(half_size_home_rule[index]) + str(
  146. value) + "hg3535" + str(match_id)
  147. sole_str = p_code + "gsb_h" + str(index) + str(match_id) + "hg3535"
  148. odds_only = Helper.genearte_MD5(hash_str, pt)
  149. sole = Helper.genearte_MD5(sole_str, pt)
  150. half_size_home_key = ["match_id", "lg_id", "odds_code", "status", "sort", "p_code", "odds", "condition",
  151. "odds_only", "sole", "source", "type", "team"]
  152. condition = half_size_home_rule[index]
  153. half_size_home_value = [match_id, league_id, "gsb_h", "0", index, p_code, value, condition,
  154. odds_only, sole, "hg3535", "0", ""]
  155. half_size_home_data = dict(zip(half_size_home_key, half_size_home_value))
  156. data_list.append(half_size_home_data)
  157. # 全场场大小
  158. size_guest = item["size_guest"]
  159. size_guest_rule = item["size_guest_rule"]
  160. size_home = item["size_home"]
  161. size_home_rule = item["size_home_rule"]
  162. # size_home
  163. for index, value in enumerate(size_home):
  164. hash_str = p_code + "gsb" + str(index) + str(size_home_rule[index]) + str(value) + "hg3535" + str(
  165. match_id)
  166. sole_str = p_code + "gsb" + str(index) + str(match_id) + "hg3535"
  167. odds_only = Helper.genearte_MD5(hash_str, pt)
  168. sole = Helper.genearte_MD5(sole_str, pt)
  169. size_home_key = ["match_id", "lg_id", "odds_code", "status", "sort", "p_code", "odds", "condition",
  170. "odds_only", "sole", "source", "type", "team"]
  171. condition = size_home_rule[index]
  172. size_home_value = [match_id, league_id, "gsb", "0", index, p_code, value, condition, odds_only,
  173. sole, "hg3535", "0", ""]
  174. size_home_data = dict(zip(size_home_key, size_home_value))
  175. data_list.append(size_home_data)
  176. # size_guest
  177. for index, value in enumerate(size_guest):
  178. hash_str = p_code + "gss" + str(index) + str(size_guest_rule[index]) + str(value) + "hg3535" + str(
  179. match_id)
  180. sole_str = p_code + "gss" + str(index) + str(match_id) + "hg3535"
  181. odds_only = Helper.genearte_MD5(hash_str, pt)
  182. sole = Helper.genearte_MD5(sole_str, pt)
  183. size_guest_key = ["match_id", "lg_id", "odds_code", "status", "sort", "p_code", "odds", "condition",
  184. "odds_only", "sole", "source", "type", "team"]
  185. condition = size_guest_rule[index]
  186. size_guest_value = [match_id, league_id, "gss", "0", index, p_code, value, condition, odds_only,
  187. sole, "hg3535", "0", ""]
  188. size_home_data = dict(zip(size_guest_key, size_guest_value))
  189. data_list.append(size_home_data)
  190. p_code = 'CO'
  191. half_concede_home_rule = item["half_concede_home_rule"]
  192. half_concede_home = item["half_concede_home"]
  193. half_concede_guest_rule = item["half_concede_guest_rule"]
  194. half_concede_guest = item["half_concede_guest"]
  195. # half_concede_home
  196. if half_concede_guest:
  197. for index, value in enumerate(half_concede_guest):
  198. hash_str = p_code + "cog_h" + str(index) + str(half_concede_guest_rule[index]) + str(
  199. value) + "hg3535" + str(match_id)
  200. sole_str = p_code + "cog_h" + str(index) + str(match_id) + "hg3535"
  201. odds_only = Helper.genearte_MD5(hash_str, pt)
  202. sole = Helper.genearte_MD5(sole_str, pt)
  203. half_concede_guest_key = ["match_id", "lg_id", "odds_code", "status", "sort", "p_code", "odds", "condition",
  204. "odds_only", "sole", "source", "type", "team"]
  205. condition = half_concede_guest_rule[index]
  206. half_concede_guest_value = [match_id, league_id, "cog_h", "0", index, p_code, value, condition,
  207. odds_only, sole, "hg3535", "0", ""]
  208. half_concede_guest_data = dict(zip(half_concede_guest_key, half_concede_guest_value))
  209. data_list.append(half_concede_guest_data)
  210. # half_concede_home
  211. if half_concede_home:
  212. for index, value in enumerate(half_concede_home):
  213. hash_str = p_code + "coh_h" + str(index) + str(half_concede_home_rule[index]) + str(
  214. value) + "hg3535" + str(match_id)
  215. sole_str = p_code + "coh_h" + str(index) + str(match_id) + "hg3535"
  216. odds_only = Helper.genearte_MD5(hash_str, pt)
  217. sole = Helper.genearte_MD5(sole_str, pt)
  218. half_concede_home_key = ["match_id", "lg_id", "odds_code", "status", "sort", "p_code", "odds", "condition",
  219. "odds_only", "sole", "source", "type", "team"]
  220. condition = half_concede_home_rule[index]
  221. half_concede_home_value = [match_id, league_id, "coh_h", "0", index, p_code, value, condition,
  222. odds_only, sole, "hg3535", "0", ""]
  223. half_concede_home_data = dict(zip(half_concede_home_key, half_concede_home_value))
  224. data_list.append(half_concede_home_data)
  225. concede_guest = item["concede_guest"]
  226. concede_guest_rule = item["concede_guest_rule"]
  227. concede_home = item["concede_home"]
  228. concede_home_rule = item["concede_home_rule"]
  229. # concede_guest
  230. if concede_guest:
  231. for index, value in enumerate(concede_guest):
  232. hash_str = p_code + "cog" + str(index) + str(concede_guest_rule[index]) + str(
  233. value) + "hg3535" + str(match_id)
  234. sole_str = p_code + "cog" + str(index) + str(match_id) + "hg3535"
  235. odds_only = Helper.genearte_MD5(hash_str, pt)
  236. sole = Helper.genearte_MD5(sole_str, pt)
  237. concede_guest_key = ["match_id", "lg_id", "odds_code", "status", "sort", "p_code", "odds", "condition",
  238. "odds_only", "sole", "source", "type", "team"]
  239. condition = concede_guest_rule[index]
  240. concede_guest_value = [match_id, league_id, "cog", "0", index, p_code, value, condition,
  241. odds_only, sole, "hg3535", "0", ""]
  242. concede_guest_data = dict(zip(concede_guest_key, concede_guest_value))
  243. data_list.append(concede_guest_data)
  244. # concede_home
  245. if concede_home:
  246. for index, value in enumerate(concede_home):
  247. hash_str = p_code + "coh" + str(index) + str(concede_home_rule[index]) + str(
  248. value) + "hg3535" + str(match_id)
  249. sole_str = p_code + "coh" + str(index) + str(match_id) + "hg3535"
  250. odds_only = Helper.genearte_MD5(hash_str, pt)
  251. sole = Helper.genearte_MD5(sole_str, pt)
  252. concede_home_key = ["match_id", "lg_id", "odds_code", "status", "sort", "p_code", "odds", "condition",
  253. "odds_only", "sole", "source", "type", "team"]
  254. condition = concede_home_rule[index]
  255. concede_home_value = [match_id, league_id, "coh", "0", index, p_code, value, condition, odds_only,
  256. sole, "hg3535", "0", ""]
  257. concede_guest_data = dict(zip(concede_home_key, concede_home_value))
  258. data_list.append(concede_guest_data)
  259. # 独赢----------------------------------------------------------------------------------------------------------
  260. p_code = 'C'
  261. half_capot_home = item["half_capot_home"]
  262. half_capot_guest = item["half_capot_guest"]
  263. half_capot_dogfall = item["half_capot_dogfall"]
  264. capot_home = item["capot_home"]
  265. capot_guest = item["capot_guest"]
  266. capot_dogfall = item["capot_dogfall"]
  267. # half_capot_home
  268. hash_str = p_code + "ch_h" + '0' + '1' + str(half_capot_home) + "hg3535" + str(match_id)
  269. sole_str = p_code + "ch_h" + '0' + str(match_id) + "hg3535"
  270. odds_only = Helper.genearte_MD5(hash_str, pt)
  271. sole = Helper.genearte_MD5(sole_str, pt)
  272. half_capot_home_key = ["match_id", "lg_id", "odds_code", "status", "sort", "p_code", "odds", "condition",
  273. "odds_only", "sole", "source", "type", "team"]
  274. half_capot_home_value = [match_id, league_id, "ch_h", "0", 0, p_code, half_capot_home, '1',
  275. odds_only, sole, "hg3535", "0", ""]
  276. half_capot_homet_data = dict(zip(half_capot_home_key, half_capot_home_value))
  277. data_list.append(half_capot_homet_data)
  278. # half_capot_guest
  279. hash_str = p_code + "cg_h" + '0' + '2' + str(half_capot_guest) + "hg3535" + str(match_id)
  280. sole_str = p_code + "cg_h" + '0' + str(match_id) + "hg3535"
  281. odds_only = Helper.genearte_MD5(hash_str, pt)
  282. sole = Helper.genearte_MD5(sole_str, pt)
  283. half_capot_guest_key = ["match_id", "lg_id", "odds_code", "status", "sort", "p_code", "odds", "condition",
  284. "odds_only", "sole", "source", "type", "team"]
  285. half_capot_guest_value = [match_id, league_id, "cg_h", "0", 0, p_code, half_capot_guest, '2',
  286. odds_only, sole, "hg3535", "0", ""]
  287. half_capot_guest_data = dict(zip(half_capot_guest_key, half_capot_guest_value))
  288. data_list.append(half_capot_guest_data)
  289. # half_capot_dogfall
  290. hash_str = p_code + "cd_h" + '0' + 'X' + str(half_capot_dogfall) + "hg3535" + str(match_id)
  291. sole_str = p_code + "cd_h" + '0' + str(match_id) + "hg3535"
  292. odds_only = Helper.genearte_MD5(hash_str, pt)
  293. sole = Helper.genearte_MD5(sole_str, pt)
  294. half_capot_dogfall_key = ["match_id", "lg_id", "odds_code", "status", "sort", "p_code", "odds", "condition",
  295. "odds_only", "sole", "source", "type", "team"]
  296. half_capot_dogfall_value = [match_id, league_id, "cd_h", "0", 0, p_code, half_capot_dogfall, 'X',
  297. odds_only, sole, "hg3535", "0", ""]
  298. half_capot_dogfall_data = dict(zip(half_capot_dogfall_key, half_capot_dogfall_value))
  299. data_list.append(half_capot_dogfall_data)
  300. # capot_dogfall
  301. hash_str = p_code + "cd" + '0' + 'X' + str(capot_dogfall) + "hg3535" + str(match_id)
  302. sole_str = p_code + "cd" + '0' + str(match_id) + "hg3535"
  303. odds_only = Helper.genearte_MD5(hash_str, pt)
  304. sole = Helper.genearte_MD5(sole_str, pt)
  305. capot_dogfall_key = ["match_id", "lg_id", "odds_code", "status", "sort", "p_code", "odds", "condition",
  306. "odds_only", "sole", "source", "type", "team"]
  307. capot_dogfall_value = [match_id, league_id, "cd", "0", 0, p_code, capot_dogfall, 'X', odds_only,
  308. sole, "hg3535", "0", ""]
  309. capot_dogfall_data = dict(zip(capot_dogfall_key, capot_dogfall_value))
  310. data_list.append(capot_dogfall_data)
  311. # capot_home
  312. hash_str = p_code + "ch" + '0' + '1' + str(capot_home) + "hg3535" + str(match_id)
  313. sole_str = p_code + "ch" + '0' + str(match_id) + "hg3535"
  314. odds_only = Helper.genearte_MD5(hash_str, pt)
  315. sole = Helper.genearte_MD5(sole_str, pt)
  316. capot_home_key = ["match_id", "lg_id", "odds_code", "status", "sort", "p_code", "odds", "condition",
  317. "odds_only", "sole", "source", "type", "team"]
  318. capot_home_value = [match_id, league_id, "ch", "0", 0, p_code, capot_home, '1',
  319. odds_only, sole, "hg3535", "0", ""]
  320. capot_homet_data = dict(zip(capot_home_key, capot_home_value))
  321. data_list.append(capot_homet_data)
  322. # capot_guest
  323. hash_str = p_code + "cg" + '0' + '2' + str(capot_guest) + "hg3535" + str(match_id)
  324. sole_str = p_code + "cg" + '0' + str(match_id) + "hg3535"
  325. odds_only = Helper.genearte_MD5(hash_str, pt)
  326. sole = Helper.genearte_MD5(sole_str, pt)
  327. capot_guest_key = ["match_id", "lg_id", "odds_code", "status", "sort", "p_code", "odds", "condition",
  328. "odds_only", "sole", "source", "type", "team"]
  329. capot_guest_value = [match_id, league_id, "cg", "0", 0, p_code, capot_guest, '2',
  330. odds_only, sole, "hg3535", "0", ""]
  331. capot_guest_data = dict(zip(capot_guest_key, capot_guest_value))
  332. data_list.append(capot_guest_data)
  333. # 入球数单双-----------------------------------------------------------------------------------------------------
  334. # p_code, p_id = get_pcode(corner_ball, 'two_sides')
  335. p_code = 'TS'
  336. odd_even_odd = item["odd_even_odd"]
  337. odd_even_even = item["odd_even_even"]
  338. half_odd_even_odd = item["half_odd_even_odd"]
  339. half_odd_even_even = item["half_odd_even_even"]
  340. # odd_even_odd
  341. hash_str = p_code + "tss" + '0' + '单' + str(odd_even_odd) + "hg3535" + str(match_id)
  342. sole_str = p_code + "tss" + '0' + str(match_id) + "hg3535"
  343. odds_only = Helper.genearte_MD5(hash_str, pt)
  344. sole = Helper.genearte_MD5(sole_str, pt)
  345. single_key = ["match_id", "lg_id", "odds_code", "status", "sort", "p_code", "odds", "condition",
  346. "odds_only", "sole", "source", "type", "team"]
  347. single_value = [match_id, league_id, "tss", "0", 0, p_code, odd_even_odd, '单',
  348. odds_only, sole, "hg3535", "0", ""]
  349. single_data = dict(zip(single_key, single_value))
  350. data_list.append(single_data)
  351. # odd_even_even
  352. hash_str = p_code + "tsd" + '0' + '双' + str(odd_even_even) + "hg3535" + str(match_id)
  353. sole_str = p_code + "tsd" + '0' + str(match_id) + "hg3535"
  354. odds_only = Helper.genearte_MD5(hash_str, pt)
  355. sole = Helper.genearte_MD5(sole_str, pt)
  356. double_key = ["match_id", "lg_id", "odds_code", "status", "sort", "p_code", "odds", "condition",
  357. "odds_only", "sole", "source", "type", "team"]
  358. double_value = [match_id, league_id, "tsd", "0", 0, p_code, odd_even_even, '双',
  359. odds_only, sole, "hg3535", "0", ""]
  360. double_data = dict(zip(double_key, double_value))
  361. data_list.append(double_data)
  362. # half_odd_even_even
  363. hash_str = p_code + "tsd_h" + '0' + '双' + str(half_odd_even_even) + "hg3535" + str(match_id)
  364. sole_str = p_code + "tsd_h" + '0' + str(match_id) + "hg3535"
  365. odds_only = Helper.genearte_MD5(hash_str, pt)
  366. sole = Helper.genearte_MD5(sole_str, pt)
  367. half_double_key = ["match_id", "lg_id", "odds_code", "status", "sort", "p_code", "odds", "condition",
  368. "odds_only", "sole", "source", "type", "team"]
  369. half_double_value = [match_id, league_id, "tsd_h", "0", 0, p_code, half_odd_even_even, '双',
  370. odds_only, sole, "hg3535", "0", ""]
  371. half_double_data = dict(zip(half_double_key, half_double_value))
  372. data_list.append(half_double_data)
  373. # half_odd_even_odd
  374. hash_str = p_code + "tss_h" + '0' + '单' + str(half_odd_even_odd) + "hg3535" + str(match_id)
  375. sole_str = p_code + "tss_h" + '0' + str(match_id) + "hg3535"
  376. odds_only = Helper.genearte_MD5(hash_str, pt)
  377. sole = Helper.genearte_MD5(sole_str, pt)
  378. half_single_key = ["match_id", "lg_id", "odds_code", "status", "sort", "p_code", "odds", "condition",
  379. "odds_only", "sole", "source", "type", "team"]
  380. half_single_value = [match_id, league_id, "tss_h", "0", 0, p_code, half_odd_even_odd, '单', odds_only,
  381. sole, "hg3535", "0", ""]
  382. half_single_data = dict(zip(half_single_key, half_single_value))
  383. data_list.append(half_single_data)
  384. # 总入球数 ------------------------------------------------------------------------------------------------------
  385. p_code = 'TG'
  386. total_goals = item['total_goal']
  387. total_dict = {'tg0': '0-1', 'tg1': '2-3', 'tg2': '4-6','tg3': '7或以上', 'tg0_h': '0', "tg1_h": '1',
  388. "tg2_h": '2', "tg3_h": '3或以上'}
  389. # 全场入球数 单双
  390. # 上半场入球数 单双
  391. for key, value in total_goals.items():
  392. hash_str = p_code + key + '0' + total_dict[key] + str(value) + "hg3535" + str(match_id)
  393. sole_str = p_code + key + '0' + str(match_id) + "hg3535"
  394. odds_only = Helper.genearte_MD5(hash_str, pt)
  395. sole = Helper.genearte_MD5(sole_str, pt)
  396. total_goals_key = ["match_id", "lg_id", "odds_code", "status", "sort", "p_code", "odds", "condition",
  397. "odds_only", "sole", "source", "type", "team"]
  398. total_goals_value = [match_id, league_id, key, "0", 0, p_code, value, total_dict[key], odds_only,
  399. sole, "hg3535", "0", ""]
  400. total_goals_data = dict(zip(total_goals_key, total_goals_value))
  401. data_list.append(total_goals_data)
  402. # 全场半场 ------------------------------------------------------------------------------------------------------
  403. half_fulls = item['half_full']
  404. p_code = 'HF'
  405. full_dict = {"hfhh": "主主", "hfhd": "主和", "hfhg": "主客", "hfdh": "和主",
  406. "hfdd": "和和", "hfdg": "和客", "hfgh": "客主", "hfgd": "客和", "hfgg": "客客"}
  407. if half_fulls:
  408. for key, value in half_fulls.items():
  409. hash_str = p_code + key + '0' + full_dict[key] + str(value) + "hg3535" + str(match_id)
  410. sole_str = p_code + key + '0' + str(match_id) + "hg3535"
  411. odds_only = Helper.genearte_MD5(hash_str, pt)
  412. sole = Helper.genearte_MD5(sole_str, pt)
  413. half_fulls_key = ["match_id", "lg_id", "odds_code", "status", "sort", "p_code", "odds", "condition",
  414. "odds_only", "sole", "source", "type", "team"]
  415. half_fulls_value = [match_id, league_id, key, "0", 0, p_code, value, full_dict[key], odds_only,
  416. sole, "hg3535", "0", ""]
  417. half_fulls_data = dict(zip(half_fulls_key, half_fulls_value))
  418. data_list.append(half_fulls_data)
  419. # 波胆-----------------------------------------------------------------------------------------------------------
  420. bodan_datas = item['bodan_data']
  421. p_code = 'B'
  422. bodan_dict = {"b10": "1-0", "b20": "2-0", "b21": "2-1", "b30": "3-0", "b31": "3-1", "b32": "3-2",
  423. "b40": "4-0", "b41": "4-1", "b42": "4-2", "b43": "4-3", "b01": "0-1", "b02": "0-2",
  424. "b12": "1-2", "b03": "0-3", "b13": "1-3", "b23": "2-3", "b04": "0-4", "b14": "1-4",
  425. "b24": "2-4", "b34": "3-4", "b00": "0-0", "b11": "1-1", "b22": "2-2", "b33": "3-3",
  426. "b44": "4-4", "bo": "其他", "b10_h": "1-0", "b20_h": "2-0", "b21_h": "2-1", "b30_h": "3-0",
  427. "b31_h": "3-1", "b32_h": "3-2", "b01_h": "0-1", "b02_h": "0-2", "b12_h": "1-2", "b03_h": "0-3",
  428. "b13_h": "1-3", "b23_h": "2-3", "b00_h": "0-0", "b11_h": "1-1", "b22_h": "2-2", "b33_h": "3-3",
  429. "bo_h": "其他"}
  430. if bodan_datas:
  431. for key, value in bodan_datas.items():
  432. hash_str = p_code + key + '0' + bodan_dict[key] + str(value) + "hg3535" + str(match_id)
  433. sole_str = p_code + key + '0' + str(match_id) + "hg3535"
  434. odds_only = Helper.genearte_MD5(hash_str, pt)
  435. sole = Helper.genearte_MD5(sole_str, pt)
  436. bodan_dict_key = ["match_id", "lg_id", "odds_code", "status", "sort", "p_code", "odds", "condition",
  437. "odds_only", "sole", "source", "type", "team"]
  438. bodan_dict_value = [match_id, league_id, key, "0", 0, p_code, value, bodan_dict[key], odds_only,
  439. sole, "hg3535", "0", ""]
  440. bodan_dict_data = dict(zip(bodan_dict_key, bodan_dict_value))
  441. data_list.append(bodan_dict_data)
  442. # 最先进球/最后进球 ----------------------------------------------------------------------------------------------
  443. first_last_balls = item['first_last_ball']
  444. # p_code, p_id = get_pcode(corner_ball, 'first_last_ball')
  445. p_code = 'FLB'
  446. first_last_dict = {"flbfh": "最先进球", "flbfg": "最先进球", "flblh": "最后进球", "flblg": "最后进球", "flbn": "没有进球"}
  447. if first_last_balls:
  448. for key, value in first_last_balls.items():
  449. hash_str = p_code + key + '0' + first_last_dict[key] + str(value) + "hg3535" + str(match_id)
  450. sole_str = p_code + key + '0' + str(match_id) + "hg3535"
  451. odds_only = Helper.genearte_MD5(hash_str, pt)
  452. sole = Helper.genearte_MD5(sole_str, pt)
  453. first_last_balls_key = ["match_id", "lg_id", "odds_code", "status", "sort", "p_code", "odds", "condition",
  454. "odds_only", "sole", "source", "type", "team"]
  455. first_last_balls_value = [match_id, league_id, key, "0", 0, p_code, value, first_last_dict[key], odds_only,
  456. sole, "hg3535", "0", ""]
  457. first_last_balls_data = dict(zip(first_last_balls_key, first_last_balls_value))
  458. data_list.append(first_last_balls_data)
  459. # 球队得分大小
  460. p_code = 'TB'
  461. # 全场
  462. full_dicts = item['full_data']
  463. # 上半场
  464. half_dicts = item['half_data']
  465. full_dict_rules = item['full_data_rule']
  466. half_dict_rules = item['half_data_rule']
  467. if full_dicts:
  468. for key, value in full_dicts.items():
  469. hash_str = p_code + key + '0' + full_dict_rules[key] + str(value) + "hg3535" + str(match_id)
  470. sole_str = p_code + key + '0' + str(match_id) + "hg3535"
  471. odds_only = Helper.genearte_MD5(hash_str, pt)
  472. sole = Helper.genearte_MD5(sole_str, pt)
  473. full_dict_rules_key = ["match_id", "lg_id", "odds_code", "status", "sort", "p_code", "odds",
  474. "condition", "odds_only", "sole", "source", "type", "team"]
  475. full_dict_rules_value = [match_id, league_id, key, "0", 0, p_code, value, full_dict_rules[key],
  476. odds_only,sole, "hg3535", "0", ""]
  477. full_dict_rules_data = dict(zip(full_dict_rules_key, full_dict_rules_value))
  478. data_list.append(full_dict_rules_data)
  479. if half_dicts:
  480. for key, value in half_dicts.items():
  481. hash_str = p_code + key + '0' + half_dict_rules[key] + str(value) + "hg3535" + str(match_id)
  482. sole_str = p_code + key + '0' + str(match_id) + "hg3535"
  483. odds_only = Helper.genearte_MD5(hash_str, pt)
  484. sole = Helper.genearte_MD5(sole_str, pt)
  485. half_dicts_key = ["match_id", "lg_id", "odds_code", "status", "sort", "p_code", "odds",
  486. "condition","odds_only", "sole", "source", "type", "team"]
  487. half_dicts_value = [match_id, league_id, key, "0", 0, p_code, value, half_dict_rules[key],
  488. odds_only, sole, "hg3535", "0", ""]
  489. half_dicts_data = dict(zip(half_dicts_key, half_dicts_value))
  490. data_list.append(half_dicts_data)
  491. p_code = 'CB'
  492. horn_ou_dict = item['horn_ou_dict']
  493. horn_ou_dict_rule = item['horn_ou_dict_rule']
  494. horn_oe_dict = item['horn_oe_dict']
  495. horn_oe_dict_rule = item['horn_oe_dict_rule']
  496. if horn_ou_dict:
  497. for key, value in horn_ou_dict.items():
  498. hash_str = p_code + key + '0' + horn_ou_dict_rule[key] + str(value) + "hg3535" + str(match_id)
  499. sole_str = p_code + key + '0' + str(match_id) + "hg3535"
  500. odds_only = Helper.genearte_MD5(hash_str, pt)
  501. sole = Helper.genearte_MD5(sole_str, pt)
  502. horn_ou_key = ["match_id", "lg_id", "odds_code", "status", "sort", "p_code", "odds",
  503. "condition", "odds_only", "sole", "source", "type", "team"]
  504. horn_ou_value = [match_id, league_id, key, "0", 0, p_code, value, horn_ou_dict_rule[key],
  505. odds_only, sole, "hg3535", "0", ""]
  506. horn_ou_data = dict(zip(horn_ou_key, horn_ou_value))
  507. data_list.append(horn_ou_data)
  508. if horn_oe_dict:
  509. for key, value in horn_oe_dict.items():
  510. hash_str = p_code + key + '0' + horn_oe_dict_rule[key] + str(value) + "hg3535" + str(match_id)
  511. sole_str = p_code + key + '0' + str(match_id) + "hg3535"
  512. odds_only = Helper.genearte_MD5(hash_str, pt)
  513. sole = Helper.genearte_MD5(sole_str, pt)
  514. horn_oe_key = ["match_id", "lg_id", "odds_code", "status", "sort", "p_code", "odds",
  515. "condition", "odds_only", "sole", "source", "type", "team"]
  516. horn_oe_value = [match_id, league_id, key, "0", 0, p_code, value, horn_oe_dict_rule[key],
  517. odds_only, sole, "hg3535", "0", ""]
  518. horn_oe_data = dict(zip(horn_oe_key, horn_oe_value))
  519. data_list.append(horn_oe_data)
  520. if pt == '3':
  521. ris_stringscene = 1
  522. else:
  523. ris_stringscene = 0
  524. odds_key = ["game_code", "title", "match_id", "lg_id", "data", "source", "odds_only", "tag", "uuid", "is_stringscene", "utime", "pt"]
  525. odds_value = ["zq", "odds", match_id, league_id, data_list, "hg3535", odds_onlys, tag_number, uuid, ris_stringscene, utime, pt]
  526. odds_dict = dict(zip(odds_key, odds_value))
  527. if data_list:
  528. res = Helper.async_post(ODDS_URL, odds_dict)
  529. if res:
  530. if "成功" in res:
  531. logger.info('足球详细赔率提交成功, {}'.format(res))
  532. logger.info(odds_dict)
  533. else:
  534. logger.warning('足球相信赔率提交失败, {}'.format(res))
  535. logger.warning(odds_dict)
  536. else:
  537. logging.warning('足球详细赔率接口异常, {}'.format(res))
  538. else:
  539. logger.info('足球详细赔率列表为空')
  540. # 角球处理分割线---------------------------------------------------------------------------------------------------
  541. horn_team = item['horn_team']
  542. if horn_team:
  543. team_home = horn_team['horn_home']
  544. team_guest = horn_team['horn_guest']
  545. match_id = horn_team['horn_id']
  546. match_list = []
  547. if self.db.zq_competition35.find({'match_id': match_id, pt_status: 1}).count() < 1:
  548. match_dict = {"game_code": "zq", "title": "match", "source": "hg3535"}
  549. match_kay = ["home_team", "guest_team", "lg_id", "status", "match_id", "match_date", "match_time",
  550. "tag", "source", "is_rollball", "is_morningplate", "is_stringscene", "us_time", "uuid",
  551. "half_match_id", "is_today", 'is_horn']
  552. match_value = [team_home, team_guest, league_id, 0, match_id, match_date, match_time, tag_number,
  553. "hg3535", is_rollball, is_morningplate, is_stringscene, us_time, uuid, 0, is_today, 1]
  554. match_data = dict(zip(match_kay, match_value))
  555. match_list.append(match_data)
  556. match_dict['data'] = match_list
  557. res = Helper.async_post(MATCH_URL, match_dict)
  558. if res:
  559. if "成功" in res:
  560. self.db.zq_competition35.insert(match_data)
  561. logger.info('足球角球, 赛事表提交失败, {}'.format(res))
  562. logger.info(match_dict)
  563. else:
  564. logger.warning('足球角球, 赛事表提交失败, {}'.format(res))
  565. logger.warning(match_dict)
  566. else:
  567. logger.warning('足球角球, 赛事接口异常提交失败, {}'.format(res))
  568. logger.warning(match_dict)
  569. else:
  570. logger.info('足球角球, 赛事已存在,不提交')
  571. p_code = "GS"
  572. half_size_guest = item["half_size_guest"]
  573. half_size_guest_rule = item["half_size_guest_rule"]
  574. half_size_home = item["half_size_home"]
  575. half_size_home_rule = item["half_size_home_rule"]
  576. data_list = []
  577. odds_onlys = []
  578. # half_size_guest
  579. for index, value in enumerate(half_size_guest):
  580. hash_str = p_code + "gss_h" + str(index) + str(half_size_guest_rule[index]) + str(
  581. value) + "hg3535" + str(match_id)
  582. sole_str = p_code + "gss_h" + str(index) + str(match_id) + "hg3535"
  583. odds_only = Helper.genearte_MD5(hash_str, pt)
  584. sole = Helper.genearte_MD5(sole_str, pt)
  585. half_size_guest_key = ["match_id", "lg_id", "odds_code", "status", "sort", "p_code", "odds",
  586. "condition",
  587. "odds_only", "sole", "source", "type", "team"]
  588. condition = half_size_guest_rule[index]
  589. half_size_guest_value = [match_id, league_id, "gss_h", "0", index, p_code, value, condition,
  590. odds_only, sole, "hg3535", "0", ""]
  591. half_size_guest_data = dict(zip(half_size_guest_key, half_size_guest_value))
  592. data_list.append(half_size_guest_data)
  593. # half_size_home
  594. for index, value in enumerate(half_size_home):
  595. hash_str = p_code + "gsb_h" + str(index) + str(half_size_home_rule[index]) + str(
  596. value) + "hg3535" + str(match_id)
  597. sole_str = p_code + "gsb_h" + str(index) + str(match_id) + "hg3535"
  598. odds_only = Helper.genearte_MD5(hash_str, pt)
  599. sole = Helper.genearte_MD5(sole_str, pt)
  600. half_size_home_key = ["match_id", "lg_id", "odds_code", "status", "sort", "p_code", "odds", "condition",
  601. "odds_only", "sole", "source", "type", "team"]
  602. condition = half_size_home_rule[index]
  603. half_size_home_value = [match_id, league_id, "gsb_h", "0", index, p_code, value, condition,
  604. odds_only, sole, "hg3535", "0", ""]
  605. half_size_home_data = dict(zip(half_size_home_key, half_size_home_value))
  606. data_list.append(half_size_home_data)
  607. # 全场场大小
  608. size_guest = item["size_guest"]
  609. size_guest_rule = item["size_guest_rule"]
  610. size_home = item["size_home"]
  611. size_home_rule = item["size_home_rule"]
  612. # size_home
  613. for index, value in enumerate(size_home):
  614. hash_str = p_code + "gsb" + str(index) + str(size_home_rule[index]) + str(value) + "hg3535" + str(
  615. match_id)
  616. sole_str = p_code + "gsb" + str(index) + str(match_id) + "hg3535"
  617. odds_only = Helper.genearte_MD5(hash_str, pt)
  618. sole = Helper.genearte_MD5(sole_str, pt)
  619. size_home_key = ["match_id", "lg_id", "odds_code", "status", "sort", "p_code", "odds", "condition",
  620. "odds_only", "sole", "source", "type", "team"]
  621. condition = size_home_rule[index]
  622. size_home_value = [match_id, league_id, "gsb", "0", index, p_code, value, condition, odds_only,
  623. sole, "hg3535", "0", ""]
  624. size_home_data = dict(zip(size_home_key, size_home_value))
  625. data_list.append(size_home_data)
  626. # size_guest
  627. for index, value in enumerate(size_guest):
  628. hash_str = p_code + "gss" + str(index) + str(size_guest_rule[index]) + str(value) + "hg3535" + str(
  629. match_id)
  630. sole_str = p_code + "gss" + str(index) + str(match_id) + "hg3535"
  631. odds_only = Helper.genearte_MD5(hash_str, pt)
  632. sole = Helper.genearte_MD5(sole_str, pt)
  633. size_guest_key = ["match_id", "lg_id", "odds_code", "status", "sort", "p_code", "odds", "condition",
  634. "odds_only", "sole", "source", "type", "team"]
  635. condition = size_guest_rule[index]
  636. size_guest_value = [match_id, league_id, "gss", "0", index, p_code, value, condition, odds_only,
  637. sole, "hg3535", "0", ""]
  638. size_home_data = dict(zip(size_guest_key, size_guest_value))
  639. data_list.append(size_home_data)
  640. p_code = 'CO'
  641. half_concede_home_rule = item["half_concede_home_rule"]
  642. half_concede_home = item["half_concede_home"]
  643. half_concede_guest_rule = item["half_concede_guest_rule"]
  644. half_concede_guest = item["half_concede_guest"]
  645. # half_concede_home
  646. if half_concede_guest:
  647. for index, value in enumerate(half_concede_guest):
  648. hash_str = p_code + "cog_h" + str(index) + str(half_concede_guest_rule[index]) + str(
  649. value) + "hg3535" + str(match_id)
  650. sole_str = p_code + "cog_h" + str(index) + str(match_id) + "hg3535"
  651. odds_only = Helper.genearte_MD5(hash_str, pt)
  652. sole = Helper.genearte_MD5(sole_str, pt)
  653. half_concede_guest_key = ["match_id", "lg_id", "odds_code", "status", "sort", "p_code", "odds",
  654. "condition",
  655. "odds_only", "sole", "source", "type", "team"]
  656. condition = half_concede_guest_rule[index]
  657. half_concede_guest_value = [match_id, league_id, "cog_h", "0", index, p_code, value, condition,
  658. odds_only, sole, "hg3535", "0", ""]
  659. half_concede_guest_data = dict(zip(half_concede_guest_key, half_concede_guest_value))
  660. data_list.append(half_concede_guest_data)
  661. # half_concede_home
  662. if half_concede_home:
  663. for index, value in enumerate(half_concede_home):
  664. hash_str = p_code + "coh_h" + str(index) + str(half_concede_home_rule[index]) + str(
  665. value) + "hg3535" + str(match_id)
  666. sole_str = p_code + "coh_h" + str(index) + str(match_id) + "hg3535"
  667. odds_only = Helper.genearte_MD5(hash_str, pt)
  668. sole = Helper.genearte_MD5(sole_str, pt)
  669. half_concede_home_key = ["match_id", "lg_id", "odds_code", "status", "sort", "p_code", "odds",
  670. "condition",
  671. "odds_only", "sole", "source", "type", "team"]
  672. condition = half_concede_home_rule[index]
  673. half_concede_home_value = [match_id, league_id, "coh_h", "0", index, p_code, value, condition,
  674. odds_only, sole, "hg3535", "0", ""]
  675. half_concede_home_data = dict(zip(half_concede_home_key, half_concede_home_value))
  676. data_list.append(half_concede_home_data)
  677. concede_guest = item["concede_guest"]
  678. concede_guest_rule = item["concede_guest_rule"]
  679. concede_home = item["concede_home"]
  680. concede_home_rule = item["concede_home_rule"]
  681. # concede_guest
  682. if concede_guest:
  683. for index, value in enumerate(concede_guest):
  684. hash_str = p_code + "cog" + str(index) + str(concede_guest_rule[index]) + str(
  685. value) + "hg3535" + str(match_id)
  686. sole_str = p_code + "cog" + str(index) + str(match_id) + "hg3535"
  687. odds_only = Helper.genearte_MD5(hash_str, pt)
  688. sole = Helper.genearte_MD5(sole_str, pt)
  689. concede_guest_key = ["match_id", "lg_id", "odds_code", "status", "sort", "p_code", "odds",
  690. "condition",
  691. "odds_only", "sole", "source", "type", "team"]
  692. condition = concede_guest_rule[index]
  693. concede_guest_value = [match_id, league_id, "cog", "0", index, p_code, value, condition,
  694. odds_only, sole, "hg3535", "0", ""]
  695. concede_guest_data = dict(zip(concede_guest_key, concede_guest_value))
  696. data_list.append(concede_guest_data)
  697. # concede_home
  698. if concede_home:
  699. for index, value in enumerate(concede_home):
  700. hash_str = p_code + "coh" + str(index) + str(concede_home_rule[index]) + str(
  701. value) + "hg3535" + str(match_id)
  702. sole_str = p_code + "coh" + str(index) + str(match_id) + "hg3535"
  703. odds_only = Helper.genearte_MD5(hash_str, pt)
  704. sole = Helper.genearte_MD5(sole_str, pt)
  705. concede_home_key = ["match_id", "lg_id", "odds_code", "status", "sort", "p_code", "odds",
  706. "condition",
  707. "odds_only", "sole", "source", "type", "team"]
  708. condition = concede_home_rule[index]
  709. concede_home_value = [match_id, league_id, "coh", "0", index, p_code, value, condition, odds_only,
  710. sole, "hg3535", "0", ""]
  711. concede_guest_data = dict(zip(concede_home_key, concede_home_value))
  712. data_list.append(concede_guest_data)
  713. # 独赢----------------------------------------------------------------------------------------------------------
  714. p_code = 'C'
  715. half_capot_home = item["half_capot_home"]
  716. half_capot_guest = item["half_capot_guest"]
  717. half_capot_dogfall = item["half_capot_dogfall"]
  718. capot_home = item["capot_home"]
  719. capot_guest = item["capot_guest"]
  720. capot_dogfall = item["capot_dogfall"]
  721. # half_capot_home
  722. hash_str = p_code + "ch_h" + '0' + '1' + str(half_capot_home) + "hg3535" + str(match_id)
  723. sole_str = p_code + "ch_h" + '0' + str(match_id) + "hg3535"
  724. odds_only = Helper.genearte_MD5(hash_str, pt)
  725. sole = Helper.genearte_MD5(sole_str, pt)
  726. half_capot_home_key = ["match_id", "lg_id", "odds_code", "status", "sort", "p_code", "odds", "condition",
  727. "odds_only", "sole", "source", "type", "team"]
  728. half_capot_home_value = [match_id, league_id, "ch_h", "0", 0, p_code, half_capot_home, '1',
  729. odds_only, sole, "hg3535", "0", ""]
  730. half_capot_homet_data = dict(zip(half_capot_home_key, half_capot_home_value))
  731. data_list.append(half_capot_homet_data)
  732. # half_capot_guest
  733. hash_str = p_code + "cg_h" + '0' + '2' + str(half_capot_guest) + "hg3535" + str(match_id)
  734. sole_str = p_code + "cg_h" + '0' + str(match_id) + "hg3535"
  735. odds_only = Helper.genearte_MD5(hash_str, pt)
  736. sole = Helper.genearte_MD5(sole_str, pt)
  737. half_capot_guest_key = ["match_id", "lg_id", "odds_code", "status", "sort", "p_code", "odds", "condition",
  738. "odds_only", "sole", "source", "type", "team"]
  739. half_capot_guest_value = [match_id, league_id, "cg_h", "0", 0, p_code, half_capot_guest, '2',
  740. odds_only, sole, "hg3535", "0", ""]
  741. half_capot_guest_data = dict(zip(half_capot_guest_key, half_capot_guest_value))
  742. data_list.append(half_capot_guest_data)
  743. # half_capot_dogfall
  744. hash_str = p_code + "cd_h" + '0' + 'X' + str(half_capot_dogfall) + "hg3535" + str(match_id)
  745. sole_str = p_code + "cd_h" + '0' + str(match_id) + "hg3535"
  746. odds_only = Helper.genearte_MD5(hash_str, pt)
  747. sole = Helper.genearte_MD5(sole_str, pt)
  748. half_capot_dogfall_key = ["match_id", "lg_id", "odds_code", "status", "sort", "p_code", "odds", "condition",
  749. "odds_only", "sole", "source", "type", "team"]
  750. half_capot_dogfall_value = [match_id, league_id, "cd_h", "0", 0, p_code, half_capot_dogfall, 'X',
  751. odds_only, sole, "hg3535", "0", ""]
  752. half_capot_dogfall_data = dict(zip(half_capot_dogfall_key, half_capot_dogfall_value))
  753. data_list.append(half_capot_dogfall_data)
  754. # capot_dogfall
  755. hash_str = p_code + "cd" + '0' + 'X' + str(capot_dogfall) + "hg3535" + str(match_id)
  756. sole_str = p_code + "cd" + '0' + str(match_id) + "hg3535"
  757. odds_only = Helper.genearte_MD5(hash_str, pt)
  758. sole = Helper.genearte_MD5(sole_str, pt)
  759. capot_dogfall_key = ["match_id", "lg_id", "odds_code", "status", "sort", "p_code", "odds", "condition",
  760. "odds_only", "sole", "source", "type", "team"]
  761. capot_dogfall_value = [match_id, league_id, "cd", "0", 0, p_code, capot_dogfall, 'X', odds_only,
  762. sole, "hg3535", "0", ""]
  763. capot_dogfall_data = dict(zip(capot_dogfall_key, capot_dogfall_value))
  764. data_list.append(capot_dogfall_data)
  765. # capot_home
  766. hash_str = p_code + "ch" + '0' + '1' + str(capot_home) + "hg3535" + str(match_id)
  767. sole_str = p_code + "ch" + '0' + str(match_id) + "hg3535"
  768. odds_only = Helper.genearte_MD5(hash_str, pt)
  769. sole = Helper.genearte_MD5(sole_str, pt)
  770. capot_home_key = ["match_id", "lg_id", "odds_code", "status", "sort", "p_code", "odds", "condition",
  771. "odds_only", "sole", "source", "type", "team"]
  772. capot_home_value = [match_id, league_id, "ch", "0", 0, p_code, capot_home, '1',
  773. odds_only, sole, "hg3535", "0", ""]
  774. capot_homet_data = dict(zip(capot_home_key, capot_home_value))
  775. data_list.append(capot_homet_data)
  776. # capot_guest
  777. hash_str = p_code + "cg" + '0' + '2' + str(capot_guest) + "hg3535" + str(match_id)
  778. sole_str = p_code + "cg" + '0' + str(match_id) + "hg3535"
  779. odds_only = Helper.genearte_MD5(hash_str, pt)
  780. sole = Helper.genearte_MD5(sole_str, pt)
  781. capot_guest_key = ["match_id", "lg_id", "odds_code", "status", "sort", "p_code", "odds", "condition",
  782. "odds_only", "sole", "source", "type", "team"]
  783. capot_guest_value = [match_id, league_id, "cg", "0", 0, p_code, capot_guest, '2',
  784. odds_only, sole, "hg3535", "0", ""]
  785. capot_guest_data = dict(zip(capot_guest_key, capot_guest_value))
  786. data_list.append(capot_guest_data)
  787. # 入球数单双-----------------------------------------------------------------------------------------------------
  788. # p_code, p_id = get_pcode(corner_ball, 'two_sides')
  789. p_code = 'TS'
  790. odd_even_odd = item["odd_even_odd"]
  791. odd_even_even = item["odd_even_even"]
  792. half_odd_even_odd = item["half_odd_even_odd"]
  793. half_odd_even_even = item["half_odd_even_even"]
  794. # odd_even_odd
  795. hash_str = p_code + "tss" + '0' + '单' + str(odd_even_odd) + "hg3535" + str(match_id)
  796. sole_str = p_code + "tss" + '0' + str(match_id) + "hg3535"
  797. odds_only = Helper.genearte_MD5(hash_str, pt)
  798. sole = Helper.genearte_MD5(sole_str, pt)
  799. single_key = ["match_id", "lg_id", "odds_code", "status", "sort", "p_code", "odds", "condition",
  800. "odds_only", "sole", "source", "type", "team"]
  801. single_value = [match_id, league_id, "tss", "0", 0, p_code, odd_even_odd, '单',
  802. odds_only, sole, "hg3535", "0", ""]
  803. single_data = dict(zip(single_key, single_value))
  804. data_list.append(single_data)
  805. # odd_even_even
  806. hash_str = p_code + "tsd" + '0' + '双' + str(odd_even_even) + "hg3535" + str(match_id)
  807. sole_str = p_code + "tsd" + '0' + str(match_id) + "hg3535"
  808. odds_only = Helper.genearte_MD5(hash_str, pt)
  809. sole = Helper.genearte_MD5(sole_str, pt)
  810. double_key = ["match_id", "lg_id", "odds_code", "status", "sort", "p_code", "odds", "condition",
  811. "odds_only", "sole", "source", "type", "team"]
  812. double_value = [match_id, league_id, "tsd", "0", 0, p_code, odd_even_even, '双',
  813. odds_only, sole, "hg3535", "0", ""]
  814. double_data = dict(zip(double_key, double_value))
  815. data_list.append(double_data)
  816. # half_odd_even_even
  817. hash_str = p_code + "tsd_h" + '0' + '双' + str(half_odd_even_even) + "hg3535" + str(match_id)
  818. sole_str = p_code + "tsd_h" + '0' + str(match_id) + "hg3535"
  819. odds_only = Helper.genearte_MD5(hash_str, pt)
  820. sole = Helper.genearte_MD5(sole_str, pt)
  821. half_double_key = ["match_id", "lg_id", "odds_code", "status", "sort", "p_code", "odds", "condition",
  822. "odds_only", "sole", "source", "type", "team"]
  823. half_double_value = [match_id, league_id, "tsd_h", "0", 0, p_code, half_odd_even_even, '双',
  824. odds_only, sole, "hg3535", "0", ""]
  825. half_double_data = dict(zip(half_double_key, half_double_value))
  826. data_list.append(half_double_data)
  827. # half_odd_even_odd
  828. hash_str = p_code + "tss_h" + '0' + '单' + str(half_odd_even_odd) + "hg3535" + str(match_id)
  829. sole_str = p_code + "tss_h" + '0' + str(match_id) + "hg3535"
  830. odds_only = Helper.genearte_MD5(hash_str, pt)
  831. sole = Helper.genearte_MD5(sole_str, pt)
  832. half_single_key = ["match_id", "lg_id", "odds_code", "status", "sort", "p_code", "odds", "condition",
  833. "odds_only", "sole", "source", "type", "team"]
  834. half_single_value = [match_id, league_id, "tss_h", "0", 0, p_code, half_odd_even_odd, '单', odds_only,
  835. sole, "hg3535", "0", ""]
  836. half_single_data = dict(zip(half_single_key, half_single_value))
  837. data_list.append(half_single_data)
  838. # 总入球数 ---------------------------------------------------------------------------------------------------
  839. p_code = 'TG'
  840. total_goals = item['total_goal']
  841. total_dict = {'tg0': '0-1', 'tg1': '2-3', 'tg2': '4-6', 'tg3': '7或以上', 'tg0_h': '0', "tg1_h": '1',
  842. "tg2_h": '2', "tg3_h": '3或以上'}
  843. # 全场入球数 单双
  844. # 上半场入球数 单双
  845. for key, value in total_goals.items():
  846. hash_str = p_code + key + '0' + total_dict[key] + str(value) + "hg3535" + str(match_id)
  847. sole_str = p_code + key + '0' + str(match_id) + "hg3535"
  848. odds_only = Helper.genearte_MD5(hash_str, pt)
  849. sole = Helper.genearte_MD5(sole_str, pt)
  850. total_goals_key = ["match_id", "lg_id", "odds_code", "status", "sort", "p_code", "odds", "condition",
  851. "odds_only", "sole", "source", "type", "team"]
  852. total_goals_value = [match_id, league_id, key, "0", 0, p_code, value, total_dict[key], odds_only,
  853. sole, "hg3535", "0", ""]
  854. total_goals_data = dict(zip(total_goals_key, total_goals_value))
  855. data_list.append(total_goals_data)
  856. # 全场半场 ---------------------------------------------------------------------------------------------------
  857. half_fulls = item['half_full']
  858. p_code = 'HF'
  859. full_dict = {"hfhh": "主主", "hfhd": "主和", "hfhg": "主客", "hfdh": "和主",
  860. "hfdd": "和和", "hfdg": "和客", "hfgh": "客主", "hfgd": "客和", "hfgg": "客客"}
  861. if half_fulls:
  862. for key, value in half_fulls.items():
  863. hash_str = p_code + key + '0' + full_dict[key] + str(value) + "hg3535" + str(match_id)
  864. sole_str = p_code + key + '0' + str(match_id) + "hg3535"
  865. odds_only = Helper.genearte_MD5(hash_str, pt)
  866. sole = Helper.genearte_MD5(sole_str, pt)
  867. half_fulls_key = ["match_id", "lg_id", "odds_code", "status", "sort", "p_code", "odds", "condition",
  868. "odds_only", "sole", "source", "type", "team"]
  869. half_fulls_value = [match_id, league_id, key, "0", 0, p_code, value, full_dict[key], odds_only,
  870. sole, "hg3535", "0", ""]
  871. half_fulls_data = dict(zip(half_fulls_key, half_fulls_value))
  872. data_list.append(half_fulls_data)
  873. # 波胆-----------------------------------------------------------------------------------------------------------
  874. bodan_datas = item['bodan_data']
  875. p_code = 'B'
  876. bodan_dict = {"b10": "1-0", "b20": "2-0", "b21": "2-1", "b30": "3-0", "b31": "3-1", "b32": "3-2",
  877. "b40": "4-0", "b41": "4-1", "b42": "4-2", "b43": "4-3", "b01": "0-1", "b02": "0-2",
  878. "b12": "1-2", "b03": "0-3", "b13": "1-3", "b23": "2-3", "b04": "0-4", "b14": "1-4",
  879. "b24": "2-4", "b34": "3-4", "b00": "0-0", "b11": "1-1", "b22": "2-2", "b33": "3-3",
  880. "b44": "4-4", "bo": "其他", "b10_h": "1-0", "b20_h": "2-0", "b21_h": "2-1", "b30_h": "3-0",
  881. "b31_h": "3-1", "b32_h": "3-2", "b01_h": "0-1", "b02_h": "0-2", "b12_h": "1-2",
  882. "b03_h": "0-3",
  883. "b13_h": "1-3", "b23_h": "2-3", "b00_h": "0-0", "b11_h": "1-1", "b22_h": "2-2",
  884. "b33_h": "3-3",
  885. "bo_h": "其他"}
  886. if bodan_datas:
  887. for key, value in bodan_datas.items():
  888. hash_str = p_code + key + '0' + bodan_dict[key] + str(value) + "hg3535" + str(match_id)
  889. sole_str = p_code + key + '0' + str(match_id) + "hg3535"
  890. odds_only = Helper.genearte_MD5(hash_str, pt)
  891. sole = Helper.genearte_MD5(sole_str, pt)
  892. bodan_dict_key = ["match_id", "lg_id", "odds_code", "status", "sort", "p_code", "odds", "condition",
  893. "odds_only", "sole", "source", "type", "team"]
  894. bodan_dict_value = [match_id, league_id, key, "0", 0, p_code, value, bodan_dict[key], odds_only,
  895. sole, "hg3535", "0", ""]
  896. bodan_dict_data = dict(zip(bodan_dict_key, bodan_dict_value))
  897. data_list.append(bodan_dict_data)
  898. # 最先进球/最后进球 ----------------------------------------------------------------------------------------------
  899. first_last_balls = item['first_last_ball']
  900. # p_code, p_id = get_pcode(corner_ball, 'first_last_ball')
  901. p_code = 'FLB'
  902. first_last_dict = {"flbfh": "最先进球", "flbfg": "最先进球", "flblh": "最后进球", "flblg": "最后进球", "flbn": "没有进球"}
  903. if first_last_balls:
  904. for key, value in first_last_balls.items():
  905. hash_str = p_code + key + '0' + first_last_dict[key] + str(value) + "hg3535" + str(match_id)
  906. sole_str = p_code + key + '0' + str(match_id) + "hg3535"
  907. odds_only = Helper.genearte_MD5(hash_str, pt)
  908. sole = Helper.genearte_MD5(sole_str, pt)
  909. first_last_balls_key = ["match_id", "lg_id", "odds_code", "status", "sort", "p_code", "odds",
  910. "condition",
  911. "odds_only", "sole", "source", "type", "team"]
  912. first_last_balls_value = [match_id, league_id, key, "0", 0, p_code, value, first_last_dict[key],
  913. odds_only,
  914. sole, "hg3535", "0", ""]
  915. first_last_balls_data = dict(zip(first_last_balls_key, first_last_balls_value))
  916. data_list.append(first_last_balls_data)
  917. # 球队得分大小
  918. p_code = 'TB'
  919. # 全场
  920. full_dicts = item['full_data']
  921. # 上半场
  922. half_dicts = item['half_data']
  923. full_dict_rules = item['full_data_rule']
  924. half_dict_rules = item['half_data_rule']
  925. if full_dicts:
  926. for key, value in full_dicts.items():
  927. hash_str = p_code + key + '0' + full_dict_rules[key] + str(value) + "hg3535" + str(match_id)
  928. sole_str = p_code + key + '0' + str(match_id) + "hg3535"
  929. odds_only = Helper.genearte_MD5(hash_str, pt)
  930. sole = Helper.genearte_MD5(sole_str, pt)
  931. full_dict_rules_key = ["match_id", "lg_id", "odds_code", "status", "sort", "p_code", "odds",
  932. "condition", "odds_only", "sole", "source", "type", "team"]
  933. full_dict_rules_value = [match_id, league_id, key, "0", 0, p_code, value, full_dict_rules[key],
  934. odds_only, sole, "hg3535", "0", ""]
  935. full_dict_rules_data = dict(zip(full_dict_rules_key, full_dict_rules_value))
  936. data_list.append(full_dict_rules_data)
  937. if half_dicts:
  938. for key, value in half_dicts.items():
  939. hash_str = p_code + key + '0' + half_dict_rules[key] + str(value) + "hg3535" + str(match_id)
  940. sole_str = p_code + key + '0' + str(match_id) + "hg3535"
  941. odds_only = Helper.genearte_MD5(hash_str, pt)
  942. sole = Helper.genearte_MD5(sole_str, pt)
  943. half_dicts_key = ["match_id", "lg_id", "odds_code", "status", "sort", "p_code", "odds",
  944. "condition", "odds_only", "sole", "source", "type", "team"]
  945. half_dicts_value = [match_id, league_id, key, "0", 0, p_code, value, half_dict_rules[key],
  946. odds_only, sole, "hg3535", "0", ""]
  947. half_dicts_data = dict(zip(half_dicts_key, half_dicts_value))
  948. data_list.append(half_dicts_data)
  949. p_code = 'CB'
  950. horn_ou_dict = item['horn_ou_dict']
  951. horn_ou_dict_rule = item['horn_ou_dict_rule']
  952. horn_oe_dict = item['horn_oe_dict']
  953. horn_oe_dict_rule = item['horn_oe_dict_rule']
  954. if horn_ou_dict:
  955. for key, value in horn_ou_dict.items():
  956. hash_str = p_code + key + '0' + horn_ou_dict_rule[key] + str(value) + "hg3535" + str(match_id)
  957. sole_str = p_code + key + '0' + str(match_id) + "hg3535"
  958. odds_only = Helper.genearte_MD5(hash_str, pt)
  959. sole = Helper.genearte_MD5(sole_str, pt)
  960. horn_ou_key = ["match_id", "lg_id", "odds_code", "status", "sort", "p_code", "odds",
  961. "condition", "odds_only", "sole", "source", "type", "team"]
  962. horn_ou_value = [match_id, league_id, key, "0", 0, p_code, value, horn_ou_dict_rule[key],
  963. odds_only, sole, "hg3535", "0", ""]
  964. horn_ou_data = dict(zip(horn_ou_key, horn_ou_value))
  965. data_list.append(horn_ou_data)
  966. if horn_oe_dict:
  967. for key, value in horn_oe_dict.items():
  968. hash_str = p_code + key + '0' + horn_oe_dict_rule[key] + str(value) + "hg3535" + str(match_id)
  969. sole_str = p_code + key + '0' + str(match_id) + "hg3535"
  970. odds_only = Helper.genearte_MD5(hash_str, pt)
  971. sole = Helper.genearte_MD5(sole_str, pt)
  972. horn_oe_key = ["match_id", "lg_id", "odds_code", "status", "sort", "p_code", "odds",
  973. "condition", "odds_only", "sole", "source", "type", "team"]
  974. horn_oe_value = [match_id, league_id, key, "0", 0, p_code, value, horn_oe_dict_rule[key],
  975. odds_only, sole, "hg3535", "0", ""]
  976. horn_oe_data = dict(zip(horn_oe_key, horn_oe_value))
  977. data_list.append(horn_oe_data)
  978. if pt == '3':
  979. ris_stringscene = 1
  980. else:
  981. ris_stringscene = 0
  982. odds_key = ["game_code", "title", "match_id", "lg_id", "data", "source", "odds_only", "tag", "uuid",
  983. "is_stringscene", "utime", "pt"]
  984. odds_value = ["zq", "odds", match_id, league_id, data_list, "hg3535", odds_onlys, tag_number, uuid,
  985. ris_stringscene, utime, pt]
  986. odds_dict = dict(zip(odds_key, odds_value))
  987. if data_list:
  988. res = Helper.async_post(ODDS_URL, odds_dict)
  989. if res:
  990. if "成功" in res:
  991. logger.info('足球角球, 详细赔率提交成功, {}'.format(res))
  992. logger.info(odds_dict)
  993. else:
  994. logger.warning('足球角球, 详细赔率提交失败, {}'.format(res))
  995. logger.warning(odds_dict)
  996. else:
  997. logging.warning('足球角球, 详细赔率接口异常, {}'.format(res))
  998. else:
  999. logger.info('足球详细赔率列表为空')
  1000. reactor.callFromThread(out.callback, item)