Train GraphicClick on the map to explore geographics
 
I need help
FAQ
Emergency
About .
Travel & transport from BBC stories as at 05:35 29 Mar 2024
- Bus plunges off South Africa bridge, killing 45
- Easter getaway begins with flood alerts in place
- Easter travel warning as millions set to hit roads
Read about the forum [here].
Register [here] - it's free.
What do I gain from registering? [here]
 02/06/24 - Summer Timetable starts
17/08/24 - Bus to Imber
27/09/25 - 200 years of passenger trains

On this day
29th Mar (1913)
Foundation of National Union or Railwaymen (*)

Train RunningCancelled
07:00 Bedwyn to Newbury
07:22 Newbury to Bedwyn
08:13 Newbury to Bedwyn
08:46 Bedwyn to Newbury
09:54 Bedwyn to Newbury
10:22 Newbury to Bedwyn
11:29 Newbury to Bedwyn
11:57 Bedwyn to Newbury
12:52 Bedwyn to Newbury
Short Run
04:54 Plymouth to London Paddington
05:12 Reading to Bedwyn
05:23 Hereford to London Paddington
05:33 Plymouth to London Paddington
05:55 Plymouth to London Paddington
06:00 Bedwyn to London Paddington
06:37 Plymouth to London Paddington
07:03 London Paddington to Paignton
08:35 Plymouth to London Paddington
10:35 London Paddington to Exeter St Davids
Delayed
23:45 London Paddington to Penzance
05:03 Penzance to London Paddington
06:05 Penzance to London Paddington
07:10 Penzance to London Paddington
08:03 London Paddington to Penzance
08:15 Penzance to London Paddington
09:04 London Paddington to Plymouth
09:37 London Paddington to Paignton
10:04 London Paddington to Penzance
11:03 London Paddington to Plymouth
PollsOpen and recent polls
Closed 2024-03-25 Easter Escape - to where?
Abbreviation pageAcronymns and abbreviations
Stn ComparatorStation Comparator
Rail newsNews Now - live rail news feed
Site Style 1 2 3 4
Next departures • Bristol Temple MeadsBath SpaChippenhamSwindonDidcot ParkwayReadingLondon PaddingtonMelksham
Exeter St DavidsTauntonWestburyTrowbridgeBristol ParkwayCardiff CentralOxfordCheltenham SpaBirmingham New Street
March 29, 2024, 05:50:28 *
Welcome, Guest. Please login or register.

Login with username, password and session length
Forgotten your username or password? - get a reminder
Most recently liked subjects
[87] would you like your own LIVE train station departure board?
[81] West Wiltshire Bus Changes April 2024
[72] Return of the BRUTE?
[61] Infrastructure problems in Thames Valley causing disruption el...
[49] 2024 - Service update and amendment log, Swindon <-> Westbury...
[44] If not HS2 to Manchester, how will traffic be carried?
 
News: A forum for passengers ... with input from rail professionals welcomed too
 
   Home   Help Search Calendar Login Register  
Pages: [1]
  Print  
Author Topic: Buses at the station ... combined with rail timetable  (Read 2413 times)
grahame
Administrator
Hero Member
*****
Posts: 40690



View Profile WWW Email
« on: April 09, 2020, 12:37:57 »

Question asked of me ... how does the Melksham Rail User Group's web site work to produce a combined live bus and train feed?



Well - we start off by identifying the bus stops and station we're interested in. The National Public Transport Access Nodes database - read about it at http://naptan.app.dft.gov.uk/DataRequest/help and download the data from http://naptan.app.dft.gov.uk/DataRequest/Naptan.ashx?format=csv tells you about just about every bus stop and then you hunt through to find the ones that you want (a needle in a whole line of haystacks!) and get the 7 letter code for each stop wanted. Here are the codes for the two stops at the Railway Inn in Westbury, at the bottom of Station Approach.

"4600WIA10362","wilagtwa","","","Railway Inn","en","","","","","Station Road","en","","","NW-bound","en","NW","E0056892","Westbury","","","","","","","0","U",386481,151896,-2.1951501123,51.2660577345,"BCT","MKD","OTH","","","","108","2020-04-07T12:46:51","2020-02-25T08:31:54",0,"new","act"

