cubehouse / themeparks

Unofficial API for accessing ride wait times and schedules for Disneyland, Disney World, Universal Studios, and many more parks
MIT License
542 stars 126 forks source link

Universal Pulls Locally But Not From Heroku Server #85

Closed ringcraig closed 6 years ago

ringcraig commented 6 years ago

I am having no problem pulling Six Flags wait times locally, but when I push the code to my heroku server, I get this error:

2017-11-23T15:43:37.907140+00:00 app[web.1]: Error fetching park wait times: 403: "<HTML><HEAD>\n<TITLE>Access Denied</TITLE>\n</HEAD><BODY>\n<H1>Access Denied</H1>\n \nY
ou don't have permission to access \"http&#58;&#47;&#47;api&#46;sixflags&#46;net&#47;Authentication&#47;identity&#47;connect&#47;token\" on this server.<P>\nReference&#32
;&#35;18&#46;f0111cb8&#46;1511451817&#46;289eef46\n</BODY>\n</HTML>\n" 

Here is the code I'm using to get the wait times and save to my database:

var sixFlags= new ThemeParks.Parks.SixFlagsAmerica();

sixFlags.GetWaitTimes(function(err, rides) {
    if (err) {
      console.log(err) 
    } else {
      var time = timestamper();
      rides.forEach(function(ride) {
        db.collection('SixFlagsAmerica').doc(ride.id).collection('waits').add({
          timestamp: time,
          wait: ride.waitTime
        })
      })
    }
  })

This error occurs with all Six Flags parks.

The only other parks that have this problem are LaRonde Montreal and The Great Escape. I'm able to pull all of the rest deployed to heroku with no problem.

ringcraig commented 6 years ago

It appears that inserting this piece of code resolved the issue:

sixFlags.GetAccessToken()

So now my code is:

var sixFlags= new ThemeParks.Parks.SixFlagsAmerica();
sixFlags.GetAccessToken();
sixFlags.GetWaitTimes(function(err, rides) {
    if (err) {
      console.log(err) 
    } else {
      var time = timestamper();
      rides.forEach(function(ride) {
        db.collection('SixFlagsAmerica').doc(ride.id).collection('waits').add({
          timestamp: time,
          wait: ride.waitTime
        })
      })
    }
  })
ringcraig commented 6 years ago

It looks like I spoke too soon. This issue is still resolved for me with sixFlags but I am having a similar issue with Universal. Locally it's fine, but when deployed to my server on heroku I get this error from the Universal parks:

Error fetching park wait times: 200: ""

This is my code:

var universal= new ThemeParks.Parks.UniversalStudiosFlorida();
universal.GetAccessToken();
universal.GetWaitTimes(function(err, rides) {
    if (err) {
      console.log(err) 
    } else {
      var time = timestamper();
      rides.forEach(function(ride) {
        db.collection('UniversalStudiosFlorida').doc(ride.id).collection('waits').add({
          timestamp: time,
          wait: ride.waitTime
        })
      })
    }
  })

Any help with this is greatly appreciated. Thanks! And thanks in general for themeparks. It's an awesome API.

cubehouse commented 6 years ago

Hi,

Sometimes the APIs will not return valid data, this is usually if you're accessing it too frequently, Universal will stop returning valid data.

I can see that you're creating a new "universal" object and immediately accessing it's waittimes. Are you keeping this object around and using it later so you can benefit from caching data so you don't have to constantly fetch the same data again? This will reduce the requests you're making, and you'll be less likely to be locked out of their API.

Make sure you don't request new wait times any more frequently than every 10 minutes or so to ensure you don't make excessive calls.

In regards to Heroku, I'm afraid I can't help you implement the library for a specific framework or service.

ringcraig commented 6 years ago

Yes I keep the object around, but as I was testing things I definitely was making a lot of requests, so that makes sense.