An API for the mobitrans.fr web service via pages scrapping made with nodeJs licensed under the terms of the GNU GPLv3.
This API is, at the moment, must be seen as a «work in progress» or «experimental stage»
You will need to have nodeJs, npm (the nodeJs packet manager) and redis installed.
Under any debian-like simply do sudo apt-get install nodejs npm redis-server in a terminal console
- Clone the project
- In a terminal console, go to the project's directory then run
npm installto install the project's dependencies - Run the API server with the default by typing
node app.jsin a terminal console - Open the following URL in a browser : http://127.0.0.1:1337/scrap/MySecret (if you are using it on your own machine)
- Restart the server ([Ctrl]+[C] then
node app.js)
During the first scrap, a «storage.json» file is created to store the datas.
All the default settings are in the default.settings.json file.
Here is the default one :
{
"operators": [
"tam",
"tag",
"citura",
"tao"
],
"secret": "MySecret",
"port": 1337,
"redis": {
"host": "127.0.0.1",
"port": 6379,
"password": null
}
}
operatorsis an array of strings listing all the operators names to usesecretis a string used to create a special URL for the first scrapportis an integer determining the port on wich the server will listen.redisis an object of parameters to configure the redis client
If you want your own configuration, just edit this file or create a new one with a new name like «production.settings.json».
To specify to the app the settings file you want to use, use the environment variables like SETTINGS=production node app.js
A good thing is to use the Forever tool to launch your server. Install it is easy via a simple sudo npm -g install forever
NodeJitsu is a professional hosting service dedicated to nodeJs apps. The distributed package.json file in this repo is ready to be deployed on nodejitsu, modulo some personal tweaks as the name, domains and subdomain vars.
The API is a rest API wich serve, HTML, XML or JSON formatted datas dependng on extension (first has precedence). By default (ie without specifying an extension, HTML will be served)
/scrap/MySecret: perform the very first scrap, to list lines, stop, junctions for all operators/viewStorage/MySecret{null|.html|.json|.xml}: url to call to have a look to the whole storage/:operator/lines{null|.html|.json|.xml}: get all infos for all lines example/:operator/lines/:line{null|.html|.json|.xml}: get all infos for a line example/:operator/stops{null|.html|.json|.xml}: get all infos for all stops example/:operator/stops/:stop{null|.html|.json|.xml}: get all infos for a stop example/:operator/arrivals/:stop/:line{null|.html|.json|.xml}: get the arrivals for a stop on a line example/:operator/arrivals/:stop{null|.html|.json|.xml}: get all the arrivals for a stop from all lines example/:operator/arrivalsAtStop/:stop/forLine/:line{null|.html|.json|.xml}: same as above example/:operator/arrivalsAtLine/:line/forStop/:stop{null|.html|.json|.xml}: same as above example/:operator/arrivalsAtStop/:stop.{null|.html|.json|.xml}: get all arrvivals at a stop from all lines example
Where :
:operatormust be one of the listed operators in the settings file:linemust be a line id:stopmust be a stop id