Giter Site home page Giter Site logo

roo7k1d / wow-calendar.js Goto Github PK

View Code? Open in Web Editor NEW
2.0 1.0 1.0 129 KB

An npm package that fetches the World of Warcraft ingame events from https://wowhead.com/events using Axios & Cheerio.

Home Page: https://www.npmjs.com/package/wow-calendar.js

License: Apache License 2.0

JavaScript 100.00%
api calendar javacsript module nodejs npm of package warcraft world

wow-calendar.js's Introduction

An npm package that fetches the World of Warcraft ingame events from https://wowhead.com/events using Axios & Cheerio.

Stars Badge Forks Badge Pull Requests Badge Issues Badge GitHub contributors License Badge
License Badge License Badge License Badge License Badge

Report a Bug | Request a New Feature | Help Develop This Project | Fund Me

Loved the project? Please consider giving a star :)


Available Functions

getActiveEvents (Promise)

const calendar = require("wow-calendar.js");

calendar.getActiveEvents([locale]).then(result => {
  //Result: Array Of All Active Events (Objects; Including Event Descriptions & Event Icon URLs)

  //Additionally
  //
  //If the description request in the desired locale results in too many redirects because of URL encoding
  //this function automatically falls back to english and also returns:
  //
  //descriptionFallback: true
  //
  //Updating your Node.js version might fix this "Too Many Redirects" issue. It did at least for me.
  //At the moment it seems to work with v18+.
})
Parameter Type Description Possible Values
locale string Optional (Default: en). The language you wish the results to be in. de, es, fr, it, pt, ru, ko, cn

getAllEvents (Promise)

const calendar = require("wow-calendar.js");

calendar.getAllEvents([locale]).then(result => {
  //Result: Array Of All Events (Objects)
})
Parameter Type Description Possible Values
locale string Optional (Default: en). The language you wish the results to be in. de, es, fr, it, pt, ru, ko, cn

getEvent (Promise)

const calendar = require("wow-calendar.js");

calendar.getEvent(id, [locale]).then(result => {
  //Result: Event Object (Including Event Descriptions & Event Icon URLs)
})
Parameter Type Description Possible Values
id integer The WoW event id. e.g. 181, 643, ...
locale string Optional (Default: en). The language you wish the results to be in. de, es, fr, it, pt, ru, ko, cn

Help Wanted!

Feel free to submit pull requests that improve the README, functions, documentation and overall code quality!

wow-calendar.js's People

Contributors

dominicabrooks avatar roo7k1d avatar

Stargazers

 avatar  avatar

Watchers

 avatar

Forkers

dominicabrooks

wow-calendar.js's Issues

getActiveEvents("de") - Error: Too Many Redirects

Today I noticed, that the description request fails for some events that have "ß", "ü" or similar characters in them.
This results in the error "Too Many Redirects".

My Attempts To Fix This

I have tried upping the maxRedirects property of the Axios request but with no success.

I have played around with this function
axios.get("https://www.wowhead.com/de/event=634")

The URL Axios tries to request is the following:
https://www.wowhead.com/de/event=634/das-gro%C3%83%C2%9Fe-hippogryphenschl%C3%83%C2%BCpfen
which Axios does not seem to work with since this keeps redirecting. (It does work in a normal browser)

Though when I manually give Axios this URL (which i directly copied from my browser):
https://www.wowhead.com/de/event=634/das-gro%C3%9Fe-hippogryphenschl%C3%BCpfen
it does work.

Notice the additional %83%C2 which seems to break the code.

The Workaround

As you can see in my latest push 84733e0 for version v2.2.0 i have now implemented this workaround:

try {
    let description = axios.get(`https://www.wowhead.com/${locale}/event=${JSON.parse(filteredResults[i].id)}`).then(({ data }) => {
        let metaTag = data.match('<meta name="description" content="(?:.*)">', 'gi');
        return metaTag[0].replace('<meta name="description" content="', '').replace('">', '');
    });

    // Add the description to the event object and push it to the activeEvents array
    filteredResults[i].description = await description;
    filteredResults[i].descriptionLocale = locale;
    // Set a flag to indicate that the description request was successful and no fallback was used
    filteredResults[i].descriptionFallback = false;
    activeEvents.push(filteredResults[i]);


} catch {

    //Fallback to "en" if the chosen description locale request results in too many redirects
    let description = axios.get(`https://www.wowhead.com/en/event=${JSON.parse(filteredResults[i].id)}`).then(({ data }) => {
        let metaTag = data.match('<meta name="description" content="(?:.*)">', 'gi');
        return metaTag[0].replace('<meta name="description" content="', '').replace('">', '');
    });

    // Add the description to the event object and push it to the activeEvents array
    filteredResults[i].description = await description;
    filteredResults[i].descriptionLocale = "en";
    // Set a flag to indicate that the description has been replaced with a fallback
    filteredResults[i].descriptionFallback = true;
    activeEvents.push(filteredResults[i]);
}

This workaround just falls back to "en" locale, which does not seem to have this Too Many Redirects issue (at least at this moment).
It also sets the flag descriptionFallback = true; to indicate, that this description is a fallback to english.

Help Wanted!

I really want to get this working with all the different locales without issues and not with this sloppy workaround.
Maybe some of you reading this have better ideas than I have and can maybe help me with this issue.

I do appreciate everyone who creates a Pull Request to help me fix this bug.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    πŸ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. πŸ“ŠπŸ“ˆπŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❀️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.