Advertisement
ZTTrak

AMTKBeta

May 23rd, 2024 (edited)
626
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. Clear-Host
  2. Write-Output "
  3. ███████ ████████ ████████ ██████   █████  ██   ██     ██████  ███████ ██    ██ ███████ ██       ██████  ██████  ███    ███ ███████ ███    ██ ████████
  4.   ███     ██       ██    ██   ██ ██   ██ ██  ██      ██   ██ ██      ██    ██ ██      ██      ██    ██ ██   ██ ████  ████ ██      ████   ██    ██    
  5.  ███      ██       ██    ██████  ███████ █████       ██   ██ █████   ██    ██ █████   ██      ██    ██ ██████  ██ ████ ██ █████   ██ ██  ██    ██    
  6. ███       ██       ██    ██   ██ ██   ██ ██  ██      ██   ██ ██       ██  ██  ██      ██      ██    ██ ██      ██  ██  ██ ██      ██  ██ ██    ██    
  7. ███████    ██       ██    ██   ██ ██   ██ ██   ██     ██████  ███████   ████   ███████ ███████  ██████  ██      ██      ██ ███████ ██   ████    ██    
  8.                                                                                                                                                      
  9.                                                                                                                                                      "
  10.  
  11. Write-Output "Please note that Amtrak Station NAMES are NOT supported, if you do not know what Amtrak Station Codes are, I recommend searching up the station code."                                                                                                                                                                
  12. $stationCode = Read-Host "Enter the Amtrak Station Code you would like to monitor."
  13. Write-Output "Your station status will load shortly, if your data loads but an error pops up, please ignore it unless your data for that station does not show up"
  14.  
  15.  
  16. $url = "https://dixielandsoftware.net/Amtrak/solari/data/" + $stationCode + "_schedule.txt"
  17. $url2 = "_schedule.txt"
  18. $currentDate = Get-Date
  19. $year = $currentDate.Year
  20. $month = $currentDate.Month.toString("D2")
  21. $day = $currentDate.Day
  22. $startWriting = 0
  23. $downloadsPath = "$HOME\Downloads"
  24. $fileName = "ZTK_DEVELOPMENT_$($year)_$($month)_$($day)_$($stationCode)_STATION.txt"
  25. $filePath = Join-Path -Path $downloadsPath -ChildPath $fileName
  26.  
  27. $urlfinal = $url + "" + $url2
  28.  
  29.  
  30. try {
  31.     $response = Invoke-WebRequest -Uri $url -UseBasicParsing
  32.  
  33.     if ($response.StatusCode -eq 200) {
  34.         Write-Output $response.Content
  35.         $jsonObject = $response.Content | ConvertFrom-Json
  36.  
  37.         $currentDate = Get-Date
  38.  
  39.  
  40.         $year = $currentDate.Year
  41.         $month = $currentDate.Month
  42.         $day = $currentDate.Day
  43.         Write-Output $year
  44.         Write-Output $month.toString("D2")
  45.         Write-Output $day      
  46.         $phrase2 = "</a>"
  47.         Clear-Host
  48.         Write-Output "
  49.        ███████ ████████ ████████ ██████   █████  ██   ██     ██████  ███████ ██    ██ ███████ ██       ██████  ██████  ███    ███ ███████ ███    ██ ████████
  50.           ███     ██       ██    ██   ██ ██   ██ ██  ██      ██   ██ ██      ██    ██ ██      ██      ██    ██ ██   ██ ████  ████ ██      ████   ██    ██    
  51.          ███      ██       ██    ██████  ███████ █████       ██   ██ █████   ██    ██ █████   ██      ██    ██ ██████  ██ ████ ██ █████   ██ ██  ██    ██    
  52.         ███       ██       ██    ██   ██ ██   ██ ██  ██      ██   ██ ██       ██  ██  ██      ██      ██    ██ ██      ██  ██  ██ ██      ██  ██ ██    ██    
  53.        ███████    ██       ██    ██   ██ ██   ██ ██   ██     ██████  ███████   ████   ███████ ███████  ██████  ██      ██      ██ ███████ ██   ████    ██    
  54.                                                                                                                                                      
  55.                                                                                                                                                      "
  56.        
  57.         foreach ($item in $jsonObject) {
  58.             Write-Output "--=New Section=--"
  59.             $trainnonew = $item.trainno
  60.             $outputString = $trainnonew -replace [regex]::Escape($aphrase)
  61.             Write-Output $newTrainNumber
  62.             Write-Output "Train Number: $($outputString)"
  63.             Write-Output "Scheduled: $($item.scheduled)"
  64.             Write-Output "Scheduled 24h: $($item.scheduled24)"
  65.             Write-Output "Service: $($item.service)"
  66.             Write-Output "Destination: $($item.destination)"
  67.             Write-Output "Origin: $($item.origin)"
  68.             Write-Output "Remarks/Boarding: $($item.remarks_boarding)"
  69.             Write-Output "New Time: $($item.newtime)"
  70.             Write-Output "New Time 24h: $($item.newtime24)"
  71.             Write-Output ""
  72.         }  
  73.         while ($true) {& $refreshDataStart-Sleep -Seconds 30}
  74.     } else {
  75.         Write-Output "Failed to fetch data for station code $stationCode. Please check the station code and try again."
  76.     }
  77. } catch {
  78.     Write-Output "Failed to fetch data for station code $stationCode. Please check the station code and try again. URL was $url"
  79. }
  80.  
  81.  
  82. $refreshData = {
  83.     $url = "https://dixielandsoftware.net/Amtrak/solari/data/" + $stationCode + "_schedule.txt"
  84. $url2 = "_schedule.txt"
  85.  
  86. $urlfinal = $url + "" + $url2
  87.  
  88.  
  89. try {
  90.     $response = Invoke-WebRequest -Uri $url -UseBasicParsing
  91.  
  92.     if ($response.StatusCode -eq 200) {
  93.         Write-Output $response.Content
  94.         $jsonObject = $response.Content | ConvertFrom-Json
  95.         $phrase2 = "</a>"
  96.         Write-Output "Station data has loaded!"
  97.         Clear-Host
  98.         Write-Output "
  99.        ███████ ████████ ████████ ██████   █████  ██   ██     ██████  ███████ ██    ██ ███████ ██       ██████  ██████  ███    ███ ███████ ███    ██ ████████
  100.           ███     ██       ██    ██   ██ ██   ██ ██  ██      ██   ██ ██      ██    ██ ██      ██      ██    ██ ██   ██ ████  ████ ██      ████   ██    ██    
  101.          ███      ██       ██    ██████  ███████ █████       ██   ██ █████   ██    ██ █████   ██      ██    ██ ██████  ██ ████ ██ █████   ██ ██  ██    ██    
  102.         ███       ██       ██    ██   ██ ██   ██ ██  ██      ██   ██ ██       ██  ██  ██      ██      ██    ██ ██      ██  ██  ██ ██      ██  ██ ██    ██    
  103.        ███████    ██       ██    ██   ██ ██   ██ ██   ██     ██████  ███████   ████   ███████ ███████  ██████  ██      ██      ██ ███████ ██   ████    ██    
  104.                                                                                                                                                      
  105.                                                                                                                                                      "
  106.         foreach ($item in $jsonObject) {
  107.             $trainnonew = $item.trainno
  108.             $outputString = $trainnonew -replace [regex]::Escape($aphrase)
  109.             if (startWriting==1) {
  110.                 $fileContent = $fileContent + "$($item.scheduled)       $($item.scheduled24)       $($item.service)           $($outputString)         $($item.origin)         $($item.destination)        $($item.remarks_boarding)"
  111.                 Set-Content -Path $filePath -Value $fileContent
  112.             }
  113.             Write-Output "--=New Section=--"
  114.             Write-Output "Train Number: $($outputString)"
  115.             Write-Output "Scheduled: $($item.scheduled)"
  116.             Write-Output "Scheduled 24h: $($item.scheduled24)"
  117.             Write-Output "Service: $($item.service)"
  118.             Write-Output "Destination: $($item.destination)"
  119.             Write-Output "Origin: $($item.origin)"
  120.             Write-Output "Remarks/Boarding: $($item.remarks_boarding)"
  121.             Write-Output "New Time: $($item.newtime)"
  122.             Write-Output "New Time 24h: $($item.newtime24)"
  123.             Write-Output ""
  124. }        
  125.                
  126.            
  127.     } else {
  128.         Write-Output "Failed to fetch data for station code $stationCode. Please check the station code and try again."
  129.     }
  130. } catch {
  131.     Write-Output "Failed to fetch data for station code $stationCode. Please check the station code and try again. URL was $url"
  132. }
  133.     Get-Date
  134. }
  135. Write-Output "Station Status will update every 30 seconds"
  136. Write-Host "Press F1 to write station data to a .txt file"
  137. Write-Host "Press any key to exit..." -NoNewline
  138. $x = $host.UI.RawUI.ReadKey("NoEcho,IncludeKeyDown")
  139. Add-Type -AssemblyName System.Windows.Forms
  140. $fileContent = "12h Time------24h Time-----------Train------------Number----------Origin---------Destination-------Status-----"
  141. function Write-TextFile {
  142.     Set-Content -Path $filePath -Value $fileContent
  143.     [System.Windows.Forms.MessageBox]::Show("File created at: $filePath", "File Creation")
  144.     Write-Output "The .txt file has been put in Downloads and will resume printing data on the text document until this page closes"
  145.     $startWriting = 1
  146. }
  147. $form = New-Object System.Windows.Forms.Form
  148. $form.Text = "Press F1 to create a text file"
  149. $form.KeyPreview = $true
  150. $form.Add_KeyDown({
  151.     if ($_.KeyCode -eq [System.Windows.Forms.Keys]::F1) {
  152.         Write-TextFile
  153.     }
  154. })
  155. $form.ShowDialog()
  156.  
  157.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement