[xml]$Weather = Get-Content "C:\Users\Morten\Downloads\GetMeasuredWeatherData.xml"
$EndResult = @()
$IDs = "206","207"
Foreach ($place in $IDs) {
$Location = $Weather.d2LogicalModel.payloadPublication.siteMeasurements
| Where-Object { $_.measurementsitereference.id
-eq $place }
$LocationAirTemp = ($Location.measuredValue
| Where-Object {$_.index
-eq "101"}).innertext
$LocationRoadTemp = ($Location.measuredValue
| Where-Object {$_.index
-eq "801"}).innertext
$LocationPrecipitation = ($Location.measuredValue
| Where-Object {$_.index
-eq "2501"}).innertext
+ " mm/h"
$Place = $place -replace "206","Lygna" -replace "207","Bekkehallum"
$Resultname = [PSCustomObject][ordered]@{
Lokasjon = $place
Lufttemperatur = $LocationAirTemp
Veibanetemperatur = $LocationRoadTemp
Nedbørintensitet = $LocationPrecipitation
}
$EndResult += $ResultName
}
$EndResult
$fragments = @()
$fragments+= "<H1>Værstatistikk</H1>"
[xml]$html = $EndResult | convertto-html -Fragment
for ($i=1;$i -le $html.table.tr.count-1;$i++) {
if ([int]$html.table.tr[$i].td[1] -le 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[2].attributes.append($class) #| out-null
$html.table.tr[$i].childnodes[1].'#text' = ($html.table.tr[$i].childnodes[1].'#text') + " °C"
}
}
for ($i=1;$i -le $html.table.tr.count-1;$i++) {
if ([int]$html.table.tr[$i].td[2] -le 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"
}
}
$fragments += $html.InnerXml
$fragments += "Here there be stuff, kanskje kamera?<br>Andre kameraer?"
$fragments += "<p class='footer'>$(get-date)</p>"
$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">
"@
body = $fragments
}
convertto-html @convertParams | out-file c:\temp\mesta.html
Write-host -fore Yellow "## Starting FTP upload.."
$File = "C:\temp\mesta.html";
$webclient = New-Object -TypeName System.Net.WebClient;
$uri = New-Object -TypeName System.Uri -ArgumentList $ftp;
Write-Host -fore Yellow "## Uploading $File...";
$webclient.UploadFile($uri, $File);