feat(axios-get-service): initial commit

This commit is contained in:
dancingCycle 2022-05-19 11:59:11 +02:00
parent 413b5904b0
commit a50f4190f6
5 changed files with 128 additions and 0 deletions

3
axios-get-service/.env Normal file
View File

@ -0,0 +1,3 @@
NODE_ENV=development
URL=http://localhost:65534/servicedays?routeshortname=411
#URL=http://localhost:65534/trips?routeshortname=411

View File

@ -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

View File

@ -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);
}

View File

@ -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"
}
}

View File

@ -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
};