• Stars
    star
    107
  • Rank 316,024 (Top 7 %)
  • Language
    PHP
  • License
    GNU Affero Genera...
  • Created almost 14 years ago
  • Updated 6 months ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

iRail API / scraper

iRail

License AGPL-3.0 Join the chat at https://gitter.im/iRail/iRail

iRail supports digital creativity concerning mobility in Belgium. This is an attempt to make the railway time schedules in Belgium easily available for anyone.

Our main site consists of a very easy mobile website to look up time schedules using our own API.

Native applications using the iRail API and created or supported by the iRail team are named BeTrains and RailerApp.

All information can be found on our blog at hello.iRail.be.

API Documentation

API Documentation can be found at https://docs.irail.be.

Installation for development purposes

note: you'll also need to have nodejs, composer and PHP curl extension installed on your system

  • Step 1: Clone this repo
  • Step 2: If you don't need the occupancy functionality, you can remove the mongodb/mongodb requirement from the composer file. You can now run composer install. If you'd like to have support for the occupancy scores, read below on how to setup mongo before proceeding to run composer install.
  • Step 3: Make sure storage is writable: chmod 777 storage
  • Step 4: Run your test server: php -S localhost:8008 -t api
  • Step 5: Enjoy your own iRail API at http://localhost:8008/connections.php?from=Gent%20Sint%20Pieters&to=Antwerp

MongoDB / Spitsgids setup

Optional: if you want to set up the iRail API with occupancy scores you will need to set up a MongoDB database:

  • Install MongoDB
  • Install the MongoDB module for PHP: pecl install mongodb Make sure PHP loads the module: the conf.d folder for your PHP installation should contain a file with contents extension=mongodb.so in order to load the module. Both the CLI and web version need this, as Composer will run from the CLI
  • Add MongoDB environment variables: cp .env.example .env (If your MongoDB URL is different or you want another database name you can change this file)
  • Import the data (the structural.csv file) in MongoDB: mongoimport -d irail -c structural --type csv --file occupancy/data/structural.csv --headerline
  • Run the startscript to push structural data to the occupancy table: php occupancy/scripts/startscript.php
  • Once the startscript has ran, the task of pushing structural data to the occupancy table should be automated: crontab -e => 30 3 * * * php $PATH_TO_IRAIL_FOLDER/occupancy/scripts/cronjob.php
  • Enjoy the occupancy scores in all the GET requests. Read the docs on how to post occupancy data.

Important: If you plan on using spitsgids in a production environment, don't forget to add indices. Most queries check either the connection (routes, liveboards endpoints) or vehicle field (vehicle endpoint). Example indices can be found below.

  • For queries on vehicles: db.occupancy.createIndex({vehicle: 1}) or db.occupancy.createIndex({date: -1, vehicle: 1})
  • For queries on connections: db.occupancy.createIndex({connection: 1})

Improving performance

Optional: you can improve performance by using APCu. APCu in-memory caching will automaticly be used when the APCu extension is available. When installed, every request to the NMBS will be cached for 15 seconds.

Install with docker

  1. Clone this repo
  2. Run docker-compose build on the project root
  3. After building the container, start them using docker-compose up -d
  4. Run docker-compose exec php composer install to install project dependency
  5. Enjoy your own iRail API at http://localhost:8008/connections.php?from=Gent%20Sint%20Pieters&to=Antwerp

Optional: if you want to set up the iRail API with occupancy scores you will need to import data to MongoDB:

  1. First run cp .env.example .env
  2. Replace MONGODB_URL="mongodb://localhost:27017" with MONGODB_URL="mongodb://mongo:27017"
  3. Run this to to push structural data to the occupancy table : docker-compose exec php php cupancy/scripts/startscript.php
  4. Run this to import the data (the structural.csv file) in MongoDB docker-compose exec mongo mongoimport -d irail -c structural --type csv --file /data/structural.csv --headerline
  5. Once the startscript has ran, the task of pushing structural data to the occupancy table should be automated. In order to do this, edit the docker/php/crontab file and uncomment the following line: 30 3 * * * root /usr/local/bin/php /var/www/html/occupancy/scripts/cronjob.php >> /var/log/cron.log 2>&1

Update stations list

Stations are updated through the irail/stations composer package. Just perform a composer update in the root of the project.

More links

More Repositories

1

hyperRail

The repo for the iRail.be webapp
JavaScript
45
star
2

stations

A list of all the Belgian stations and their properties used within the iRail project
PHP
32
star
3

The-DataTank

DEPRECATED - new repo at http://github.com/tdt/core
PHP
26
star
4

BeTrains-for-Android

