feat(node-axios-bindings-debug): initial commit
This commit is contained in:
parent
8171dd1ae7
commit
24c2d0cada
|
@ -0,0 +1 @@
|
|||
URL=http://192.168.22.16:8080/vehicle-positions
|
|
@ -0,0 +1,2 @@
|
|||
//URL=http://localhost:8080/vehicle-positions
|
||||
URL=https://data.bus-data.dft.gov.uk/api/v1/gtfsrtdatafeed/
|
|
@ -0,0 +1 @@
|
|||
URL=https://dedriver.org/gtfs-rt/vehiclePositions.pb
|
|
@ -0,0 +1 @@
|
|||
URL=https://wimb-api-ops-gis.ew1p3.k8s.mfb.io/v1/gtfs-rt/flavour/rmv/region/de/agency/bus_train/vehicle-position
|
|
@ -0,0 +1 @@
|
|||
URL=http://localhost:8080/vehicle-positions
|
|
@ -0,0 +1 @@
|
|||
URL=https://cdn.mbta.com/realtime/VehiclePositions.pb
|
|
@ -0,0 +1 @@
|
|||
URL=https://gtfs.openov.nl/gtfs-rt/vehiclePositions.pb
|
|
@ -0,0 +1 @@
|
|||
URL=https://soll.vbn.de/vehicle-positions
|
|
@ -0,0 +1 @@
|
|||
URL=http://gtfsr.vbn.de/gtfsr_connect.bin
|
|
@ -0,0 +1,120 @@
|
|||
# Other
|
||||
.env
|
||||
*~
|
||||
|
||||
# Logs
|
||||
logs
|
||||
*.log
|
||||
npm-debug.log*
|
||||
yarn-debug.log*
|
||||
yarn-error.log*
|
||||
lerna-debug.log*
|
||||
|
||||
# Diagnostic reports (https://nodejs.org/api/report.html)
|
||||
report.[0-9]*.[0-9]*.[0-9]*.[0-9]*.json
|
||||
|
||||
# Runtime data
|
||||
pids
|
||||
*.pid
|
||||
*.seed
|
||||
*.pid.lock
|
||||
|
||||
# Directory for instrumented libs generated by jscoverage/JSCover
|
||||
lib-cov
|
||||
|
||||
# Coverage directory used by tools like istanbul
|
||||
coverage
|
||||
*.lcov
|
||||
|
||||
# nyc test coverage
|
||||
.nyc_output
|
||||
|
||||
# Grunt intermediate storage (https://gruntjs.com/creating-plugins#storing-task-files)
|
||||
.grunt
|
||||
|
||||
# Bower dependency directory (https://bower.io/)
|
||||
bower_components
|
||||
|
||||
# node-waf configuration
|
||||
.lock-wscript
|
||||
|
||||
# Compiled binary addons (https://nodejs.org/api/addons.html)
|
||||
build/Release
|
||||
|
||||
# Dependency directories
|
||||
node_modules/
|
||||
jspm_packages/
|
||||
|
||||
# Snowpack dependency directory (https://snowpack.dev/)
|
||||
web_modules/
|
||||
|
||||
# TypeScript cache
|
||||
*.tsbuildinfo
|
||||
|
||||
# Optional npm cache directory
|
||||
.npm
|
||||
|
||||
# Optional eslint cache
|
||||
.eslintcache
|
||||
|
||||
# Microbundle cache
|
||||
.rpt2_cache/
|
||||
.rts2_cache_cjs/
|
||||
.rts2_cache_es/
|
||||
.rts2_cache_umd/
|
||||
|
||||
# Optional REPL history
|
||||
.node_repl_history
|
||||
|
||||
# Output of 'npm pack'
|
||||
*.tgz
|
||||
|
||||
# Yarn Integrity file
|
||||
.yarn-integrity
|
||||
|
||||
# dotenv environment variables file
|
||||
.env
|
||||
.env.test
|
||||
|
||||
# parcel-bundler cache (https://parceljs.org/)
|
||||
.cache
|
||||
.parcel-cache
|
||||
|
||||
# Next.js build output
|
||||
.next
|
||||
out
|
||||
|
||||
# Nuxt.js build / generate output
|
||||
.nuxt
|
||||
dist
|
||||
|
||||
# Gatsby files
|
||||
.cache/
|
||||
# Comment in the public line in if your project uses Gatsby and not Next.js
|
||||
# https://nextjs.org/blog/next-9-1#public-directory-support
|
||||
# public
|
||||
|
||||
# vuepress build output
|
||||
.vuepress/dist
|
||||
|
||||
# Serverless directories
|
||||
.serverless/
|
||||
|
||||
# FuseBox cache
|
||||
.fusebox/
|
||||
|
||||
# DynamoDB Local files
|
||||
.dynamodb/
|
||||
|
||||
# TernJS port file
|
||||
.tern-port
|
||||
|
||||
# Stores VSCode versions used for testing VSCode extensions
|
||||
.vscode-test
|
||||
|
||||
# yarn v2
|
||||
.yarn/cache
|
||||
.yarn/unplugged
|
||||
.yarn/build-state.yml
|
||||
.yarn/install-state.gz
|
||||
.pnp.*
|
|
@ -0,0 +1,86 @@
|
|||
const debug = require('debug')('gtfs');
|
||||
const GtfsRealtimeBindings = require('gtfs-realtime-bindings');
|
||||
|
||||
function decode(buffer){
|
||||
debug('decode...');
|
||||
|
||||
var feed = GtfsRealtimeBindings.transit_realtime.FeedMessage.decode(buffer);
|
||||
if(feed){
|
||||
debug('feed: %s',feed)
|
||||
let header=feed.header;
|
||||
if(header){
|
||||
debug('header: %s',header)
|
||||
let gtfsRealtimeVersion=header.gtfsRealtimeVersion;
|
||||
if(gtfsRealtimeVersion){
|
||||
debug('gtfsRealtimeVersion: %s',gtfsRealtimeVersion)
|
||||
}
|
||||
}
|
||||
feed.entity.forEach(function(entity) {
|
||||
if (entity.tripUpdate) {
|
||||
debug('tripUpdate')
|
||||
const tripUpdate=entity.tripUpdate;
|
||||
if(tripUpdate.trip){
|
||||
debug('TripDescriptor')
|
||||
const trip=tripUpdate.trip
|
||||
if(trip.tripId){
|
||||
debug('trip_id: %s',trip.tripId)
|
||||
}
|
||||
if(trip.routeId){
|
||||
debug('route_id: %s',trip.routeId)
|
||||
}
|
||||
if(trip.directionId){
|
||||
debug('direction_id: %s',trip.directionId)
|
||||
}
|
||||
if(trip.startTime){
|
||||
debug('start_time: %s',trip.startTime)
|
||||
}
|
||||
if(trip.startDate){
|
||||
debug('start_date: %s',trip.startDate)
|
||||
}
|
||||
if(trip.scheduleRelationship){
|
||||
debug('schedule_relationship: %s',trip.scheduleRelationship)
|
||||
}
|
||||
}
|
||||
if(tripUpdate.vehicle){
|
||||
debug('VehicleDescriptor')
|
||||
}
|
||||
if(tripUpdate.timestamp){
|
||||
debug('timestamp: %s',tripUpdate.timestamp)
|
||||
}
|
||||
}else if(entity.vehicle){
|
||||
const vehPos=entity.vehicle;
|
||||
debug('vehiclePosition')
|
||||
if(vehPos.position){
|
||||
const pos=vehPos.position;
|
||||
debug('position')
|
||||
if(pos.latitude){
|
||||
const lat=pos.latitude;
|
||||
debug('lat: %s',lat)
|
||||
}
|
||||
if(pos.longitude){
|
||||
const lon=pos.longitude;
|
||||
debug('lon: %s',lon)
|
||||
}
|
||||
}
|
||||
}else if(entity.alert){
|
||||
debug('alert')
|
||||
}else{
|
||||
debug('entity unknown')
|
||||
}
|
||||
});
|
||||
// Verify the payload if necessary (i.e. when possibly incomplete or invalid)
|
||||
let errMsg = GtfsRealtimeBindings.transit_realtime.FeedMessage.verify(feed);
|
||||
if (errMsg){
|
||||
debug('msg invalid')
|
||||
throw Error(errMsg);
|
||||
}else{
|
||||
debug('msg valid')
|
||||
}
|
||||
}else{
|
||||
debug('feed unavailable')
|
||||
}
|
||||
debug('...done.')
|
||||
return feed;
|
||||
}
|
||||
module.exports = {decode}
|
||||
|
|
@ -0,0 +1,41 @@
|
|||
const axios=require('axios');
|
||||
const gtfsRt = require('./gtfsRtDecode');
|
||||
const debug = require('debug')('gtfs');
|
||||
require('dotenv').config();
|
||||
|
||||
const URL=process.env.URL||'TODO: Adjust URL according to use case!'
|
||||
debug('URL: '+URL)
|
||||
|
||||
run().catch(err => {
|
||||
debug('run: error')
|
||||
console.log(err)
|
||||
});
|
||||
|
||||
async function run() {
|
||||
debug('run started...')
|
||||
|
||||
const token = 'f5e9ef10f43095ce597cfa4b5c3b742475984b68';
|
||||
const url = URL;
|
||||
const usr = 'stefan2';
|
||||
const ky = 'f5e9ef10f43095ce597cfa4b5c3b742475984b68';
|
||||
const config = {
|
||||
headers: {
|
||||
authorization: `${token}`
|
||||
},
|
||||
// Axios looks for the `auth` option, and, if it is set, formats a
|
||||
// basic auth header for you automatically.
|
||||
//auth: {
|
||||
// username: `${usr}`,
|
||||
// password: `${ky}`
|
||||
//},
|
||||
responseType: 'arraybuffer'
|
||||
//responseType: 'blob'
|
||||
};
|
||||
|
||||
const res = await axios.get(URL,config);
|
||||
//debug('run res: '+res);
|
||||
//debug('run JSON res: '+JSON.stringify(res));
|
||||
//debug('run res.data: '+res.data);
|
||||
let feed=gtfsRt.decode(res.data);
|
||||
debug('run done.')
|
||||
}
|
File diff suppressed because it is too large
Load Diff
|
@ -0,0 +1,22 @@
|
|||
{
|
||||
"name": "gtfs-realtime-bindings",
|
||||
"version": "0.0.1",
|
||||
"description": "decode GTFS Realtime and log to console",
|
||||
"main": "index.js",
|
||||
"scripts": {
|
||||
"dev": "nodemon index.js",
|
||||
"start": "node index.js",
|
||||
"test": "echo \"Error: no test specified\" && exit 1"
|
||||
},
|
||||
"author": "Stefan Begerad",
|
||||
"license": "GPL-3.0",
|
||||
"dependencies": {
|
||||
"axios": "1.4.0",
|
||||
"debug": "4.3.4",
|
||||
"dotenv": "16.3.1",
|
||||
"gtfs-realtime-bindings": "1.1.1"
|
||||
},
|
||||
"devDependencies": {
|
||||
"nodemon": "2.0.7"
|
||||
}
|
||||
}
|
|
@ -0,0 +1,17 @@
|
|||
## Overview
|
||||
|
||||
Decode GTFS Realtime and log to console
|
||||
|
||||
It translates message feeds from the GTFS Realtime format to human readable text and logs it onto the command line interface.
|
||||
|
||||
## Preparation
|
||||
|
||||
```
|
||||
npm i
|
||||
```
|
||||
|
||||
# Test
|
||||
|
||||
```
|
||||
DEBUG=debug,gtfs npm run dev
|
||||
```
|
|
@ -0,0 +1 @@
|
|||
URL=https://soll.vbn.de/vehicle-positions
|
Loading…
Reference in New Issue