Train Graphic
Great Western Passengers' Forum
GWR advice during Coronavirus
Coffee Shop during Coronavirus
Please - Do NOT travel unless you have to!
Great Western Coffee Shop - [home] and [about]
Read about the forum [here].
Register [here] - it's free.
What do I gain from registering? [here]
 today - Benefits to gain - ONLINE
28/05/2020 - CILT seminar - ONLINE
29/05/2020 - TWSW - Bristol Mayor - ONLINE
05/06/2020 - World Environment Day
Random Image
Train Running @GWR Twitter Acronyms/Abbreviations Station Comparator Rail news GWR co. site Site Style 1 2 3 4
Next departures • Bristol Temple MeadsBath SpaChippenhamSwindonDidcot ParkwayReadingLondon PaddingtonMelksham
Exeter St DavidsTauntonWestburyTrowbridgeBristol ParkwayCardiff CentralOxfordCheltenham SpaBirmingham New Street
May 26, 2020, 09:10:09 pm *
Welcome, Guest. Please login or register.

Login with username, password and session length
Forgotten your username or password? - get a reminder
Most liked recent subjects
[78] Great Western Railway: on-board catering, buffets, Travelling ...
[56] Which UK network station has the best view? [DotD 25.5.20]
[51] Rail programmes MONDAY 25th May
[49] Hebridean Light Railway, and highland proposals and short-live...
[46] Rail programmes TUESDAY 26th May
[37] What happened near Dauntsey on Wednesday 20th May?
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 444 times)
grahame
Administrator
Hero Member
*****
Posts: 29433



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

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, 04:21:46 pm by grahame » Logged

Coffee Shop Admin, Vice Chair of Melksham Rail User Group, and on the board of TravelWatch SouthWest.
davidfletcher
Newbie
*
Posts: 4


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

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: 29433



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

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, Vice Chair of Melksham Rail User Group, and on the board of TravelWatch SouthWest.
TonyK
Global Moderator
Hero Member
*****
Posts: 4988


The artist formerly known as Four Track, Now!


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

 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: 4


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

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


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

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: 29433



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

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 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, Vice Chair of Melksham Rail User Group, and on the board of TravelWatch SouthWest.
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 a customer 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). Forum hosted by Well House Consultants

Jump to top of pageJump to Forum Home Page