I live in Belfort and I do use the bus service Optymo daily and need to continuously check fastly when the next bus will be coming. However, nothing but a big PDF is given to us to know it. What I needed is a way to check instantly from my notifications the next buses.
Unfortunately, the company Optymo has no API available. I needed to find a way to recover informations such as the next stops, all the stops names and all the lines with the stops.
The little QR Codes
QR Codes are available to check the next buses at a given stop. So let's use it. The most interesting data of the web page of this QR code is its URL. It contains some sort of slug telling what is the stop name and an index to know what line it is. However the slug is very irregular and depends a lot of the stop name which can be complicated sometimes.
Ex: this url https://siv.optymo.fr/passage.php?ar=Utb01 which slug is Utb01, has a name which is Techn'hom 1/UTBM
I cannot spend weeks searching each slug for each stop and line. I need to find another solution.
The Optymo website has something really interesting. It has a Google map with all the stops integrated (link)! But where did he find its stops? let's open the browser network traffic tool :
Wow, that's a lot of traffic! Hard to know what is what but the domain names might help me.
This sounds cool : "interactive map"?
The bus positions in real time ? Not interesting for me.
var srcFileBus = modePrm == "demo" ? "itrsub/get_markers_demo.php" : modePrm == "vide" ? "itrsub/get_markers_vide.php" : modePrm == "urb" ? "itrsub/get_markers_urb.php" : modePrm == "sub" ? "itrsub/get_markers_sub.php" : "itrsub/get_markers_urb.php";
What is this script? belfort.js ? There are some API keys, let's see what I can do with it.
stopsuggestionengine.js ? That's what I am looking for!
Nice! There is a URL that use the API key to get the stops!
"url" : '//app.mecatran.com/' + apiPath + instance + '?includeStops='+ includeStops +'&includeStations='+ includeStations +'&apiKey=' + apiKey
Now let's get them! What it this thing?
That might be XML. Let's check the source code of the page. Now this is better!
Yes! Let's download it. I will parse it later to get everything I need. Now I need to know the next bus for a given stop. When I click on a bus stop a tooltip is displayed :
This page looks like the one from the QR code but this one works for all the stops in the same location. The URL may be different. I'll see what it is with the code inspector. Hello my friend!
https://siv.optymo.fr/passage.php?ar=technhom1utbm&type=1 That's a win! The URL slug is much easier to guess. It is only alphanumeric characters in lowercase. Now that I have all my URLs and my stops I can start working on the data model for my app. I will be using Android Studio and Java to do it. First I will make a Java desktop project to organize all my data and see how I can achieve my goals.
Thanks for reading. See you later for the next part.