BeTrains for android by the iRail NPO and Christophe Versieux
Java
24
star
5

brail2gtfs

[DEPRECATED] GTFS generator for the Belgian Railway company in PHP -- Use the official GTFS now
PHP
8
star
6

PlugID

[deprecated] A generic framework for creating a single sign-on system for your organisation
PHP
7
star
7

brail2gtfs-rt

GTFS-realtime generator for the Belgian Railway company
Java
6
star
8

datawall

The iRail data wall at De Krook library in Ghent!
JavaScript
6
star
9

MIVBSTIBResource

[being phased out] MIVB/STIB Resource plug-in for The DataTank
PHP
6
star
10

iRailForPython

Python 2.x wrapper for the iRail API
Python
5
star
11

Web

The repo for the mobile site
JavaScript
4
star
12

iRail-images

Images used by iRail and BeTrains
4
star
13

DeLijnResource

[Being phased out] A The DataTank 1.0 resource for De Lijn
PHP
4
star
14

WebClient

This was the codebase behind irail.be between 2011 and 2014
PHP
4
star
15

iRailForObjectiveC

iRail Objective C wrapper
Objective-C
4
star
16

gtfs-tdt

Loads GTFS into MySQL and serves next departures and arrivals at a certain stop from The DataTank
PHP
4
star
17

The-Semantifier

[deprecated] A standard GUI interface for ontology mapping in The DataTank
JavaScript
4
star
18

OTDManifest

Source files for the Open Transport Data manifest: http://epsiplatform.eu/transport
4
star
19

newline

iRail hack at 0x20 (new line)
PHP
3
star
20

gtfsrt2lc

[Deprecated] Converts our GTFS-RT to Linked Connections and adds it to our knowledge graph
JavaScript
3
star
21

DelayAnnouncer

Delay announcer using the iRail liveboards.
Perl
3
star
22

Widgets

A collection of all iRail widgets
JavaScript
3
star
23

BeTrains.Qt

Qt MVC framework for BeTrains applications using libqtrail.
C++
3
star
24

BeTrains.BBPB

BeTrains for Blackberry Playbook
ActionScript
3
star
25

BeTrains.Bada

Bada BeTrains repo
C++
3
star
26

iRail-Php-wrapper

PHP wrapper code for IRail team
3
star
27

iRailForJ

A wrapper for the iRail API for Java programming languages
Java
3
star
28

www

New generation iRail.be website: simple, fast, no bullshit route planning interface
3
star
29

iRail-hafas-tester

A tester for the HAFAS nmbs system written in python
Python
3
star
30

harbour-berail

BeRail is a Sailfish OS application to plan your journeys on the Belgian railway.
C++
2
star
31

The-DataTank-GUI

A standard GUI interface for The DataTank
PHP
2
star
32

Stations.io

[deprecated] Stations.io is a linked data project to keep track of all stations around the world
PHP
2
star
33

DataTDTPortal

[deprecated] TheDatatank data portal
JavaScript
2
star
34

GentseFeesten

An app for the Gentse Feesten
JavaScript
2
star
35

BeTrains.Maemo

BeTrains client for the Maemo platform.
C++
2
star
36

BeTrains.Bash

Bash BeTrains repo
Shell
2
star
37

command-irail

get your train data via command line :-)
JavaScript
2
star
38

libqtrail

Qt bindings for the iRail API.
C++
2
star
39

FirstsightScripts

Scripts for the Firstsight project
PHP
2
star
40

iRail-AS3

iRail ActionScript 3 wrapper
ActionScript
2
star
41

The-DataTank-examples

Example modules for The DataTank
PHP
2
star
42

Starter-Kit

[deprecated] iRail Starter Kit
JavaScript
1
star
43

TDTMapper

[deprecated] A very light geo tool for The DataTank
JavaScript
1
star
44

Circadia

Circadia's main repository used on iRail Summer of code
1
star
45

BikesResource

All bikes availability in Belgium
PHP
1
star
46

BeTrains.QML

QML
1
star
47

BeLaws

The first simple and open-source website to find Belgian laws
Shell
1
star
48

irailplatforms2lc

Linked Connections transform script to get the platforms in graph.irail.be
1
star
49

BeTraffic-Android-Client

Java
1
star
50

railtweet

Ruby
1
star
51

Pendelr

iRail hacking project at AppsForGhent
Perl
1
star
52

Commitment

A tool for social networkers to show their support for your page
PHP
1
star
53

GentseFeestenPlanning

Planning and getting to different activities during Gentse Feesten.
JavaScript
1
star
54

fitbit-traindown

Counts down until your next train
JavaScript
1
star