
Live tracking of Amtrak trains - pm24601
https://www.amtrak.com/track-your-train.html
======
reustle
I've been trying to crack the encryption on this for a while. I want to make a
free public train status api (I built amtrak.io). If anyone would like to help
improve public open data around Amtrak, please contact me.

Been also digging into making a PDF parser for their very complicated schedule
files, not that they follow it anyway :)

~~~
jonknee
A comment in the source code seems to describe what you need to do:

    
    
       MasterSegment is the length of the string at the end of the encrypted data that contains the secret key
       To decrypt - we do the following
       1. Take masterSegment (88) length - from the right of the data - this has the private key
       2. Everything from 0 to the end - master segment is the raw data - that needs to be decrypted
       3. Decrypt the 88 characters using the public key - that will give you a pipe separated string of the private key (random guid from MDS) and a time stamp (to scramble it)
       4. Now use the private key and decrypt the data stored from step 2.
       5. Parse the decrypted data - and rejoice
       6. KSUE -means key issue
       7. __$$_jmd - the public key that we obtain
       
       __$_s1 : variable name for the Security object in the Helper.js file - that file has the calls to actually decrypt the data.

~~~
iancarroll
This is insane. How much time did they put in to this pointless obfuscation,
and then why would they go and document it all?

~~~
jonknee
I would guess "management", probably under the name of Homeland Security. It
seems to be some spaghetti code of loops/callbacks written by a frustrated
jQuery developer. Here are some more fun tidbits:

> / _MasterZoom is the sum of the zoom levels from the routes_list.json file.
> That is the index in the routesList.v.json - > arr array where we have the
> public key stored. IF THE ROUTES_LIST CHANGES, REMEMBER TO CHANGE THE INDEX
> TO BE CORRECT _/

> / _Salt Value - the element is at the 8th position. So we can essentially
> pick any number from 0-100 (length of the s array in the file), get the
> length of the element, and then go to that index the following funky looking
> code will evaluate to 8. Salt has a length of 8_ /

> / _Initialization Vector Value - the element is at the 32th position. So we
> can essentially pick any number from 0-100 (length of the IV array in the
> file), get the length of the element, and then go to that index the
> following funky looking code will evaluate to 32 - IV has a length of 32_ /

And my favorite:

> masterSegment - length of data to be extracted from the encrypted response -
> 55 is just a fake //FAKE VARIABLES to throw off people hahahahaha

~~~
AdamJacobMuller
"Homeland Security"... and i'm on another list. Great.

------
softwaredoug
You’ll pry Dixielands Amtrak tracker from my cold, dead hands Amtrak!!

