cubehouse / themeparks

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

Need help ! #33

Closed theos95 closed 8 years ago

theos95 commented 8 years ago

Hello, How can we retrieve the Disneyland wait time in an HTML file? I know use only HTML and PHP and I'm a bit lost with the install of the script ! Thanks

vweimann commented 8 years ago

Hello,

its not as difficult as it seems to use the node.js scripts with PHP and return the results with HTML.

1.) You have to install and prepare your server to run node.js. Sorry, I can't help you with this, there are a lot of tutorials out there on the web for every possible OS. I have it running on my Mac and also on a Raspi Pi.

2.) Do a installation of the wdwjs package, for example directly in your web directory on the server. npm install wdwjs --save The neweset wdwjs files and all needed dependencies will be automatically installed to a directory called "node_modules"

3.) I've done a little js script for every theme park to show. This script is calling the wdwjs in an appropriate way to get and return the desired result via console.log. It looks like this: var parks = require("wdwjs"); var DisneylandParis = new parks.DisneylandParisMagicKingdom(); DisneylandParis.GetWaitTimes(function(err, times) { if (err) return console.error(err); console.log(JSON.stringify(times, null, 2)); });

This script must be callable directly in your shell using "node YourJsScriptName.js". Only then your node.js ist correctly installed.

4.) This js script is called via the "exec"-function of PHP: exec("node ". YourJsScriptName.js, $jsonWaitTimes); $attractionRawData = implode($jsonWaitTimes);

5.) The results in $attractionRawData (json) can be handled by PHP via json_decode() or whatsoever...

I appended my short, easy, quick and dirty PHP testing scripts so you can see and checkout the principle. It can be done far more elegant and efficient but this is a quick solution that works for me.

I've also done a working translation of the js scripts to PHP to do the communication with the API of DLP Paris directly within PHP, but the logic is very difficult (exchange of some tokens etc.). Due to the fact that there are many changes to the API's (you see it in the number of updates of wdwjs) where they change the logic and parameters I decided to give up to always change and adjust my PHP and simply use the excellent wdwjs node.js scripts. cubehouse did a very good job here!! Thumbs up!

Greetings

Veit

web.zip

theos95 commented 8 years ago

@vweimann : Hello, thank you for your answer ! :) I managed to install on my web server but I have a problem with : "$ AttractionRawData = implode ($ jsonWaitTimes);"

An error message is displayed in the browser "Warning: implode () [function.implode]: Argument to implode must be an array."

Do you know how to solve this problem?

cubehouse commented 8 years ago

Hi guys,

Thank you so much @vweimann for assisting @theos95 , it's very kind of you to take the time and effort to document code samples for PHP to integrate with NodeJS. This issue is very much outside the scope of the project, so it is hugely appreciated that you have done this for another GitHub member to help them out.

I regularly get email requests to create this library in PHP (or something similar), however I have no interest in maintaining this in any more than 1 language. If you wish to use this library, you'll have a generally easier time if you learn some basic NodeJS. But of course you may do what you like! That's the beauty of open-source code. You can make a Frankenstein PHP/NodeJS application if you wish, and I sadly cannot stop you! :)

As this isn't actually an issue with this project, I am going to close this issue. I have enabled the Wiki feature for this project, so if you wish to continue working on some sort of PHP runner for this, you can continue to document such a thing there.

Many thanks!