"4600WIA10363","wilagtwp","","","Railway Inn","en","","","","","Station Road","en","","","SE-bound","en","SE","E0056892","Westbury","","","","","","","0","U",386524,151872,-2.1945328891,51.2658429590,"BCT","MKD","OTH","","","","108","2020-04-07T12:46:51","2020-02-25T08:31:54",0,"new","act"

You can put those codes into sites such as nextbuses to give you a web page of departures:

https://www.nextbuses.mobi/WebView/BusStopSearch/BusStopSearchResults/wilagtwa

https://www.nextbuses.mobi/WebView/BusStopSearch/BusStopSearchResults/wilagtwp



Then go to "Tiger" - http://iris2.rail.co.uk/tiger/ - and find the station you want; grab the page in the format you want (or in XML if you're going to program it into a web page) - you'll get a URL such as http://iris2.rail.co.uk/tiger/303244.xml or http://iris2.rail.co.uk/tiger/rendercissod.asp?file=303244.xml .



If Tiger isn't available at your station, Real Time Trains and Network Rail's Darwin also offer feeds.

As a simple solution, you could offer links to each of these feeds you identify on your site.   For an integrated solution, you'll need to do a bit of programming - the Melksham Rail User Group one is in PHP, but you could use other languages.  If you ask me "does it take a long time to do" the answer is "no - it probably only took me a day", but if you ask "and how long does it take to learn what to do" ... that can take years!

A word of warning - the results on this Maundy Thursday, with lots of late changes to buses because of the pandemic crisis, are scattered with errors ... the bus companies have much else to do to plan the services they're running and you may see some suspended services shown, and some of their thinner replacements missing.
« Last Edit: April 09, 2020, 16:21:46 by grahame » Logged

Coffee Shop Admin, Acting Chair of Melksham Rail User Group, Option 24/7 Melksham Rep
davidfletcher
Newbie
*
Posts: 6


View Profile Email
« Reply #1 on: April 20, 2020, 17:18:32 »

Thank you for explaining this. It is very useful.
I have found and set up some bus records for my area in Cheshire and am now experimenting with display on our web pages.
I see that in your display you have stripped out the graphics and just showing text. Is there a simple way to do this?
I started with iframes in wordpress. Any thoughts appreciated.
Logged
grahame
Administrator
Hero Member
*****
Posts: 40690



View Profile WWW Email
« Reply #2 on: April 20, 2020, 18:18:11 »

Thank you for explaining this. It is very useful.
I have found and set up some bus records for my area in Cheshire and am now experimenting with display on our web pages.
I see that in your display you have stripped out the graphics and just showing text. Is there a simple way to do this?
I started with iframes in wordpress. Any thoughts appreciated.


Welcome to the forum, David.   Simple if you know how and have done similar before, nightmare if you don't.

