diff --git a/axios-get-service/.env b/axios-get-service/.env new file mode 100644 index 0000000..303cb6d --- /dev/null +++ b/axios-get-service/.env @@ -0,0 +1,3 @@ +NODE_ENV=development +URL=http://localhost:65534/servicedays?routeshortname=411 +#URL=http://localhost:65534/trips?routeshortname=411 diff --git a/axios-get-service/README.md b/axios-get-service/README.md new file mode 100644 index 0000000..e009617 --- /dev/null +++ b/axios-get-service/README.md @@ -0,0 +1,21 @@ +## Overview + +tbc + +## Preparation +Run the following command in your favorite terminal to install dependenies. +``` +npm i +``` +## Development setup +Run the following command in your favorite terminal if you fancy log messages for debugging. +``` +export DEBUG=$DEBUG,axios +``` +Run the following command in your favorite terminal to start the service in development mode. +``` +npm run dev +``` +## Production deployment + +tbc diff --git a/axios-get-service/index.js b/axios-get-service/index.js new file mode 100644 index 0000000..b80577d --- /dev/null +++ b/axios-get-service/index.js @@ -0,0 +1,37 @@ +require('dotenv').config(); +const axios=require('axios'); +const debug=require('debug')('axios'); + +const URL=process.env.URL; +debug('URL: '+URL) + +run().catch(err => { + debug('run: error') + console.log(err) +}); + + +async function run() { + debug('run:...') + + objService = await axios.get(URL); + + //iterate over object + for (const key in objService) { + debug(`${key}: ${objService[key]}`); + } + + //iterate over object + let timeCount=0; + for (const time in objService.data) { + //debug(`time: ${time}`); + let tripCount=0; + for (const tripId in objService.data[time]){ + //debug(`tripId: ${tripId}`); + tripCount++; + } + timeCount++; + //debug('tripCount: '+tripCount); + } + debug('timeCount: '+timeCount); +} diff --git a/axios-get-service/package.json b/axios-get-service/package.json new file mode 100644 index 0000000..ecd5652 --- /dev/null +++ b/axios-get-service/package.json @@ -0,0 +1,19 @@ +{ + "name": "axios-get-service", + "version": "0.0.1", + "description": "", + "main": "index.js", + "scripts": { + "dev": "nodemon index.js", + "test": "echo \"Error: no test specified\" && exit 1" + }, + "author": "Stefan Begerad", + "license": "GPL-3.0", + "devDependencies": { + "nodemon": "^2.0.7" + }, + "dependencies": { + "axios": "^0.21.1", + "dotenv": "^8.2.0" + } +} diff --git a/axios-get-service/utils.js b/axios-get-service/utils.js new file mode 100644 index 0000000..341196e --- /dev/null +++ b/axios-get-service/utils.js @@ -0,0 +1,48 @@ +const debug=require('debug')('utils'); + +function findSubStr(str, start, end) { + var index = str.slice(start, end); + //debug('index: '+index); + return index; +} + +function gtfsDate2NodeDate(date){ + let start = 0; + let end = 4; + let year=findSubStr(date, start, end); + //debug('year: '+year); + start=4; + end=6; + let month=findSubStr(date, start, end); + //debug('month: '+month); + start=6; + end=8; + let day=findSubStr(date, start, end); + //debug('day: '+day); + let nodeDate = new Date(year, month - 1, day); + //debug('nodeDate: '+nodeDate); + return nodeDate; +} + +const dateWeekday={ + sunday:0, + monday:1, + tuesday:2, + wednesday:3, + thursday:4, + friday:5, + saturday:6 +} + +function nextDay(epoch){ + debug('epoch: '+epoch); + let epochNext=epoch + (24 * 60 * 60 * 1000) // 1 day in millisecond + debug('epochNext: '+epochNext); + return epochNext; +} + +module.exports={ + gtfsDate2NodeDate, + nextDay, + dateWeekday +};