It is currently June 16th, 2024, 2:17 pm

Train Tracking

General topics related to Rainmeter.
Welsh
Posts: 6
Joined: May 20th, 2024, 6:23 pm

Train Tracking

Post by Welsh »

Good afternoon,

I have been looking for a train tracker for while but I can't even find anything even close. It could be anything from telling me if my train is delayed, the location of the train or even the expected time of arrival. I really don't mind if it something basic or advanced or even a link to a RSS Feed I could possible use.

Thank you. :D
User avatar
Yincognito
Rainmeter Sage
Posts: 7434
Joined: February 27th, 2015, 2:38 pm
Location: Terra Yincognita

Re: Train Tracking

Post by Yincognito »

Welsh wrote: May 22nd, 2024, 10:23 am Good afternoon,

I have been looking for a train tracker for while but I can't even find anything even close. It could be anything from telling me if my train is delayed, the location of the train or even the expected time of arrival. I really don't mind if it something basic or advanced or even a link to a RSS Feed I could possible use.

Thank you. :D
First, if by any chance you thought about that, we don't do skin requests - what we can do is help you write your own skin, if that's the case.
Secondly, your question is an extremely broad one - you didn't specify your region / country to begin with, cause there isn't a global train tracker.
Thirdly, googling for sites offering what you need is typically your job - once a suited one is found, we could help in getting data from it, if possible.
Profiles: Rainmeter ProfileDeviantArt ProfileSuites: MYiniMeterSkins: Earth
Welsh
Posts: 6
Joined: May 20th, 2024, 6:23 pm

Re: Train Tracking

Post by Welsh »

Yincognito wrote: May 22nd, 2024, 3:18 pm First, if by any chance you thought about that, we don't do skin requests - what we can do is help you write your own skin, if that's the case.
Secondly, your question is an extremely broad one - you didn't specify your region / country to begin with, cause there isn't a global train tracker.
Thirdly, googling for sites offering what you need is typically your job - once a suited one is found, we could help in getting data from it, if possible.
Sorry I do apologise I had to quickly type this whiles in work.

It isn't a skin request I am looking for, it some info on how to make one. I never really played with any language other than C# hence the reason I am looking for some help. The region/area I am looking to make one for is Wales/England.

Thank you.
User avatar
Yincognito
Rainmeter Sage
Posts: 7434
Joined: February 27th, 2015, 2:38 pm
Location: Terra Yincognita

Re: Train Tracking

Post by Yincognito »

Welsh wrote: May 22nd, 2024, 7:34 pm Sorry I do apologise I had to quickly type this whiles in work.

It isn't a skin request I am looking for, it some info on how to make one. I never really played with any language other than C# hence the reason I am looking for some help. The region/area I am looking to make one for is Wales/England.

Thank you.
No problem, thanks for the clarification. Well, before even starting to make your skin, you should find a "source" where you get that train data from. Usually, that's a site, since even if you had a local static "database" with train departures and arrivals, the "live" part regarding delays or train location can only be retrieved from some frequently updated online source.

I saw some UK sites providing such data, but you should search for these yourself, since being from there you know better than me if the provided info is comprehensive, properly updated, and overall correct. Such a site should be able to be parsed by a WebParser measure:
https://docs.rainmeter.net/manual/measures/webparser/
meaning that the info you're looking for should be visible in the HTML code when you right click on the page and choose to view the page source (CTRL+F to search some of the desired field values should make it clear).

So, once you have one or two such sites that we can use, then we can talk about the code for such a skin and how to approach this. ;-)

P.S. My bad, didn't make the connection between your nickname and your location. :oops:
Profiles: Rainmeter ProfileDeviantArt ProfileSuites: MYiniMeterSkins: Earth
Welsh
Posts: 6
Joined: May 20th, 2024, 6:23 pm

Re: Train Tracking

Post by Welsh »

Yincognito wrote: May 22nd, 2024, 8:05 pm No problem, thanks for the clarification. Well, before even starting to make your skin, you should find a "source" where you get that train data from. Usually, that's a site, since even if you had a local static "database" with train departures and arrivals, the "live" part regarding delays or train location can only be retrieved from some frequently updated online source.

I saw some UK sites providing such data, but you should search for these yourself, since being from there you know better than me if the provided info is comprehensive, properly updated, and overall correct. Such a site should be able to be parsed by a WebParser measure:
https://docs.rainmeter.net/manual/measures/webparser/
meaning that the info you're looking for should be visible in the HTML code when you right click on the page and choose to view the page source (CTRL+F to search some of the desired field values should make it clear).

So, once you have one or two such sites that we can use, then we can talk about the code for such a skin and how to approach this. ;-)

