Add Station Reading to Powershell prompt
6 years 1 month ago - 5 years 5 months ago #4095
by Radslug
Add Station Reading to Powershell prompt was created by Radslug
My station Radslug is fairly reliable but it uitilizes a modified Linksys NLU2 from around 2006 as a tiny single purpose Linux computer to read the count from a BroHogan Geiger Kit and send it to Radmon.org. Someday if it dies I'll swap out the Linksys for a R-Pi but Linksys quality was pretty good back then, so it may be a while.
Anyway, I don't check in on the station every day. So I miss when it gets hung up and needs a reboot. But I do use Powershell at least once a day at work. I realized I could grab the applicable lines from my station page on radmon.org & display them in my PS prompt. With a bit of formatting, the last update and current time line up and any discrepancy is visually obvious.
So, to save someone else wasting time formatting, here it is. Add to your
%HOMEPATH%\Documents\WindowsPowerShell\profile.ps1
- be sure to replace user=Radslug with your station handle.
If you use CMD more than Powershell, throw the line
Powershell exit &
into a .CMD and run from a DOS prompt.
It'll run & leave the powershell radmon text at the top of your window just above your first CMD prompt.
[10/12/18 edit]
Also, in a perfectly Rube Goldberg way you can have that Powershell-exit CMD run every time you open a CMD prompt (thus displaying the station info at the top of a regular DOS shell) by creating the following key in the registry:
key: HKCU\SOFTWARE\Microsoft\Command Processor
value: AutoRun
type: REG_EXPAND_SZ
data: "path\scriptname.cmd"
(where path\scriptname.cmd match your "powershell exit &" CMD script)
[05/24/19 edit] added space padding to maintain vertical allignment
Lines to add to %HOMEPATH%\Documents\WindowsPowerShell\profile.ps1
Anyway, I don't check in on the station every day. So I miss when it gets hung up and needs a reboot. But I do use Powershell at least once a day at work. I realized I could grab the applicable lines from my station page on radmon.org & display them in my PS prompt. With a bit of formatting, the last update and current time line up and any discrepancy is visually obvious.
So, to save someone else wasting time formatting, here it is. Add to your
%HOMEPATH%\Documents\WindowsPowerShell\profile.ps1
- be sure to replace user=Radslug with your station handle.
If you use CMD more than Powershell, throw the line
Powershell exit &
into a .CMD and run from a DOS prompt.
It'll run & leave the powershell radmon text at the top of your window just above your first CMD prompt.
[10/12/18 edit]
Also, in a perfectly Rube Goldberg way you can have that Powershell-exit CMD run every time you open a CMD prompt (thus displaying the station info at the top of a regular DOS shell) by creating the following key in the registry:
key: HKCU\SOFTWARE\Microsoft\Command Processor
value: AutoRun
type: REG_EXPAND_SZ
data: "path\scriptname.cmd"
(where path\scriptname.cmd match your "powershell exit &" CMD script)
[05/24/19 edit] added space padding to maintain vertical allignment
Lines to add to %HOMEPATH%\Documents\WindowsPowerShell\profile.ps1
#Get Radmon current reading
$Station = (Invoke-WebRequest -Uri http://www.radmon.org/radmon.php?function=showuserpage"&"user=Radslug).ParsedHtml.getElementsByTagName('H1')[0].InnerHTML.Trim()
$Reading = (Invoke-WebRequest -Uri http://www.radmon.org/radmon.php?function=showuserpage"&"user=Radslug).ParsedHtml.getElementsByTagName('H2')[0].InnerHTML.Trim()
$PstTime = (get-date).ToString("yyyy-MM-dd HH:mm:ss")
$UtcTime = (get-date).ToUniversalTime().ToString("yyyy-MM-dd HH:mm:ss")
#Pad with spaces if needed to keep time & date vertical allignment
$Reading2 = $Reading.PadLeft(29)
#Display before prompt
Clear-Host
Write-Host "> Current datetime is " -ForegroundColor Yellow -NoNewline
Write-Host "$PstTime" -ForegroundColor Cyan -NoNewline
Write-Host " PST" -ForegroundColor Cyan -NoNewline
Write-Host " a.k.a: " -ForegroundColor Yellow -NoNewline
Write-Host "$UtcTime" -ForegroundColor Cyan -NoNewline
Write-Host " UTC " -ForegroundColor Cyan
Write-Host "> $Station" -ForegroundColor Yellow -NoNewline
Write-Host " last update: " -ForegroundColor Yellow -NoNewline
Write-Host "$Reading2" -ForegroundColor Cyan -NoNewline
Write-Host " UTC " -ForegroundColor Cyan
Last edit: 5 years 5 months ago by Radslug. Reason: Updated script to maintain vertical allignment on output
The following user(s) said Thank You: mw0uzo
Please Log in or Create an account to join the conversation.
6 years 1 month ago #4097
by mw0uzo
Replied by mw0uzo on topic Add Station Reading to Powershell prompt
Ah this is great! How good would it be do see your radmon.org station count on your desktop background? For linux users translate into a conky script?
Please Log in or Create an account to join the conversation.
6 years 1 month ago - 6 years 1 month ago #4100
by Radslug
Replied by Radslug on topic Add Station Reading to Powershell prompt
Probably a case where hxextract or python would be most useful but b/c of the page structure, I think it could even be done like this?
Quick-n-dirty but low resource, since it's static text & simple HTML. Still needs the refresh interval, etc:
Btw, the closing tag for H1 is coming across to my browser as h2 not h1.
ie,
<h1 class="serif">Radiation monitor for Radslug</h2>
Updated 2018-10-13:
Quick-n-dirty but low resource, since it's static text & simple HTML. Still needs the refresh interval, etc:
curl -s "http://www.radmon.org/radmon.php?function=showuserpage&user=Radslug" | grep "<h1 class=\"serif\">" |sed -n -e 's/.*<h1 class=\"serif\">\(.*\)<\/h2>.*/\1/p'
curl -s "http://www.radmon.org/radmon.php?function=showuserpage&user=Radslug" | grep "<h2 class=\"serif\">" |sed -n -e 's/.*<h2 class=\"serif\">\(.*\)<\/h2>.*/\1/p'
Btw, the closing tag for H1 is coming across to my browser as h2 not h1.
ie,
<h1 class="serif">Radiation monitor for Radslug</h2>
Updated 2018-10-13:
curl -s "http://www.radmon.org/radmon.php?function=showuserpage&user=Radslug" | grep "<h1 class=\"serif\">" |sed -n -e 's/.*<h1 class=\"serif\">\(.*\)<\/h1>.*/\1/p'
curl -s "http://www.radmon.org/radmon.php?function=showuserpage&user=Radslug" | grep "<h2 class=\"serif\">" |sed -n -e 's/.*<h2 class=\"serif\">\(.*\)<\/h2>.*/\1/p'
Last edit: 6 years 1 month ago by Radslug.
Please Log in or Create an account to join the conversation.
6 years 1 month ago #4104
by mw0uzo
Replied by mw0uzo on topic Add Station Reading to Powershell prompt
Ok I've corrected the header class tags. h2 changed to h1 and i also found a missing / on /h3 closing tag
The following user(s) said Thank You: Radslug
Please Log in or Create an account to join the conversation.
Moderators: Gamma-Man
Time to create page: 0.148 seconds