pinnacleClient.js 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384
  1. import axios from "axios";
  2. import { HttpsProxyAgent } from "https-proxy-agent";
  3. import getDateInTimezone from "./getDateInTimezone.js";
  4. /**
  5. * 获取Web端联赛数据
  6. * @param {*} marketType 0: 早盘赛事, 1: 今日赛事
  7. * @param {*} locale en_US or zh_CN
  8. * @returns
  9. */
  10. export const pinnacleWebLeagues = async (marketType = 1, locale = "zh_CN") => {
  11. const dateString = marketType == 1 ? getDateInTimezone(-4) : getDateInTimezone(-4, Date.now()+24*60*60*1000);
  12. const nowTime = Date.now();
  13. const axiosConfig = {
  14. baseURL: "https://www.part987.com",
  15. url: "/sports-service/sv/compact/leagues",
  16. method: "GET",
  17. headers: {
  18. "accept": "application/json, text/plain, */*",
  19. "user-agent": "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/143.0.0.0 Safari/537.36",
  20. "x-app-data": "directusToken=TwEdnphtyxsfMpXoJkCkWaPsL2KJJ3lo;lang=zh_CN;dpVXz=ZDfaFZUP9"
  21. },
  22. params: {
  23. btg: 1, c: "", d: dateString,
  24. l: true, mk: marketType,
  25. pa: 0, pn: -1, sp: 29, tm: 0,
  26. locale, _: nowTime, withCredentials: true
  27. },
  28. timeout: 10000,
  29. };
  30. const proxy = process.env.NODE_HTTP_PROXY;
  31. if (proxy) {
  32. axiosConfig.proxy = false;
  33. axiosConfig.httpsAgent = new HttpsProxyAgent(proxy);
  34. }
  35. return axios(axiosConfig).then(res => res.data?.[0]?.[2]?.map(item => {
  36. const [ id, , name ] = item;
  37. return [id, { id, name }];
  38. }) ?? []);
  39. }
  40. /**
  41. * 获取Web比赛列表
  42. */
  43. export const pinnacleWebGames = async (leagues=[], marketType=1, locale="zh_CN") => {
  44. const dateString = marketType == 1 ? getDateInTimezone(-4) : getDateInTimezone(-4, Date.now()+24*60*60*1000);
  45. const nowTime = Date.now();
  46. const axiosConfig = {
  47. baseURL: "https://www.part987.com",
  48. url: "/sports-service/sv/odds/events",
  49. method: "GET",
  50. headers: {
  51. "accept": "application/json, text/plain, */*",
  52. "user-agent": "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/143.0.0.0 Safari/537.36",
  53. "x-app-data": "directusToken=TwEdnphtyxsfMpXoJkCkWaPsL2KJJ3lo;lang=zh_CN;dpVXz=ZDfaFZUP9"
  54. },
  55. params: {
  56. sp: 29, lg: leagues.join(','), ev: "",
  57. mk: marketType, btg: 1, ot: 1,
  58. d: dateString, o: 0, l: 100, v: 0,
  59. me: 0, more: false, tm: 0, pa: 0, c: "",
  60. g: "QQ==", cl: 100, pimo: "0,1,8,39,2,3,6,7,4,5",
  61. inl: false, _: nowTime, locale
  62. },
  63. timeout: 10000,
  64. };
  65. const proxy = process.env.NODE_HTTP_PROXY;
  66. if (proxy) {
  67. axiosConfig.proxy = false;
  68. axiosConfig.httpsAgent = new HttpsProxyAgent(proxy);
  69. }
  70. return axios(axiosConfig).then(res => res.data.n?.[0]?.[2]?.map(league => {
  71. const [leagueId, leagueName, games] = league;
  72. return games.map(game => {
  73. const [id, teamHomeName, teamAwayName, , timestamp] = game;
  74. const startTime = getDateInTimezone('+8', timestamp, true);
  75. return { id, leagueId, leagueName, teamHomeName, teamAwayName, timestamp, startTime }
  76. })
  77. }).flat().filter(game => {
  78. const { teamHomeName, teamAwayName } = game;
  79. return !teamHomeName.startsWith('主队') && !teamAwayName.startsWith('客队');
  80. }) ?? []);
  81. }