P.S. My bad, didn't make the connection between your nickname and your location. :oops:
First I'd like to say I appreciate all the help and time you spent to help me on this subject.

I have found these two websites, that maybe could help making this skin.

https://tfw.wales/
https://www.thetrainline.com/

I have also attached two photos, one containing the idea on what I am looking for(It's just an edit of the skin you just posted :D ), and anther with a inspect element of the website to see if it's correct on what we looking for :)

Image
Image
User avatar
Yincognito
Rainmeter Sage
Posts: 7434
Joined: February 27th, 2015, 2:38 pm
Location: Terra Yincognita

Re: Train Tracking

Post by Yincognito »

Welsh wrote: May 22nd, 2024, 9:11 pm First I'd like to say I appreciate all the help and time you spent to help me on this subject.

I have found these two websites, that maybe could help making this skin.

https://tfw.wales/
https://www.thetrainline.com/

I have also attached two photos, one containing the idea on what I am looking for(It's just an edit of the skin you just posted :D ), and anther with a inspect element of the website to see if it's correct on what we looking for :)

Image
Image
Well done. Yeah, the Inspect output is not always the same as the actual Page Source (or whatever it is called in MS Edge), but anyway, you completed the first step successfully. :thumbup:

The second step is to see what kind of pattern to use for the URL address and actually test it by temporarily downloading it to see if you can indeed find the desired values in it. Here is a very basic structure that you can use for this:

Code: Select all

[Variables]

[Rainmeter]
Update=1000
AccurateText=1
DynamicWindowSize=1
BackgroundMode=2
SolidColor=47,47,47,255

---Measures---

[WebParserParent]
Measure=WebParser
URL=<YourURLAdressHere>
UserAgent=Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/92.0.4515.159 Safari/537.36 Edg/92.0.902.84
RegExp=(?siU)^(.{30}).*$
Debug=2

[WebParserChild1]
Measure=WebParser
URL=[WebParserParent]
StringIndex=1

---Meters---

[WebParserChild1Value]
Meter=String
FontFace=Consolas
FontColor=255,255,255,255
Padding=5,5,5,5
FontSize=16
AntiAlias=1
MeasureName=WebParserChild1
Text=WebParser Child 1 Value:#CRLF##CRLF#%1
A few details about the code above...

I intentionally left the URL option blank so you can find yourself what to put there. The address in your screenshot isn't suited for that, since it's a general one and doesn't have a query string where you can input the parameters of your search, like the departure and arrival locations and others. You can find this address by hovering your mouse and right clicking it to copy the address over either your History list, or, preferably, by opening the Network tab from the Developer Tools in your browser and reloading / refreshing the page to see all the connections attempted by the site (not sure how these are called in MS Edge, I use Chrome). If such a query string featured address calls an API (which the 1st site you posted actually does, but careful with the 2nd as you might get blocked since they're a bit paranoid), the better, since you'll get a .JSON response that only has what you need, without all the unnecessary stuff from a regular page.

The code above has a WebParser parent measure and a WebParser child one. The former is where most options are (e.g. the UserAgent to make the site think you're opening it from the browser, the RegExp to parse the response and capture parts of it for the children via the round brackets, or the Debug set to 2 to temporarily download the response as WebParserDump.txt in the same folder as your skin's .ini file), while the latter is where you extract the captures that were marked by ( and ) in the parent's RegExp option. Currently, for simplicity and ease of understanding, the parent's RegExp makes only 1 capture, consisting of the first 30 characters in the response, but obviously you can examine the entire response in the aforementioned .txt file.

As for the meter, it simply gets the WebParser child measure in its MeasureName option, which it then references as %1 in its Text option, in order to show the result to the user. As a principle, the measure in a potential MeasureName2 will be referenced as %2 in the Text option from the meter, and so on.

Good luck in finding the suited URL! If you're not sure which one is the most usable, just paste the relevant ones here and I'll indicate it. Unfortunately, you'll see that even in the proper ones, locations are in the form of "codes", e.g. CDF for Cardiff Central, or MTA for Mountain Ash. This will make searching for routes difficult, unless you get a database of such locations and their codes from somewhere on the site, but it's almost the same for the second link you mentioned, so it is what it is. :confused:

P.S. Don't forget to look for the desired values or fields in the downloaded .txt, to make sure that what you get is useful for what you need. Also, don't abuse polling the site(s), if you don't want to be blocked: once you get the downloaded response in the .txt, you can examine it locally, and optionally unload the skin until you potentially change the URL again.
Profiles: Rainmeter ProfileDeviantArt ProfileSuites: MYiniMeterSkins: Earth