Live tracking of Amtrak trains
amtrak.com
amtrak.com
Been also digging into making a PDF parser for their very complicated schedule files, not that they follow it anyway :)
I no longer am in a situation where I need tracking, but a couple of years ago I had the need for tracking my daily commuter train. I had to resort to scraping the website to find the status. If it was late, I had a push notification sent to my phone (a combination of a free app engine deployment and pushbullet). I tried to get integration via Tasker to set my alarm back if the train was more than [x] minutes, but never got to that point.
I really hope that you make some progress on this, though I wish you didn't have to and Amtrak shared the data.
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.> /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
You can also see that the encrypted data stream is coming from https://maps.amtrak.com/services/MapDataService/trains/getTr... which is an Amtrak-hosted backend service.
If you look at the top comment in https://www.amtrak.com/services/maps.trainlocation.html you'll see the name of the consultant that probably worked on this.
// cw: FORCE the bloody stations to show at the initial zoom level. If this is not done, there is
// a possibility that stations will not show in the initial map load.
// I crib this shamelessly from SO...because it is so useful!!
// http://stackoverflow.com/questions/3125065/how-do-i-limit-panning-in-google-maps-api-v3
/*
__$$_jmd - public key
masterSegment - length of data to be extracted from the encrypted response - 55 is just a fake
//FAKE VARIABLES to throw off people hahahahaha
__$_s - salt value
__$_v - iv vale
*/This code is hilarious.
Open https://www.amtrak.com/services/maps.trainlocation.html with a headless Chrome instance and get all of the data from the global `resolver` JS variable (see: `resolver.routes`, `resolver.trains`, etc.)
$.get(_$_sal_5,{ }) .done(function(d){ var x12 = d.trim(); console.log(JSON.parse(__$_s1._$_dcrt(x12.substring(0,x12.length-masterSegment),__$_s1._$_dcrt(x12.substr(x12.length - masterSegment),__$$_jmd).split('|')[masterSegment-88])) )})
I'm sure someone else can take thus further, but, its a mess of javascript. I think its hand-rolled encryption too from a cursory look at the __$_s1._$_dcrt function
[0]: https://github.com/bianjiang/crypto-js-npm/blob/1762940b9eef... [1]: https://maps.amtrak.com/rttl/js/AS.js
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).
For comparison, here's Germany's:
http://www.apps-bahn.de/bin/livemap/query-livemap.exe/dn?L=v...
(might need to zoom in to see more trains)
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.).
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.
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.
Yes, because that economic gain would translate into more taxes, which would be applied across the rest of the country, funding, for example, infrastructure in Kansas.
Of course, that's assuming a reasonable government...
Besides, the map to which you refer is the best possible result of voter preferences. Those who prefer lower spending are bribed into a compromise by those who prefer higher spending. If we didn't see the results you note, that would indicate a failure of democracy.
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.
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.
There is a reason we are called the "United" states - no?
As for the NEC, it suffers from being a very early build. With the exception of the Penn Station approaches, the line is 4-tracked all the way through the NJ-CT corridor. Despite being 4-tracked, the capacity is still insufficient in places. Furthermore, the line in CT in particular is a fairly curvy line that prevents building up high-speed. So getting higher speed trains really requires building new track, a lot of it in topographically interesting locations and in high-priced real estate locations.
On top of that, there's quite a few tunnels and bridges whose condition is best described not as "past its expected lifespan" but rather as "this should have failed already." So improvements on the order of billions of dollars, basically. It doesn't help that Amtrak appears to have decided that money will never be forthcoming, so all of its plans get scope-creeped to massive pie-in-the-sky boondoggles rather than trying to find smaller chunks that can make immediate improvements for relatively cheap. That's why there's a $150 billion plan to get 3-hr Boston-NYC-DC super-express service involving virgin track the entire length of the corridor and brand new stations (requiring extensive tunneling in downtown cores!) in Philly and Baltimore, or why Amtrak insists on building an entire new station annex in NYC when asking for just two new tubes under the Hudson.
The other major issue with mass transit is the longer you wait to build the infrastructure, the cost per foot of track continues to go up. Seattle has a long history with light rail cost overruns.
No excuses.
We have more people stretched out over more land with more varying regions with more varying needs and costs with more conservative social, political and economic values. Nearly all of our trade involves trucking and cargo ships, with freight making up the raw material shipping that isn't time sensitive.
It makes no financial sense whatsoever to fund railroads. We have extensive interstate highways and most of our people have cars. Why pay for a railroad the size of Europe when you don't have to go all over Europe, and all your needs are met via the existing shipping mechanisms? What would be the point?
If you took our cars away, maybe it would make sense, maybe. But before we pay for railroads we might need to pay for our health care or education.
There are more people in Europe, there is more land in Europe, etc. Stop with the fake excuses.
Europeans enjoy all of it: cars, trains, and airplanes. The simple fact is that North America is lame and deficient in passenger rail transportation compared to Europe and East Asia, and the comparison keeps getting worse.
Well duh. The key to making trains useful is having people focused in heavily populated areas. If the US were like Europe, some heavily built rail in the Midwest would cover the vast majority of the population.
Look at this map to put in perspective how much more rail would be required to connect together the major population centers of the US. https://becovegan.files.wordpress.com/2014/09/europe-us-over...
Here's a better map of the European railway network: https://upload.wikimedia.org/wikipedia/en/1/1b/European_rail...
Why would we pay for that?
Amtraks trains from the west coast to Chicago sell the same seat 2x - 3x over the course of one journey. Most people are NOT going end to end. I have ridden the California Zephyr from California to Denver.
I have see others get on (there are seat tickets) :
* in Utah going to Iowa.
* Nevada going further east in Nevada
* etc.
You’re only making the argument harder for Americans (like me!) who like trains by being dismissive of excellent path-dependent and population-dependent reasons why the US passenger train networks died out.
There's a reason we're flush with self-driving car companies and not railroad companies.
I agree that long distance passenger rail mostly doesn't make a lot of financial sense.
Even today, most passengers on Amtrak are NOT riding end-to-end. They are riding between Utah and Nebraska; Or between South Carolina and Vermont; Or Boston to Connecticut.
On the California Zephyr - a coach seat is sold 2-3x times for different segments of the same journey.
Cross country trains in the US are a perennial loss maker, subsidized by under-investing in the profitable dense population corridors, where we could conceivably invest in high speed rail if there was political will to do so (there’s not, but that’s a separate issue).
Replacing cross country Amtrak with comfortable buses would be faster, more reliable, cheaper, and more acccessible to the population that uses trains. Buses are just lower status in the USA, which I think is a pretty silly reason to keep subsidizing Amtrak’s cross country routes.
How much money does the interstate highway system make? Yet we keep funding that for some reason. How much money does you local streets make ?
And before you pull out the "completely different card" remember that both rail and highways serve the exact same societal need: Moving goods and humans from one place to another. We stick humans/goods in a box with wheels and roll them to their destination.
Explain why the box rolling on asphalt should be subsidized but the box rolling on steel should not?
> Replacing cross country Amtrak with comfortable buses would be faster, more reliable, cheaper, and more acccessible to the population that uses trains
I don't believe you have ever taken a bus long distances. I have. Its like being stuck in an airplane. The long distance busses in Thailand are o.k. However you are still glued to your seat in a way that is not true for trains.
Train focused people need to get over themselves on the highway system. That is what path dependency is. Of course, as a train loving person, I wish the automobile industry hadn’t played so many dirty tricks to get us to an investment posture that makes passenger rail irrelevant, but pretending it’s not so doesn’t help.
Pretending that Americans aren’t happy to pay (whether through gas taxes or the occasional new-construction-over-maintenance boondoggle) for highways and local roads is a fantasy.
Americans, on average, don’t like trains. My wife, specifically, refuses to let us travel by train anymore, she hates them. It’s very sad for me, but my wife’s perspective is shared by the vast majority of Americans. They like cars. They like airplanes. They don’t like trains.
Please don't be so broad brush in your statements.
WRT your wife - go to Europe and ride the trains there. Recently I went to Spain. In Spain even the ratty commuter train traveled at 90+ mph.
Ride the TGV or AVE train. Those are quick and comfortable.
If at that point she still feels the way she does fine. But "Americans don't like trains" is a statement that is not correct. On the east coast, Americans use the trains a lot
A much better statement is "Americans don't like an uncomfortable experience"
BTW: http://www.cahighspeedrail.ca.gov/
And in San Francisco Area, Caltrain is electrifying precisely because people love the train so much. Caltrain needs extra capacity and the only way to get that capacity is with electrification. Plenty of Americans seem to like Caltrain. Plenty of Californians are ready to use the HSR project when segments open up.
The vast majority of Americans, when polled, don’t like the idea of taking a train between two cities. I say this as a card carrying member of NARP (they seem to have rebranded themselves RPA, but whatever)!
I just don’t think rail partisans are practicing effective politics by pretending that current US voters support tax expenditure’s on rail.
The average California voter might, just barely, be in favor of interurban rail. I think the jury’s still out on that one, because the actual money that’s been approved by voter’s in Prop 1A is so vastly insufficient to the task, but I agree that at least in California, there’s enough popular support to at least try to make a go of a decent modern train system.
That said, the website for buying tickets was atrociously bad. We had a group of six and the website was full of bugs and broken for tickets with more than five people. You essentially have to do one ticket with 5 and one with 1.
We even went to the gate agent for help and they had similar problems.
Anything like this for Canadian rail? Love to ride from coast to coast up north.
Specifically the part where https://amtk.carto.com/api/v1/map?stat_tag=API&config=%7B%22... 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- 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.
The private sector is the reason for these delays.
http://blog.amtrak.com/2015/02/message-amtrak-regarding-time...
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.
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.
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
The Port Authority of NY and NJ is just such a agency.
Not true.
Chicago to Detroit: 282 miles (4.5h via car) 5hours via train TODAY. (It should really be 2 hours with a train going ~180mph)
Chicago to St. Louis 311 miles (5h via car) 5.5 hours via train (With proper investment: 2.2 hours via HSR train)
Sure end to end may be long; but even then not as long as most people realize.
http://newsfeed.time.com/2012/12/26/china-opens-worlds-longe...
> China launched services Wednesday on the world’s longest high-speed rail route, linking the nation’s capital in Beijing all the way to the country’s southeastern hub of Guangzhou.
> Averaging speeds of up to 186 m.p.h. (300 km/h), the 1,425-mile (2,293 km) route now takes eight hours to complete;
New York to Los Angeles : 2775 miles. Or double the above line. 16 HOURS via High-Speed train. 16 HOURS.
As a point of reference flight time is 6 hours. (Not counting being at the airport 2 hours early, etc.) - so lets just say ~9 hours for a plane. So a plane is twice as fast; but with significantly less capacity.
In fact, high speed rail could also be transformative for international travel; airlines could bundle a high speed rail ticket with a much cheaper transatlantic flight from Philly, as opposed to paying out the nose for a flight out of EWR or JFK.
Does Europe have more and better trains because it has denser cities or does it have denser cities because it has more and better trains?
Probably a little bit of both.
This is probably a major factor that makes Amtrak less preferable than driving even when it’s available - once you get to almost any place in the US, you’d prefer to have your car. Amtrak stations also don’t generally have convenient car rental locations with extended hours like airports do, so that’s not even an option to deal with it.
I don’t see why we need to subsidise passenger rail. Autonomous helis and passenger planes seem like a better bet.
From the (admittedly not great) source of CAHSR:
> Providing the equivalent new capacity on the state’s highways and airports would cost more than double the investment required to develop a high-speed rail system between San Francisco and Los Angeles. If it was even possible, that would mean building 4,300 new highway lane miles, 115 additional airport gates, and four new airport runways at an estimated cost of $158 billion. [...] Caltrans estimates operations and maintenance costs on those new highway lanes at $132.8 billion for over 50 years.
[1] Deutsche Bahn is owned by the German government, but unlike Amtrak is operated as a private company.
And, when you talk about government investments into the two other modes of transportation, I presume you mean air and highways. You forgot waterways - also created/improved with government investment.
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)
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.