Introducing @whensmybus

3 October 2011

A few weeks ago TfL put all their information from Countdown, the service they use to provide bus arrival times, online. There’s a TfL Countdown website and you can enter a bus stop name, or ID number, and find out the latest buses from the stop.

But, it’s a bit fiddly. The main website doesn’t automatically redirect you to the mobile version if you are on a phone. If you type in a location, (e.g. my local Tube station, “Limehouse Station”), you have to pick a match for the location first (from two identically-named options), then a second screen asking you to find a bus stop, and then you get the relevant times. On a phone, it’s just feels fiddly and frustrating especially when I know my phone has GPS in it and knows my location anyway.

Update/correction There is, as it turns out, the ability to find by geolocation on the mobile site, it’s just on a mobile browser I just get the main website and don’t get redirected to the special mobile site, which means I never knew about it (thanks to Ade in the comments for pointing this out).

If only there was a mobile-friendly, geolocation aware, real-time way of fetching information. Oh wait. There is. It’s called Twitter. Twitter has geolocation allowed on Tweets (if you opt in) and an API to fetch and send messages, so we have a system set up already in place for our needs.

I owe a big debt of gratitude to Adrian Short, who wrote a Ruby script to pull bus times from TfL. TfL have not officially released an API for Countdown just yet, but Adrian found it, and it’s there and accessible – providing the data in JSON format for each stop. That use got me thinking – if that data is available and can be parsed quickly and easily, why not make a Twitter bot for it?

With that, @whensmybus was born, and is now in beta. Try it out now if you like. Make sure your Tweet has geolocation turned on (for which you’ll need a GPS-capable smartphone), and send a message like:

@whensmybus 135

Or whatever bus you are looking for. Within 60 seconds, you’ll get a Tweet back with the times of the next buses for that route, in each direction, from the stops closest to your location.

Why each direction? Specifying a direction is fiddly and ambiguous; bus routes wind and twist, and some of them are even circular, so “northbound” and “southbound” are not easy things to parse. The name of your destination can have ambiguous spellings, and I haven’t yet got round to tying it in with a geocoding service like Google Maps. So, at the moment the bot simply tells you buses in both directions from the stops nearest to you. I might change this in future, once I’ve got my head around geolocation services and fuzzy string matching and all that.

It’s still beta (thanks to an early unveiling by Sian ;) ) and I plan in future to add enhancements such as the ability to use without GPS. I also need to write some proper documentation for it, and stick the source code on Github later tonight once I am home. The source code is now available on github, but do bear in mind the codebase is a bit unstable right now. So, if you are a Londoner, please do use it and tell me what you think, either on the comments below or on Twitter. @ me, don’t @ the bot – it will think it’s a request for a bus service and get confused. :) All suggestions are welcome.

(And now, some tech stuff for the more interested)

The bot is a Python script, run every minute via a cronjob. It’s quite short – 350 lines including comments for the main bit. As well as the live data API, the service also uses two databases officially provided by TfL’s syndication service for free; one is of all the routes, and one for all the bus stop locations. I converted these from CSV format to sqlite so the bot can make SQL queries on the data. TfL use OS Easting and Northing locations for the bus stops, so I have to convert the GPS longitude and latitude; I am indebted to Chris Veness and his lat/lng to OS conversion script, which I translated from JavaScript to Python; I am also now much more educated on subtleties like the difference between OSGB36 and WGS84. Finally, I use the Tweepy library to receive and send the Tweets, which is really rather excellent and saves a lot of faff. Finally, the whole project would not be possible without the ideals of open data and open source software behind it, so if you’ve written even a single line of free software, then thank you as well.


66 Responses

Yeah, erm… sorry about that :-)

It’s very brilliant.

[...] some people have created iPhone apps including Next Bus London, Bus Checker and the awesome Twitter account which tweets you back with your bus arrival [...]

Allie

One small thought – how can you get round the fact that twitter won’t let you send the same tweet more than once so if I want to find out when buses are coming every day, it will only work once?

Or have you found a way round that?

Ade Bradley

This is a great idea, but i’ve not had the problems with the mobile site that you seem to?

When i use it it asks permission to find my location, then shows me the stop nearest to me. I’m at the list of busses within 2 taps.

I’m going to give your one a go though.

