Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- Clear-Host
- Write-Output "
- ███████ ████████ ████████ ██████ █████ ██ ██ ██████ ███████ ██ ██ ███████ ██ ██████ ██████ ███ ███ ███████ ███ ██ ████████
- ███ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ ████ ████ ██ ████ ██ ██
- ███ ██ ██ ██████ ███████ █████ ██ ██ █████ ██ ██ █████ ██ ██ ██ ██████ ██ ████ ██ █████ ██ ██ ██ ██
- ███ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██
- ███████ ██ ██ ██ ██ ██ ██ ██ ██ ██████ ███████ ████ ███████ ███████ ██████ ██ ██ ██ ███████ ██ ████ ██
- "
- 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."
- $stationCode = Read-Host "Enter the Amtrak Station Code you would like to monitor."
- 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"
- $url = "https://dixielandsoftware.net/Amtrak/solari/data/" + $stationCode + "_schedule.txt"
- $url2 = "_schedule.txt"
- $currentDate = Get-Date
- $year = $currentDate.Year
- $month = $currentDate.Month.toString("D2")
- $day = $currentDate.Day
- $startWriting = 0
- $downloadsPath = "$HOME\Downloads"
- $fileName = "ZTK_DEVELOPMENT_$($year)_$($month)_$($day)_$($stationCode)_STATION.txt"
- $filePath = Join-Path -Path $downloadsPath -ChildPath $fileName
- $urlfinal = $url + "" + $url2
- try {
- $response = Invoke-WebRequest -Uri $url -UseBasicParsing
- if ($response.StatusCode -eq 200) {
- Write-Output $response.Content
- $jsonObject = $response.Content | ConvertFrom-Json
- $currentDate = Get-Date
- $year = $currentDate.Year
- $month = $currentDate.Month
- $day = $currentDate.Day
- Write-Output $year
- Write-Output $month.toString("D2")
- Write-Output $day
- $phrase2 = "</a>"
- Clear-Host
- Write-Output "
- ███████ ████████ ████████ ██████ █████ ██ ██ ██████ ███████ ██ ██ ███████ ██ ██████ ██████ ███ ███ ███████ ███ ██ ████████
- ███ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ ████ ████ ██ ████ ██ ██
- ███ ██ ██ ██████ ███████ █████ ██ ██ █████ ██ ██ █████ ██ ██ ██ ██████ ██ ████ ██ █████ ██ ██ ██ ██
- ███ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██
- ███████ ██ ██ ██ ██ ██ ██ ██ ██ ██████ ███████ ████ ███████ ███████ ██████ ██ ██ ██ ███████ ██ ████ ██
- "
- foreach ($item in $jsonObject) {
- Write-Output "--=New Section=--"
- $trainnonew = $item.trainno
- $outputString = $trainnonew -replace [regex]::Escape($aphrase)
- Write-Output $newTrainNumber
- Write-Output "Train Number: $($outputString)"
- Write-Output "Scheduled: $($item.scheduled)"
- Write-Output "Scheduled 24h: $($item.scheduled24)"
- Write-Output "Service: $($item.service)"
- Write-Output "Destination: $($item.destination)"
- Write-Output "Origin: $($item.origin)"
- Write-Output "Remarks/Boarding: $($item.remarks_boarding)"
- Write-Output "New Time: $($item.newtime)"
- Write-Output "New Time 24h: $($item.newtime24)"
- Write-Output ""
- }
- while ($true) {& $refreshDataStart-Sleep -Seconds 30}
- } else {
- Write-Output "Failed to fetch data for station code $stationCode. Please check the station code and try again."
- }
- } catch {
- Write-Output "Failed to fetch data for station code $stationCode. Please check the station code and try again. URL was $url"
- }
- $refreshData = {
- $url = "https://dixielandsoftware.net/Amtrak/solari/data/" + $stationCode + "_schedule.txt"
- $url2 = "_schedule.txt"
- $urlfinal = $url + "" + $url2
- try {
- $response = Invoke-WebRequest -Uri $url -UseBasicParsing
- if ($response.StatusCode -eq 200) {
- Write-Output $response.Content
- $jsonObject = $response.Content | ConvertFrom-Json
- $phrase2 = "</a>"
- Write-Output "Station data has loaded!"
- Clear-Host
- Write-Output "
- ███████ ████████ ████████ ██████ █████ ██ ██ ██████ ███████ ██ ██ ███████ ██ ██████ ██████ ███ ███ ███████ ███ ██ ████████
- ███ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ ████ ████ ██ ████ ██ ██
- ███ ██ ██ ██████ ███████ █████ ██ ██ █████ ██ ██ █████ ██ ██ ██ ██████ ██ ████ ██ █████ ██ ██ ██ ██
- ███ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██
- ███████ ██ ██ ██ ██ ██ ██ ██ ██ ██████ ███████ ████ ███████ ███████ ██████ ██ ██ ██ ███████ ██ ████ ██
- "
- foreach ($item in $jsonObject) {
- $trainnonew = $item.trainno
- $outputString = $trainnonew -replace [regex]::Escape($aphrase)
- if (startWriting==1) {
- $fileContent = $fileContent + "$($item.scheduled) $($item.scheduled24) $($item.service) $($outputString) $($item.origin) $($item.destination) $($item.remarks_boarding)"
- Set-Content -Path $filePath -Value $fileContent
- }
- Write-Output "--=New Section=--"
- Write-Output "Train Number: $($outputString)"
- Write-Output "Scheduled: $($item.scheduled)"
- Write-Output "Scheduled 24h: $($item.scheduled24)"
- Write-Output "Service: $($item.service)"
- Write-Output "Destination: $($item.destination)"
- Write-Output "Origin: $($item.origin)"
- Write-Output "Remarks/Boarding: $($item.remarks_boarding)"
- Write-Output "New Time: $($item.newtime)"
- Write-Output "New Time 24h: $($item.newtime24)"
- Write-Output ""
- }
- } else {
- Write-Output "Failed to fetch data for station code $stationCode. Please check the station code and try again."
- }
- } catch {
- Write-Output "Failed to fetch data for station code $stationCode. Please check the station code and try again. URL was $url"
- }
- Get-Date
- }
- Write-Output "Station Status will update every 30 seconds"
- Write-Host "Press F1 to write station data to a .txt file"
- Write-Host "Press any key to exit..." -NoNewline
- $x = $host.UI.RawUI.ReadKey("NoEcho,IncludeKeyDown")
- Add-Type -AssemblyName System.Windows.Forms
- $fileContent = "12h Time------24h Time-----------Train------------Number----------Origin---------Destination-------Status-----"
- function Write-TextFile {
- Set-Content -Path $filePath -Value $fileContent
- [System.Windows.Forms.MessageBox]::Show("File created at: $filePath", "File Creation")
- Write-Output "The .txt file has been put in Downloads and will resume printing data on the text document until this page closes"
- $startWriting = 1
- }
- $form = New-Object System.Windows.Forms.Form
- $form.Text = "Press F1 to create a text file"
- $form.KeyPreview = $true
- $form.Add_KeyDown({
- if ($_.KeyCode -eq [System.Windows.Forms.Keys]::F1) {
- Write-TextFile
- }
- })
- $form.ShowDialog()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement