Coder Social home page Coder Social logo

Comments (6)

brendannee avatar brendannee commented on July 19, 2024

Great question.

After importing your GTFS, you can use sqlite3 from the command line to execute queries.

sqlite3 /tmp/gtfs "select * from trips;" ".exit"

Would it be useful to have a command within the GTFS library to do this? Like:

gtfs query "select * from trips;"

from node-gtfs.

MineRiaaa avatar MineRiaaa commented on July 19, 2024

I'm sorry I didn't make my question clear, but still thank you for your answer, which is also very helpful to me.

Below is the detailed description of my question:

I am using Windows, and I want to test the query methods and query efficiency of node-gtfs. However, I don't have a specific project, so I choose to implement this library with the command line. I hope I can use the command line to implement the Query Methods mentioned in the documentation, such as getRoutes() and getStops(), etc.

Do I need to write a js file and run it from the command line?

from node-gtfs.

brendannee avatar brendannee commented on July 19, 2024

Thanks for clarifying.

You are correct that in order to use the query methods from the command line, you'll need to make a js file that implements them.

You can see some small example scripts here: https://github.com/blinktaginc/node-gtfs#examples

You'll need to create a package.json file and install 'gtfs' from npm too.

Let me know how it goes.

from node-gtfs.

MineRiaaa avatar MineRiaaa commented on July 19, 2024

Thanks a lot!

I'll have a try and show the results here.

from node-gtfs.

MineRiaaa avatar MineRiaaa commented on July 19, 2024

It works!

I created a getStops.js file and a config.json file under the gtfs folder.

The code of getStops.js is as follows:

import { openDb, getStops } from '../gtfs/index.js';
import { readFile } from 'fs/promises';

const config = JSON.parse(await readFile(new URL('./config.json', import.meta.url)));

const db = openDb(config);
const stops = getStops(
  {
    stop_id: [
      '1622',
      '5182'
    ]
  }
);
console.log(stops);

Then I ran the command:

node getStops.js

The results are printed like this:

[
  {
    stop_id: '1622',
    stop_code: '1014',
    stop_name: 'Pacheco Blvd + Arthur Rd',
    tts_stop_name: null,
    stop_desc: null,
    stop_lat: 38.00626,
    stop_lon: -122.090569,
    zone_id: null,
    stop_url: null,
    location_type: 0,
    parent_station: null,
    stop_timezone: null,
    wheelchair_boarding: 2,
    level_id: null,
    platform_code: null
  },
  {
    stop_id: '5182',
    stop_code: '1162',
    stop_name: 'Lafayette BART',
    tts_stop_name: null,
    stop_desc: null,
    stop_lat: 37.893571,
    stop_lon: -122.125128,
    zone_id: null,
    stop_url: null,
    location_type: 0,
    parent_station: null,
    stop_timezone: null,
    wheelchair_boarding: 2,
    level_id: null,
    platform_code: null
  }
]

from node-gtfs.

brendannee avatar brendannee commented on July 19, 2024

That is great - thanks for sharing your working code.

from node-gtfs.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.