I used PHP ... my own function called "grabstop" to download from the nextbuses site to a local file (but only if I haven't already grabbed a local copy within the last three minutes) then "scrape" data from the pages.  I have hardcoded the bus stops I want by NaPTAN code, but grab the stop name from the page, as well as the times.  I make up an array of bus calls ($leaving) which later in the program I can add train and National Express times to from other sources, then sort them by time before reformatting.

Code:
function grabstop($which) {
$lag = time() - filemtime($which);
if ($lag > 179) {
$slurp = unlink($which);
$perform = "wget --no-use-server-timestamps https://www.nextbuses.mobi/WebView/BusStopSearch/BusStopSearchResults/".$which ;
$action = `$perform`;
$lag = 0;
}
$slurp = file_get_contents($which);
return array($slurp,$lag);
}

foreach (array("wilamajm","wilamagt","wildtdmp","wildptwm") as $current) {
$slurp1 = grabstop($current);
preg_match('!<body.*?>(.*)</body>!sm',$slurp1[0],$gotten1);
preg_match_all('!<h2>Departures for .*?\[(\w+)\]</h2>!sm',$slurp1[0],$gotten);
for ($k=0; $k<count($gotten[0]); $k++) { $stopper = $gotten[1][$k]; }
preg_match_all('!<tr>\s*<td class="Number">(.*?)</td>\s*</tr>!sm',$slurp1[0],$gotten);
for ($k=0; $k<count($gotten[0]); $k++) {
$recs = explode("\n",$gotten[1][$k]) ;
$px = explode(" at",strip_tags($recs[5]));
$rz .= "%" . strip_tags($recs[1]) . "<br>" . $px[0] . "<br>" . $px[1] . "<br>";
array_push($leaving,array(trim($px[1]),trim($stopper),trim(strip_tags($recs[1])),trim($px[0])));
}
}

A few a couple of forum members such as Tim and Tom (if he still reads - it's been a while and he's move on to greater things) will "get" this ... as will PHP web site geeks; others will say oh sh**.

Co-incidentally with you posting, I was looking up some bus API stuff - it's come forward in the time since I wrote this and there is now the Open Data requirement in the 2018 (was it?) Transport Act.  Life has been very, very busy for the last month but looks to be settling down a bit and I may have a go with the bus data via https://www.travelinedata.org.uk/traveline-open-data/nextbuses-api/ and also with the Network Rail (Darwin) train stuff. "Month of Sundays" I have said ... but it looks like May will be a month of Sunday bus services here!
Logged

Coffee Shop Admin, Acting Chair of Melksham Rail User Group, Option 24/7 Melksham Rep
TonyK
Global Moderator
Hero Member
*****
Posts: 6435


The artist formerly known as Four Track, Now!


View Profile
« Reply #3 on: April 20, 2020, 20:23:16 »

 Grin Oh sh**

Being serious, this could be extremely useful in a lot of places, but rather needs a bit of certainty around arrival times for both modes, so would be tricky in, say, Bristol.
Logged

Now, please!
davidfletcher
Newbie
*
Posts: 6


View Profile Email
« Reply #4 on: April 23, 2020, 11:05:52 »

thanks for the update
time to ponder!!
Logged
davidfletcher
Newbie
*
Posts: 6


View Profile Email
« Reply #5 on: April 24, 2020, 11:22:47 »

PHP not my game. I found a bit of wordpress app to insert the code, but nothing is happening
What am I missing? Any clues appreciated
Logged
grahame
Administrator
Hero Member
*****
Posts: 40690



View Profile WWW Email
« Reply #6 on: April 24, 2020, 14:56:39 »

Don't be mislead by how quickly I (or somewhat who's been at it for years) can throw together a PHP page shell. It takes a lot longer the first time, and you'll be reading up / asking lots of questions, pulling your hair out with frustration during that time.

The first time to make and bake a Victoria sponge, perhaps it would take you 90 minutes; by the time it becomes a regular routine and you know what you're doing, you may have reduced that to 45 minutes.   That's a 2:1 ratio, over perhaps a couple of dozen cakes.

I can throw together a web page with PHP variable content on the MRUG» (Melksham Rail User Group - site) or Coffee Shop websites in as short a time as 45 minutes (clearly, prepared ingredients needed as would be the case with the sponge), but the very first time I did it would have taken me all day and longer - not a 2:1 ratio but a 12:1 ratio. 

So if you're just doing one PHP page set, then, advise would be to find someone who knows ... to help set up the framework of it.   Not always easy, but by way of example I've set up a number of such initial applications / pages through my career and still look after a handful of clients.  You will appreciate I can't say "pop in and I help with the first one" at the moment though.

There is a case for much more general code that picks up rail and road data (from the APIs described above) and produces a composite feed.  Once you start generalising code and making it user friendly, easy to use and secure in its uses, you add an order of magnitude to the time taken to write, test and document ... then support ... what you have.  Given a month of Sundays (and if we're still locked down in June, I may in effect have that!) ...
Logged

Coffee Shop Admin, Acting Chair of Melksham Rail User Group, Option 24/7 Melksham Rep
davidfletcher
Newbie
*
Posts: 6


View Profile Email
« Reply #7 on: May 30, 2020, 17:20:15 »

I got in touch with the API people and started to look at that. Unfortunatley the guides are no doubt correct, but totally useless. So I am no further forward. Very frustrating.
Logged
grahame
Administrator
Hero Member
*****
Posts: 40690



View Profile WWW Email
« Reply #8 on: May 31, 2020, 18:36:41 »

I got in touch with the API people and started to look at that. Unfortunatley the guides are no doubt correct, but totally useless. So I am no further forward. Very frustrating.

How come "useless" ... was it like trying to learn Turkish starting from an English - Turkish technical dictionary?  There are  people around who know a bit of Turkish and could work with you on the specific technical bits of the API, I'm sure. Alternative is for you to learn Turkish.

Oh - for "Turkish" read "PHP" ;-)
Logged

Coffee Shop Admin, Acting Chair of Melksham Rail User Group, Option 24/7 Melksham Rep
TonyK
Global Moderator
Hero Member
*****
Posts: 6435


The artist formerly known as Four Track, Now!


View Profile
« Reply #9 on: June 01, 2020, 13:54:29 »


How come "useless" ... was it like trying to learn Turkish starting from an English - Turkish technical dictionary?  There are  people around who know a bit of Turkish and could work with you on the specific technical bits of the API, I'm sure. Alternative is for you to learn Turkish.

Onu çok severim!

Quote
Oh - for "Turkish" read "PHP" ;-)

Unless you mean the Gong album about flying teapots, I am utterly lost.
Logged

Now, please!
davidfletcher
Newbie
*
Posts: 6


View Profile Email
« Reply #10 on: June 01, 2020, 23:35:28 »

There you have the first problem. It doesnt tell me what the language is. If I knew it was php I could make a start.
And then it doesn't say what to do with the code examples it provides.
POSTing for me means printing it out, and putting it in a red box, perhaps a stamp?
It makes a broad assumption that I know what I am doing. At my age, new skills have to pay back quickly.
No time to buy green bananas!
Logged
grahame
Administrator
Hero Member
*****
Posts: 40690



View Profile WWW Email
« Reply #11 on: June 02, 2020, 02:45:08 »

There you have the first problem. It doesnt tell me what the language is. If I knew it was php I could make a start.
And then it doesn't say what to do with the code examples it provides.
POSTing for me means printing it out, and putting it in a red box, perhaps a stamp?
It makes a broad assumption that I know what I am doing. At my age, new skills have to pay back quickly.
No time to buy green bananas!

Browsers can ask for data from a server in a handful of ways and the reference to POST is one of those. I fear that if I direct you to https://www.w3.org/Protocols/rfc2616/rfc2616-sec9.html I'll have answered one question but raised a couple of dozen more.  It's either a new skill for you - and so much to that skill that you'll be set for a new career, or finding someone you can tap into who's already jumped the learning hurdle.

Part of me is so, so tempted to say "send the stuff to me and I'll take a look" as I suspect I could sort it out.  I am, however, painfully award that a project like this divides into three sections - development, code maintenance and data maintenance, and that the time put into development is followed - if something is successful - by a bigger wedge of time in lifetime maintenance, and by an even bigger wedge looking after the data - and I know if I jumped in, I would find it hard to commit to the long term code maintenance even with you or others taking up the data issues.

Were I 30 years younger, and looking to make a profession out of this, I suspect I could earn a good living. As it is, much these days is adopt and adapt.  Should an open bus data feed get built into any of the stuff we're doing in Wiltshire, happy to publish the code used but it would be on a "not guaranteed / up to you to check it's tight for you" basis; only redactions would be security keys ("put your API password / ID here") type stuff.
Logged

Coffee Shop Admin, Acting Chair of Melksham Rail User Group, Option 24/7 Melksham Rep
Do you have something you would like to add to this thread, or would you like to raise a new question at the Coffee Shop? Please [register] (it is free) if you have not done so before, or login (at the top of this page) if you already have an account - we would love to read what you have to say!

You can find out more about how this forum works [here] - that will link you to a copy of the forum agreement that you can read before you join, and tell you very much more about how we operate. We are an independent forum, provided and run by customers of Great Western Railway, for customers of Great Western Railway and we welcome railway professionals as members too, in either a personal or official capacity. Views expressed in posts are not necessarily the views of the operators of the forum.

As well as posting messages onto existing threads, and starting new subjects, members can communicate with each other through personal messages if they wish. And once members have made a certain number of posts, they will automatically be admitted to the "frequent posters club", where subjects not-for-public-domain are discussed; anything from the occasional rant to meetups we may be having ...

 
Pages: [1]
  Print  
 
Jump to:  

Powered by MySQL Powered by PHP Powered by SMF 1.1.2 | SMF © 2006-2007, Simple Machines LLC Valid XHTML 1.0! Valid CSS!
This forum is provided by customers of Great Western Railway (formerly First Great Western), and the views expressed are those of the individual posters concerned. Visit www.gwr.com for the official Great Western Railway website. Please contact the administrators of this site if you feel that the content provided by one of our posters contravenes our posting rules (email link to report). Forum hosted by Well House Consultants

Jump to top of pageJump to Forum Home Page