@Allie Just add a different random hashtag at the end of the Tweet, the bot will ignore it but it will make your Tweet unique

@Ade Ah – hadn’t noticed that, because I’m not directed to the special mobile site when I go see it. But now I’m in, and I’ve allowed Safari to use location data, I can see that option there. Will correct the above

@ottaky Nice site, though it doesn’t get my location that correct when I log in on a browser on my work computer – I’m based in Clerkenwell but it seems to think I am in Bank.

Edgemaster

Not everyone has data contracts with their phones, but do have free twitter texts, would it be possible to adapt this so that it can read location from the tweet text, if the geotag field is missing?

“Nice site, though it doesn’t get my location that correct when I log in on a browser on my work computer – I’m based in Clerkenwell but it seems to think I am in Bank.”

Using a PC will return times for buses in or around your ISP – not terribly useful ;-)

My script is designed for mobile devices – hopefully it’s a little easier to use than the official TfL website.

@Edgemaster I’m going to try to develop a non-GPS version that locates based on the text. There’s lots of things that can go wrong – spelling, misidentifying places etc. – but it is a planned feature

[...] It’s been nine days since @whensmybus was released and the feedback has by and large been positive. It’s not all been plain sailing – the [...]

hi mate… I’m from brazil and developing a project just like yours, except I’d also like to enable people to inform bus arrival times and confront them through statistics to government-provided values.

in our city, we’ve got gps-tracked buses but the overall system is terryfing: no precision, no user-friendliness, no mobile version and specially no API for us to build upon.

maybe we could get in touch and share some ideas on how to grab data from people as well. what do you say?

hey mate,

i finally managed to get a small service working here in Vitória, Brazil. it works by sending a tweet with the stop number and getting the estimated times (GPS-obtained) for that stop. We called it @vixbus and, though not as fancy as yours (GPS-tracked-tweet), it is a place to start, after all.

thanks for the motivation of whensmybus. keep the nice work.

[...] (vixbus@gmail.com) e twitter (@vixbus), entramos em contato com o o Chris Applegate – do @whensmybus, do Reino Unido – e com o Metzen, de Vitória, que criou o excelente No Ponto e iniciamos a [...]

@Marcos – that’s absolutely fantastic! So pleased to see what I’ve inspired

[...] year I introduced a service called @whensmybus, a Twitter bot that you could ask for real-time bus times from anywhere in London. It proved to be [...]

[...] (vixbus@gmail.com) e twitter (@vixbus), entramos em contato com o o Chris Applegate – do @whensmybus, do Reino Unido – e com o Metzen, de Vitória, que criou o excelente No Ponto e iniciamos a [...]

It’s going to be ending of mine day, but before finish I
am reading this great piece of writing to increase my knowledge.

Also visit my web-site – care home audit report (nanceealbert.mywapblog.com)

I’ve been browsing online more than 3 hours today, yet I
never found any interesting article like yours.

It is pretty worth enough for me. In my view, if all website owners and bloggers made good content
as you did, the internet will be much more useful
than ever before.

Hi there, after reading this remarkable article i am also delighted to share my know-how here
with friends.

Hey! Quick question that’s completely off topic. Do you know
how to make your site mobile friendly? My web site looks weird when browsing from my iphone4.
I’m trying to find a theme or plugin that might be able to resolve this issue.
If you have any recommendations, please share.
Thanks!

Hi everyone, it’s my first go to see at this web site, and piece of writing is truly fruitful designed for me,
keep up posting such articles.

Right now it sounds like Expression Engine is the preferred blogging platform available right now.
(from what I’ve read) Is that what you’re using on your blog?

Also visit my weblog; website

Quality posts is the key to invite the viewers to pay a quick
visit the web site, that’s what this web page is providing.

Feel free to visit my web site … download youtube videos mp4 (http://www.youtube.com/watch?v=0hTj5Qw694I)

Hi there! I simply wish to offer you a huge thumbs up for your excellent information you’ve got here on this post.

I’ll be returning to your web site for more soon.

Hi, i feel that i noticed you visited my site thus i got here to go back the choose?.I am attempting to in finding things to improve my site!I assume its ok to use a few of your concepts!!

Here is my web blog :: download youtube downloader latest version

I am not sure where you are getting your information, but great topic.
I needs to spend some time learning more or understanding more.
Thanks for great info I was looking for this info for my
mission.

I’m amazed, I have to admit. Rarely do I come across a blog that’s both equally educative and interesting, and let me tell you, you’ve hit the nail on the head.

The problem is something that not enough men and women are speaking intelligently about.

I am very happy I found this during my hunt for something relating
to this.

Here is my web page – free youtube downloader

What’s ?p to all, ho? is all, I think every on? is
getti?g mo?? from this web page, and ?ou? views ar? nice for ne? visitors.

Hello, I do think your web site may be having internet browser compatibility issues.
Whenever I look at your blog in Safari, it looks fine however, if opening in I.E., it has some overlapping issues.

I merely wanted to provide you with a quick heads up! Aside from that, excellent website!

When I originally left a comment I seem to have clicked on the -Notify me when new
comments are added- checkbox and from now on whenever a comment is added I
recieve 4 emails with the same comment. Perhaps there is an easy method you are able to remove me from that service?
Many thanks!

my web page; how to download a song from youtube

I am sure this piece of writing has touched all the internet viewers, its really really pleasant piece of writing on building up new website.

Here is my homepage; youtube to mp4 (http://www.dicastia.com/2011/07/5765-plants-vs-zombies-e.html)

Spot on with this write-up, I honestly think this website needs a lot more attention.
I’ll probably be back again to read more, thanks for the
information!

Nice response in return of this issue with solid arguments
and describing all about that.

My spouse and I stumbled over here by a different web
address and thought I may as well check things out.
I like what I see so i am just following you. Look forward to checking out your web page yet again.

Hi there, all is going perfectly here and ofcourse every one is sharing
facts, that’s genuinely fine, keep up writing.

I visited many web sites however the audio feature for audio songs current at this
site is really excellent.

One reason many businesses fail at providing better customer service is that they try to compete head-to-head
with their competitors. This is contributed to pizza’s cardio protective ingredients, including olive
oil and tomato sauce. Enjoy the experience of making your own pizza and savoring a nutritious meal.

However, with this in mind, there are still some types of
businesses that are more recession-proof than others.
Leaping on a Pizza Planet delivery truck, they manage to catch up with Andy, narrowly avoiding losing him forever.
Enjoy the experience of making your own pizza and savoring a nutritious meal.

One reason many businesses fail at providing better customer service is
that they try to compete head-to-head with their competitors.
For fall, yellows, reds, oranges, and browns are the colors
of choice. First, you choose the type of crust that you want:
personal pan, pan, stuffed crust, or hand tossed (thin).

One reason many businesses fail at providing better customer service is that they try to compete head-to-head
with their competitors. Pizza first started to appear in
the United States when Italian immigrants began arriving in the late 19th century.
First, you choose the type of crust that you want: personal pan, pan, stuffed crust,
or hand tossed (thin).

For added fun some choose to dip theirs in sour cream
or guacamole. Home cooks can reproduce pizza joint quality
pizzas by following a few basic techniques and using a proven
pizza dough formula. And of course, a little
salt and pepper go a long way toward adjusting the taste to suit.

Also there are a ton of online resources for the cock pot.

Pizza first started to appear in the United States when Italian immigrants began arriving in the late 19th century.
These pizza hut coupon codes are also usable in the local outlets but it is always redeemable in
online orders.

Along with specialty pizzas, Domino’s offers Breadbowl Pasta, Oven Baked Sandwiches and Wings.
Leaping on a Pizza Planet delivery truck, they manage to catch up with Andy, narrowly avoiding losing him forever.
Or seek out a bottle of the inscrutable, balsamic, T-Vine Cellars
Psychedelic Rooster “Sticky” Late Harvest ($45)
– a blend of old-vine Petite Sirah and Zinfandel — for that
special ‘David After Dentist’ feeling when indulging on a
rich slice of Nutella pizza pie for dessert.

This article may come as a surprise to you, especially if
you follow a healthy and nutritious diet. Pizza first started to appear in the United States when Italian immigrants began arriving in the late 19th century.
Some offer free breadsticks or similar things on purchase of pizza or other food
whereas some offer promotional or new food item free on the purchase of your favorite
one.

Most pizza places have horrible hard crusts that we usually throw away, but at Pizza
Hut, their crust is edible and yummy. Pizza first started to appear in
the United States when Italian immigrants began arriving in
the late 19th century. The manager of the pizza restaurant have to
create a working program for the location for an entire week.

Gumdrops, mint leaves, and candy canes are a few toppings that make nice Christmas touches.

This is contributed to pizza’s cardio protective ingredients, including olive oil and tomato sauce.
If you’re having interview problems, think about hiring a career coach for a resume review or
an overall fresh perspective on your style.

I read this paragraph fully on the topic of the comparison of most up-to-date and earlier technologies, it’s remarkable article.

my page – livres pdf (Marylin)

Quality posts is the important to invite the visitors to pay
a quick visit the web page, that’s what this web site is providing.

Feel free to surf to my webpage click here

It is not my first time to go to see this site, i am browsing this
site dailly and obtain good facts from here everyday.

my site … terraria download free pc

Heya i’m for the first time here. I found this board and I find
It really useful & it helped me out a lot. I hope to give something back
and aid others like you aided me.

For an awesome response please click the link to this site; Carters Coupons

Wow, amazing blog layout! How lengthy have you been running
a blog for? you make blogging glance easy. The whole look
of your website is wonderful, as smartly as the content material!

Review my web page – google

hey there and thank you for your info – I have certainly picked up something new from right here.

I did however expertise a few technical issues using this site, since
I experienced to reload the website lots of times previous to I
could get it to load properly. I had been wondering if your web
host is OK? Not that I’m complaining, but sluggish loading instances
times will sometimes affect your placement in google and can damage your quality score if advertising and marketing with
Adwords. Well I am adding this RSS to my email
and could look out for much more of your respective exciting content.
Make sure you update this again very soon.

For a wonderful review please click the link to this website: keranique free trial

This tip is suitable for your skin care routine.
These wipes are enriched with acne treatment guide elderflower extract and chamomile that help remove grime and makeup.
Where else but in the natural environment, then you can save a lot of things that you will get a 7-part e-course.
Every now and again you may need to incorporate an extra step
into your daily routine. 4 million spent by North American men and the $682.

my weblog: dhc skincare

Write that on your convertible automobile seat review sheet as you go
along. She is a member of the National Association of Professional Organizers and is working towards becoming
a Certified Professional Organizer. Safety options on this
type of stroller include a front brake and a wrist strap so everything stays in control at all times.

After looking at a handful of the articles
on your website, I truly like your way of blogging.
I added it to my bookmark site list and will be checking back in the near future.
Please check out my web site too and tell me what you think.

Enc?re un article visiblement ?laisant

Have a look at my ?eblog … http://Www.Godemiche.Sx

Hi there, yeah this piece of writing is genuinely pleasant and I have learned lot of things
from it concerning blogging. thanks.

My blog :: crack 40 bit rc4

Vous faîtes ?onstamment des post? attractifs

?lso visit my website – video x francaise

In general, it will usually cost over $50000 for a heavy-duty, used tow truck.
” Do keep receipts and bills of all expenses incurred in the accident to be presented to your insurer. Personal bankruptcy should be a last resort in debt management and debt consolidation.

My web page repossession software

Add pictures, videos, text, and other page elements. If all his
other posts focus purely on promoting other products you already know
it’s not a neutral opinion and never worth pursuing. A website without SEO techniques applied is just a boat travelling without destination.

Hi, I think your blog might be having browser compatibility issues.
When I look at your website in Opera, it looks fine but
when opening in Internet Explorer, it has some overlapping.

I just wanted to give you a quick heads up! Other then that,
awesome blog!

For newest information you have to visit world-wide-web and on web I found this website as a best website for latest updates.

Oh my goodness! Incredible article dude! Thank you so much, However I am having troubles with
your RSS. I don’t understand why I cannot join it.
Is there anyone else getting the same RSS problems? Anyone who knows
the answer can you kindly respond? Thanks!!

Splendide p?ste, encore une fois

My blog … petasse africaine

Un polste pl??n de bons conseils

Review m? web-site; porno algérienne

C’est d? ?onheur de regarder votre site

My blog video porno gratuite

Leave a Reply

XHTML: You can use these tags: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>