inital commit
This commit is contained in:
196
datex.ps1
Normal file
196
datex.ps1
Normal file
@@ -0,0 +1,196 @@
|
|||||||
|
|
||||||
|
#[xml]$Weather = Get-Content "C:\Users\Morten\Downloads\GetMeasuredWeatherData.xml"
|
||||||
|
#[xml]$Weather = Invoke-WebRequest -Credential (Get-Credential) -Uri https://www.vegvesen.no/ws/no/vegvesen/veg/trafikkpublikasjon/vaer/2/GetMeasuredWeatherData
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
$EndResult = @()
|
||||||
|
#$IDs = "206","207","228","1125","277","95"
|
||||||
|
$IDs = "1740","206","174"
|
||||||
|
|
||||||
|
Foreach ($place in $IDs) {
|
||||||
|
$Location = $Weather.d2LogicalModel.payloadPublication.siteMeasurements | Where-Object { $_.measurementsitereference.id -eq $place }
|
||||||
|
|
||||||
|
$LocationAirTemp = ($Location.measuredValue | Where-Object {$_.index -eq "101"}).innertext
|
||||||
|
$LocationHumidity = ($Location.measuredValue | Where-Object {$_.index -eq "201"}).innertext + " %"
|
||||||
|
$LocationDewPoint = ($Location.measuredValue | Where-Object {$_.index -eq "301"}).innertext
|
||||||
|
$LocationRoadTemp = ($Location.measuredValue | Where-Object {$_.index -eq "801"}).innertext
|
||||||
|
[float]$LocationWindSpeed = ($Location.measuredValue | Where-Object {$_.index -eq "901"}).innertext
|
||||||
|
#$LocationWindDir = ($Location.measuredValue | Where-Object {$_.index -eq "901"}).innertext
|
||||||
|
$LocationVisibility = ($Location.measuredValue | Where-Object {$_.index -eq "1401"}).innertext
|
||||||
|
$LocationPrecipitation = ($Location.measuredValue | Where-Object {$_.index -eq "2501"}).innertext + " mm/h"
|
||||||
|
$LocationSnowDepth = ($Location.measuredValue | Where-Object {$_.index -eq "3301"}).innertext
|
||||||
|
|
||||||
|
if (!$LocationSnowDepth) {$LocationSnowDepth = "-"}
|
||||||
|
if (!$LocationWindSpeed) {[string]$LocationWindSpeed = "-"} else { $LocationWindSpeed = $LocationWindSpeed*5/18 } # Omregning fra km/t til m/s
|
||||||
|
if (!$LocationVisibility) {$LocationVisibility = "-"}
|
||||||
|
$Place = $Place.Replace("206","Lygna").Replace("207","Bekkehallum").Replace("1740","Vingromsåsen").Replace("174","Eina")
|
||||||
|
$Resultname = [PSCustomObject][ordered]@{
|
||||||
|
Lokasjon = $place
|
||||||
|
Lufttemperatur = $LocationAirTemp
|
||||||
|
Duggpunkt = $LocationDewPoint
|
||||||
|
Veibanetemperatur = $LocationRoadTemp
|
||||||
|
Nedbørintensitet = $LocationPrecipitation
|
||||||
|
Vindhastighet = $LocationWindSpeed
|
||||||
|
Snødybde = $LocationSnowDepth
|
||||||
|
Luftfuktighet = $LocationHumidity
|
||||||
|
Siktrekkevidde = $LocationVisibility
|
||||||
|
}
|
||||||
|
$EndResult += $ResultName
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
$EndResult|Format-Table
|
||||||
|
$fragments = @()
|
||||||
|
|
||||||
|
$fragments+= "<H1>Værstatistikk</H1>"
|
||||||
|
[xml]$html = $EndResult | convertto-html -Fragment
|
||||||
|
|
||||||
|
# Lufttemp
|
||||||
|
for ($i=1;$i -le $html.table.tr.count-1;$i++) {
|
||||||
|
if ([float]$html.table.tr[$i].td[1] -lt 0) {
|
||||||
|
$class = $html.CreateAttribute("class")
|
||||||
|
$class.value = 'minus'
|
||||||
|
$html.table.tr[$i].childnodes[1].attributes.append($class) | out-null
|
||||||
|
$html.table.tr[$i].childnodes[1].'#text' = ($html.table.tr[$i].childnodes[1].'#text') + " °C"
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
$class = $html.CreateAttribute("class")
|
||||||
|
$class.value = 'pluss'
|
||||||
|
$html.table.tr[$i].childnodes[1].attributes.append($class) | out-null
|
||||||
|
$html.table.tr[$i].childnodes[1].'#text' = ($html.table.tr[$i].childnodes[1].'#text') + " °C"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
# Duggpunkt
|
||||||
|
for ($i=1;$i -le $html.table.tr.count-1;$i++) {
|
||||||
|
if ([float]$html.table.tr[$i].td[2] -lt 0) {
|
||||||
|
$class = $html.CreateAttribute("class")
|
||||||
|
$class.value = 'minus'
|
||||||
|
$html.table.tr[$i].childnodes[2].attributes.append($class) | out-null
|
||||||
|
$html.table.tr[$i].childnodes[2].'#text' = ($html.table.tr[$i].childnodes[2].'#text') + " °C"
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
$class = $html.CreateAttribute("class")
|
||||||
|
$class.value = 'pluss'
|
||||||
|
$html.table.tr[$i].childnodes[2].attributes.append($class) | out-null
|
||||||
|
$html.table.tr[$i].childnodes[2].'#text' = ($html.table.tr[$i].childnodes[2].'#text') + " °C"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
# Veibanetemp
|
||||||
|
for ($i=1;$i -le $html.table.tr.count-1;$i++) {
|
||||||
|
if ([float]$html.table.tr[$i].td[3] -lt 0) {
|
||||||
|
$class = $html.CreateAttribute("class")
|
||||||
|
$class.value = 'minus'
|
||||||
|
$html.table.tr[$i].childnodes[3].attributes.append($class) | out-null
|
||||||
|
$html.table.tr[$i].childnodes[3].'#text' = ($html.table.tr[$i].childnodes[3].'#text') + " °C"
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
$class = $html.CreateAttribute("class")
|
||||||
|
$class.value = 'pluss'
|
||||||
|
$html.table.tr[$i].childnodes[3].attributes.append($class) | out-null
|
||||||
|
$html.table.tr[$i].childnodes[3].'#text' = ($html.table.tr[$i].childnodes[3].'#text') + " °C"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
# Vindhastighet
|
||||||
|
for ($i=1;$i -le $html.table.tr.count-1;$i++) {
|
||||||
|
if ($html.table.tr[$i].td[5] -ne "-") {
|
||||||
|
$html.table.tr[$i].childnodes[5].'#text' = ($html.table.tr[$i].childnodes[5].'#text') + " m/s"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
# Snødybde
|
||||||
|
for ($i=1;$i -le $html.table.tr.count-1;$i++) {
|
||||||
|
if ($html.table.tr[$i].td[6] -ne "-") {
|
||||||
|
$html.table.tr[$i].childnodes[6].'#text' = ($html.table.tr[$i].childnodes[6].'#text') + " meter"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
# Siktrekkevidde
|
||||||
|
for ($i=1;$i -le $html.table.tr.count-1;$i++) {
|
||||||
|
if ($html.table.tr[$i].td[8] -ne "-") {
|
||||||
|
$html.table.tr[$i].childnodes[8].'#text' = ($html.table.tr[$i].childnodes[8].'#text') + " meter"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
#$fragments += $html.InnerXml
|
||||||
|
$html.InnerXml |Out-File C:\temp\mestatable.inc
|
||||||
|
$fragments += @'
|
||||||
|
<div id="Container">
|
||||||
|
<? include 'mestatable.inc'; ?>
|
||||||
|
</div>
|
||||||
|
<div id="refresh">
|
||||||
|
<div id="time">
|
||||||
|
<p class='footer'>Siste oppdatering: <?php echo date('H:i:s');?></p>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<script src="https://cdn.jsdelivr.net/npm/hls.js@canary"></script>
|
||||||
|
<video id="video" controls autoplay class="videoCentered"></video>
|
||||||
|
<script>
|
||||||
|
var video = document.getElementById('video');
|
||||||
|
if(Hls.isSupported()) {
|
||||||
|
var hls = new Hls();
|
||||||
|
hls.loadSource('https://kamera.vegvesen.no/public/0529008_1/manifest.m3u8');
|
||||||
|
hls.attachMedia(video);
|
||||||
|
hls.on(Hls.Events.MANIFEST_PARSED,function() {
|
||||||
|
video.play();
|
||||||
|
});
|
||||||
|
}
|
||||||
|
</script>
|
||||||
|
'@
|
||||||
|
|
||||||
|
|
||||||
|
$convertParams = @{
|
||||||
|
head = @"
|
||||||
|
<Title>Mesta Værstatistikk</Title>
|
||||||
|
<style>
|
||||||
|
body { background-color:#E5E4E2;
|
||||||
|
font-family:Monospace;
|
||||||
|
font-size:10pt; }
|
||||||
|
td, th { border:0px solid black;
|
||||||
|
border-collapse:collapse;
|
||||||
|
white-space:pre;
|
||||||
|
text-align:center; }
|
||||||
|
th { color:white;
|
||||||
|
background-color:black; }
|
||||||
|
table, tr, td, th { padding: 2px; margin: 0px ;white-space:pre; }
|
||||||
|
tr:nth-child(odd) {background-color: lightgray}
|
||||||
|
table { width:500px;margin-left:5px; margin-bottom:20px;}
|
||||||
|
h2 {
|
||||||
|
font-family:Tahoma;
|
||||||
|
color:#6D7B8D;
|
||||||
|
}
|
||||||
|
.minus {
|
||||||
|
color: blue;
|
||||||
|
}
|
||||||
|
.pluss {
|
||||||
|
color: red;
|
||||||
|
}
|
||||||
|
.footer
|
||||||
|
{ color:green;
|
||||||
|
margin-left:10px;
|
||||||
|
font-family:Tahoma;
|
||||||
|
font-size:8pt;
|
||||||
|
font-style:italic;
|
||||||
|
}
|
||||||
|
</style>
|
||||||
|
<meta charset="UTF-8">
|
||||||
|
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.3/jquery.min.js"></script>
|
||||||
|
"@
|
||||||
|
body = $fragments
|
||||||
|
}
|
||||||
|
|
||||||
|
convertto-html @convertParams | out-file c:\temp\mesta.php
|
||||||
|
|
||||||
|
Write-host -fore Yellow "## Starting FTP upload.."
|
||||||
|
$File = "C:\temp\mesta.php";
|
||||||
|
$ftp = "ftp://xxxxxxx:yyyyyyy@web.home.zyrex.org//home/httpd/sites/zyrex.org/temp/mesta.php";
|
||||||
|
$File2 = "C:\temp\mestatable.inc";
|
||||||
|
$ftp2 = "ftp://xxxxxxxx:yyyyyyy@web.home.zyrex.org//home/httpd/sites/zyrex.org/temp/mestatable.inc";
|
||||||
|
|
||||||
|
$webclient = New-Object -TypeName System.Net.WebClient;
|
||||||
|
$uri = New-Object -TypeName System.Uri -ArgumentList $ftp;
|
||||||
|
$uri2 = New-Object -TypeName System.Uri -ArgumentList $ftp2;
|
||||||
|
|
||||||
|
|
||||||
|
Write-Host -fore Yellow "## Uploading $File...";
|
||||||
|
$webclient.UploadFile($uri, $File);
|
||||||
|
Write-Host -fore Yellow "## Uploading $File2...";
|
||||||
|
$webclient.UploadFile($uri2, $File2);
|
||||||
Reference in New Issue
Block a user