Jump to content

User:Habst/getWaNews.js

From Wikipedia, the free encyclopedia
Note: After saving, you have to bypass your browser's cache to see the changes. Google Chrome, Firefox, Microsoft Edge and Safari: Hold down the ⇧ Shift key and click the Reload toolbar button. For details and instructions about other browsers, see Wikipedia:Bypass your cache.
await (await fetch("https://jsyr3xmt7nchpjukzohfslxfre.appsync-api.eu-west-1.amazonaws.com/graphql", {
  headers: { "x-api-key": "da2-o5lb23etxbe3viqhbquknwoazq" }, // intentionally public
  body: JSON.stringify({
  operationName: "GetNewArticles",
  variables: {
    language: "en",
    orderBy: "PublishedDate",
    orderDirection: "Descending",
    checkHiddenOnMainSite: true,
    types: [13], // heritage
    limit: 999,
    offset: 0,
  },
  query: `query GetNewArticles($language: String = "en", $relatedEventIds: [Int], $relatedCompetitionIds: [String], $types: [Int], $orderBy: OrderByNewArticleEnum = PublishedDate, $orderDirection: OrderDirectionEnum = Descending, $limit: Int, $offset: Int, $relatedEventNameUrlSlug: [String], $relatedDisciplineUrlSlug: [String], $relatedDisciplineCodes: [String], $relatedAthleteUrlSlug: [String], $relatedAthleteIds: [String], $relatedCompetitionUrlSlug: [String], $relatedMinisiteIds: [String], $relatedLocationIds: [String], $relatedCountryCodes: [String], $relatedRegionCodes: [String], $tags: [String], $filterArticleSlug: String, $checkHiddenOnMainSite: Boolean = true, $publishedYear: String) {
  getNewArticles(language: $language, relatedEventIds: $relatedEventIds, relatedCompetitionIds: $relatedCompetitionIds, relatedEventNameUrlSlug: $relatedEventNameUrlSlug, relatedDisciplineUrlSlug: $relatedDisciplineUrlSlug, relatedDisciplineCodes: $relatedDisciplineCodes, relatedAthleteUrlSlug: $relatedAthleteUrlSlug, relatedAthleteIds: $relatedAthleteIds, relatedCompetitionUrlSlug: $relatedCompetitionUrlSlug, relatedMinisiteIds: $relatedMinisiteIds, relatedLocationIds: $relatedLocationIds, relatedCountryCodes: $relatedCountryCodes, relatedRegionCodes: $relatedRegionCodes, tags: $tags, types: $types, orderBy: $orderBy, orderDirection: $orderDirection, limit: $limit, offset: $offset, filterArticleSlug: $filterArticleSlug, checkHiddenOnMainSite: $checkHiddenOnMainSite, publishedYear: $publishedYear) {
    ...ArticleUrlFields
    id
    title
    body
    gatedContent
    standFirst
    standfirst
    liveFrom
    contentId
    urlSlug
    backgroundColour
    seoDescription
    imageEdited
    campaignId
    relatedUrls
    slug
    articleType
    featureImageId
    featureImageEdited
    hideOnTheMainSite
    sEOTitle: seoTitle
    seoTitle
    metaDescription: seoDescription
    eventId
    blogUpdated
    liveBlog
    language
    contentModules {
      moduleType
      backgroundColor
      __typename
    }
    relatedMedia {
      id
      fileName
      __typename
    }
    relatedCompetitions {
      ...ArticleRelatedCompetitions
      __typename
    }
    event {
      ...ArticleEventUrlFields
      __typename
    }
    relatedEventIds
    relatedEvents {
      id
      name
      ...ArticleEventUrlFields
      __typename
    }
    relatedCompetitors {
      id
      iaafId
      firstName
      lastName
      friendlyName
      fullName
      friendlyNameLetter
      friendlyNameFirst3Letter
      sexCode
      sexName
      countryCode
      countryName
      birthDate
      birthPlace
      birthPlaceCountryName
      sexNameUrlSlug
      countryUrlSlug
      birthPlaceCountryUrlSlug
      birthCountryCode
      primaryMediaId
      primaryMedia {
        fileName
        __typename
      }
      urlSlug
      representativeId
      biography
      twitterLink
      instagramLink
      facebookLink
      transfersOfAllegiance
      aaId
      countryFullName
      familyName
      givenName
      birthDateStr
      facebookUsername
      twitterUsername
      instagramUsername
      __typename
    }
    relatedCountryCodes
    relatedRegionCodes
    __typename
  }
}

fragment ArticleUrlFields on NewArticle {
  articleType
  urlSlug
  relatedMinisiteIds
  relatedMinisitePages {
    slug
    __typename
  }
  tags
  __typename
}

fragment ArticleEventUrlFields on WAWEvent {
  id
  eventId_WA
  nameUrlSlug
  subCategoryNameUrlSlug
  categoryCode
  endDate
  name
  countryName
  venue
  areaName
  areaCode
  countryCode
  indoorOutdoor
  categoryCode
  categoryName
  page {
    slug
    __typename
  }
  __typename
}

fragment ArticleRelatedCompetitions on Competition {
  id
  name
  urlSlug
  category
  __typename
}`
}),
  method: "POST",
})).json();

temp1.toReversed().map(a => `* ${a.title.replace('Track & Field', 'Track_&_Field').replace('Hare & Hounds', 'Hare_&_Hounds').replace('Boys and Girls', 'Boys_and_Girls').split(/ (&|\/|and) /).filter(w => !['&', '/', 'and'].includes(w)).map(t => `[[${t}]]`).join(', ')}: ${a.body.split('\n').find(l => l.toLowerCase().includes('plaque categor'))?.split('-').at(-1).split('&ndash;').at(-1).replace('</span>', '').replace('</p>', '')}`).join('\n')