[http://www.dixielandsoftware.net/Amtrak/status/StatusMaps/](http://www.dixielandsoftware.net/Amtrak/status/StatusMaps/)

~~~
apple4ever
Yes yes! I love that site. I actually use a simple Python script to parse the
data on that site and send me a notification every morning and afternoon of
how on time my train is.

Its sad I have to do that. Amtrak should have that system already (they sort
of do- but only for trains that are 20 minutes late).

------
ucaetano
Wow, this is depressing.

For comparison, here's Germany's:

[http://www.apps-bahn.de/bin/livemap/query-
livemap.exe/dn?L=v...](http://www.apps-bahn.de/bin/livemap/query-
livemap.exe/dn?L=vs_livefahrplan&livemap=yes)

(might need to zoom in to see more trains)

~~~
rayiner
Not really. In terms of density, the only part of the U.S. comparable to
Germany (600 people per square mile) is the northeast megalopolis (900 people
per square mile). Also, your map includes regional trains, while the Amtrak
map is just inter-city. This is a more appropriate point of comparison:
[https://4194e6d9-a-62cb3a1a-s-
sites.googlegroups.com/site/no...](https://4194e6d9-a-62cb3a1a-s-
sites.googlegroups.com/site/northeastrailmap/Northeast_Rail_Map_2014-12-29.png?attachauth=ANoY7cqyBCSOnE9TzEzq6kJ4XdUvKVREN65Htw55NvMFavebEqmPl9KmEjUG9dCN69_xhWDMSOCODqRQfzshYvnO02A0wYtd1IwoPa0vSvBapIojSvefH_n_ceGS6LIeHc91nhDdSIwLglIlk3lNMmamt3eJuN6lW0iYDGCx3jbo-
mcgKpowYEYXYvRkanYFSiDoqoeJmbfaRkrdN6fSFhLbxqaxaBMeTt1GBhAHmX2TBg-
fiOyCVMHh7rFb_jz7Y5cEjDFxQuMU&attredirects=0). (Note that the middle of
Pennsylvania, or upstate New York, or almost all of Virginia are not part of
the northeast megalopolis: [http://statchatva.org/files/2015/11/Northeast-
Corridor2-991x...](http://statchatva.org/files/2015/11/Northeast-
Corridor2-991x1024.jpg)).

~~~
ucaetano
> the only part of the U.S. comparable to Germany (600 people per square mile)
> is the northeast megalopolis (900 people per square mile)

Which has >50M people, 2/3 of the population of Germany. In that comparison,
that region should have then 2/3 of the rail network of Germany. It has 1
medium-speed rail line.

> while the Amtrak map is just inter-city

The Capitol Corridor, for example, is comparable to a Regio train in Germany
(but slower, shittier, etc.).

~~~
rayiner
> Which has >50M people, 2/3 of the population of Germany. In that comparison,
> that region should have then 2/3 of the rail network of Germany. It has 1
> medium-speed rail line.

What the U.S. also has is 275 million other people who (1) won't benefit from
such a rail network; and (2) won't vote to fund it; (3) will condition _any_
support of Amtrak on useless long-distance routes through low-density regions
that sap money away from the only corridor in the U.S. where rail makes sense.
And it's a _completely rational_ decision for those people.

~~~
ucaetano
Oh, sure, I'm very familiar with the problems. That's why it is depressing.

And it isn't even a rational decision for those people, the economic gains
would largely outweigh the costs, being a net-positive for the rest of the
country.

~~~
rayiner
Even if that's true (which I'm not sure about), would economic gains from
high-speed rail between New York and DC accrue to a taxpayer in Kansas? Or
would a taxpayer in Kansas be bankrolling increased prosperity in a far-off
part of the country that's already well off?

~~~
nashashmi
There is a website somewhere that says how much benefit each state gets from
the federal government versus how much their people put in. Half the states
lose money. And half gain. And all those gaining states have low density.
While all the losing states are in the North East.

~~~
hueving
>much benefit each state gets from the federal government versus how much
their people put in

No, that's not what it shows. It talks about the balance of tax revenue vs
subsidies for each state. That distinction is critical and can completely
change the balance of which state is receiving more 'benefit'.

If this confuses you, consider the following scenario. State A is filled with
farmers subsidized to grow food so everyone in State B has a stable an cheap
food supply. From a purely monetary accounting perspective A looks like a
leech, but in reality it's a major part of the success of B (and the rest of
the states it trades cheap food with) and separating them is a pointless
exercise designed to score political points.

This applies to any states receiving subsidies to support the rest of the
states (e.g. ones with military bases, government research labs, etc).

All of the states that look like they are self-sustaining mega economies would
fall apart without the neighboring states that they suck cheap power, land
use, etc off of. Don't perpetuate the myth that some states are just carrying
the rest of them, it's just designed to divide people.

~~~
mercutio2
You’re saying just getting rid of the farm bill, with all its subsidies for
agriculture, would hurt urban areas by destroying production? That seems like
a real stretch of economic theory, to me. Subsidizing the low-margin producers
in certain states and putting up agricultural tariffs like we do is really not
benefitting rich urban areas.

Consumers in NYC don’t sit around saying, “thank goodness I have this
expensive cane sugar and cheap high fructose corn syrup because of the
exorbitant tariffs on Brazilian sugar and subsidized crop insurance for corn
production!”

New Yorkers also don’t get much direct benefit from Conservation Reserve,
where farmers are paid to do restoration work on marginal farmland rather than
sending the topsoil down the river.

Finally, SNAP, which makes up 75% of the cost of the farm bill, last time I
checked, is a conditional transfer directly to consumers, so SNAP tax
expenditures to agricultural states are feeding poor people in those states,
not subsidizing urban consumers in other states. That seems like a fine way to
do the accounting to me.

I support the conservation bits of the farm bill, and SNAP and Medicaid (which
dominate interstate transfer payments), but not because they benefit rich
urban states directly; I don’t think they do at all. I just think top soil
conservation and providing food and health care to the poor are moral
mandates, and I’m philosophically in favor of transfer payments from the rich
to the poor.

~~~
hueving
You're thesis seems to be predicated on the notion that everyone in rich
states is rich. I suggest you find some retail workers in a rich area and ask
if doubling the cost of their food and energy would have an impact on them.

------
yellowcherry
Yay! An official version. This site has been doing it "unofficially" for
years, but I'm sure even they will be happy there's a real Amtak version now.

[https://asm.transitdocs.com/](https://asm.transitdocs.com/)

~~~
claudenm
It's weird (to me) that this submission is getting upvoted now. It's existed
for five years (I helped work on a small part of it).

~~~
reustle
So, any pointers on where we can find the data source? :)

------
gok
First train I tapped was 9 hours late. So yeah that’s definitely Amtrak!

------
lqet
We did something similar on a global scale a few years ago
([http://tracker.geops.de/?z=9&s=1&x=901854.6472&y=5948883.686...](http://tracker.geops.de/?z=9&s=1&x=901854.6472&y=5948883.6866&l=transport)).
Unfortunately, it is still very difficult to obtain official real-time data
(even simple delay information).

------
JKCalhoun
Makes me want to hop on the Zephyr.

Anything like this for Canadian rail? Love to ride from coast to coast up
north.

~~~
pm24601
You should - very beautiful scenery. Including canyons with no roads through
them.

------
geuis
Two fingers to drag on mobile? Who built this thing?

~~~
edhu2017
somebody with conjoined fingers!

------
eurticket
I've always wanted something like this for the buses in my area.

------
exikyut
Huh, the "carto" service this calls out to seems a bit interesting. Surely
someone else has noticed this...

Specifically the part where
[https://amtk.carto.com/api/v1/map?stat_tag=API&config=%7B%22...](https://amtk.carto.com/api/v1/map?stat_tag=API&config=%7B%22version%22%3A%221.3.0%22%2C%22stat_tag%22%3A%22API%22%2C%22layers%22%3A%5B%7B%22type%22%3A%22cartodb%22%2C%22options%22%3A%7B%22sql%22%3A%22SELECT%20*%20FROM%20national_route_shape_v16%22%2C%22cartocss%22%3A%22%23layer%20%7Bline-
color%3A%20%23FF031D%3Bline-
width%3A%202%3B%7D%22%2C%22cartocss_version%22%3A%222.1.0%22%7D%7D%5D%7D&callback=_cdbc_2486699862_1)
is a URL-encoded request for the following encoded JSON:

    
    
      https://amtk.carto.com/api/v1/map?stat_tag=API&config={
        "version":"1.3.0",
        "stat_tag":"API",
        "layers": [{
           "type":"cartodb",
           "options":{
              "sql": "SELECT * FROM national_route_shape_v16",
              "cartocss": "#layer {line-color: #FF031D;line-width: 2;}",
              "cartocss_version": "2.1.0"
           }
        }]
      }
    

In case you don't see it:

    
    
      SELECT * FROM ...
    

It does seem to be going through some mangling and parsing however. Carto's
website doesn't look like it's from 1994, so my guess is that Someone™ read a
book on "rapid-turnaround web development" upside down a few years ago, and
now the current devs have to live with some poor decisions (raw SQL as form
input) for the sake of legacy compatibility.

This being said, the error messages are quite fun:

    
    
      > SELECT version();
      {"errors":["Postgis Plugin: ERROR:  column \"the_geom_webmercator\" does not exist\nLINE 1: ...ECT ST_AsTWKB(ST_Simplify(ST_RemoveRepeatedPoints(\"the_geom_...\n                                                             ^\nin executeQuery Full sql was: 'SELECT ST_AsTWKB(ST_Simplify(ST_RemoveRepeatedPoints(\"the_geom_webmercator\",1e-05),1e-05,true),5) AS geom FROM (SELECT version()) as cdbq WHERE \"the_geom_webmercator\" && ST_SetSRID('BOX3D(-20037508.3 20037508.25881302,-20037508.25881302 20037508.3)'::box3d, 3857)'\n"],"errors_with_context":[{"type":"layer","message":"Postgis Plugin: ERROR:  column \"the_geom_webmercator\" does not exist\nLINE 1: ...ECT ST_AsTWKB(ST_Simplify(ST_RemoveRepeatedPoints(\"the_geom_...\n                                                             ^\nin executeQuery Full sql was: 'SELECT ST_AsTWKB(ST_Simplify(ST_RemoveRepeatedPoints(\"the_geom_webmercator\",1e-05),1e-05,true),5) AS geom FROM (SELECT version()) as cdbq WHERE \"the_geom_webmercator\" && ST_SetSRID('BOX3D(-20037508.3 20037508.25881302,-20037508.25881302 20037508.3)'::box3d, 3857)'\n","subtype":"query","layer":{"id":"layer0","index":0,"type":"mapnik"}}]}
    

The ">" prompt above is from this 4-second hacky script to make a shell:

    
    
      tput reset; while true; do read -p '> ' x; echo '{"version":"1.3.0","stat_tag":"API","layers":[{"type":"cartodb","options":{"sql":"'"$x"'","cartocss":"#layer {line-color: #FF031D;line-width: 2;}","cartocss_version":"2.1.0"}}]}' | curl "https://amtk.carto.com/api/v1/map?stat_tag=API&config=$(php -r 'print urlencode(fgets(STDIN));')"; echo; done

------
mkempe
Great to have access to that information.

\- Empire Builder near Minneapolis: 10h late.

\- Empire Builder near Kalispell: 6h late.

Passenger train service in America needs to be returned to the private sector,
without any interference by Congress. [added] Or you can watch the government
fuck-up and quickly cast blame on the private sector. Private passenger
services would have different, satisfying contracts with the rail owners; this
is what companies do in the private sector some people apparently hate so
much. There was a time when privately operated railroads were reliable in this
country.

Freight currently has deleterious right of way _because this is what
bureaucrats have agreed to. Imagine these bureaucrats did something similar on
the highways you all love so much, making passenger vehicles wait on the side
to let trucks move a little faster._

~~~
michaelleslie
Ahh, the classic, "We've defunded and gutted this government program. Look!
Government doesn't work!" that the American right traffics in.

The private sector is the reason for these delays.

[http://blog.amtrak.com/2015/02/message-amtrak-regarding-
time...](http://blog.amtrak.com/2015/02/message-amtrak-regarding-time-
performance/)

~~~
kevin_thibedeau
Except that Amtrack is consistently late on the NEC and other regional lines
that they have priority on. Really annoying when you are on a train waiting to
pull out of a station and can't go because a late Amtrack has priority.

~~~
michaelleslie
That's a good point.

I know Penn is a major bottleneck (we have Christie to thank for that after
killing ARC), and there's the added problem of delays conflicting with Metro
North/NJT schedules.

We need infrastructure investment in dense corridors if we're to get anywhere
remotely near European or Asian standards.

~~~
rayiner
It's not clear to me we even have "dense corridors" like in Europe. I was in
Munich, and driving in from the airport what struck me is that the city just
_ends_. The city is 1.5 million people. Then there is another million or so
people in the metro area, and 30 minutes outside of downtown its farms.
Contrast Philadelphia, which is at the center of the U.S. "northeast
megalopolis." It's also 1.5 million people, but there are another _4.5
million_ people in the surrounding sprawl. You can go an hour outside Philly
in almost any direction and still be in suburban sprawl. That totally changes
the transit equation. You build high-speed rail to Munich, and you're serving
more than half the population of the metro area. You build high-speed rail to
Philly, and you serve just a quarter of the population (while the other three
quarters is stuck paying for something they have to drive to get to anyway).

This is true at multiple levels of scale. Compare Ulm, Germany to Richmond,
VA. Both are about 100-200k people. Aside from a few appendages, you hit farms
2-3 miles outside Ulm in most directions. Richmond, by contrast, is surrounded
for 8-10 miles in all directions by suburbs, which have another million
people. When it comes to voting for things like transit or train service, the
people in the city that might benefit from it are totally outnumbered by all
the people in the suburbs who can't.

~~~
ams6110
I think this is a good observation. The USA is just too spread out for rail
travel to really work well. Most European countries are no bigger than a
medium sized US state, and the cities are denser and smaller than American
cities. It's easier to run a rail route between two European cities and
realistically serve most of the people in those cities. And the cities aren't
so far apart that flying becomes a really time-saving option.

~~~
mkempe
You are deeply wrong and need to look at proper maps.

Europe is 33% larger than the USA (contiguous 48).

[added] Note sure why this _fact_ would be down-voted. We don't include
Greenland or e.g. French Polynesian dependencies in the European total. Sweden
is slightly larger than California, with 1/4 the population. Et caetera.
Really, you should look at maps, population facts, as well as the extent and
quality of railroads.

And quit pretending that there is no rail connection _across_ Europe. [1]
America is failing when it comes to 21st century pubic transportation. Angrily
lagging behind European, Japanese [2], or Chinese [3] railroads is not a
healthy path.

[1] [https://en.wikipedia.org/wiki/High-
speed_rail_in_Europe](https://en.wikipedia.org/wiki/High-speed_rail_in_Europe)

[2]
[https://en.wikipedia.org/wiki/Shinkansen](https://en.wikipedia.org/wiki/Shinkansen)

[3] [https://en.wikipedia.org/wiki/High-
speed_rail_in_China](https://en.wikipedia.org/wiki/High-speed_rail_in_China)

~~~
rayiner
Define "Europe." "Europe" doesn't have high speed rail. Germany, France, etc.,
do, and those countries are a lot denser than the U.S. and most U.S. states.
Moreover, U.S. cities are shaped very differently from Western European ones.
Take the ratio of (city population) / (metro area population) and compare the
U.S. state capitals to European capitals. In Europe, it's common for the
majority of a metro area to live within city limits, even in small cities. In
the U.S., the only major city that gets close to that benchmark is New York.

~~~
pm24601
The arbitrary government boundaries are not really relevant.

~~~
AnimalMuppet
Given that the governments fund the passenger trains, those boundaries are
extremely relevant.

~~~
pm24601
Not really, the city government works with the county government, which works
with the state government, which works with the federal government.

The Port Authority of NY and NJ is just such a agency.

------
smokeyBread
Are there seriously some US states with no trains? e.g. wyoming, south dakota

Or is Amtrak just one company, and there are other train companies offering
different routes? It just seems like such a tiny number of routes (especially
compared to Europe train routes)

~~~
mercutio2
The USA is much, much, much less dense than Europe.

Anyway, yes, there are no cross country passenger trains in many states, and
even for the states that have them they exist as congressional pork, at this
point.

It is much faster and cheaper to drive in the US (the train max speeds are
slower than the highways), and slightly cheaper and vastly faster to fly.

Only in dense regions, like California and the northeast, are inter-urban
trains a meaningful thing in the USA.

Freight trains, on the other hand, are a much bigger deal in the USA than in
Europe.

