From slakan, 2 Years ago, written in PowerShell.
Embed
  1.  
  2. [xml]$Weather = Get-Content "C:\Users\Morten\Downloads\GetMeasuredWeatherData.xml"
  3.  
  4. $EndResult = @()
  5. $IDs = "206","207"
  6.  
  7.  
  8. Foreach ($place in $IDs) {
  9.     $Location = $Weather.d2LogicalModel.payloadPublication.siteMeasurements | Where-Object { $_.measurementsitereference.id -eq $place }
  10.  
  11.     $LocationAirTemp = ($Location.measuredValue | Where-Object {$_.index -eq "101"}).innertext
  12.     $LocationRoadTemp = ($Location.measuredValue | Where-Object {$_.index -eq "801"}).innertext
  13.     $LocationPrecipitation = ($Location.measuredValue | Where-Object {$_.index -eq "2501"}).innertext + " mm/h"
  14.  
  15.     $Place = $place -replace "206","Lygna" -replace "207","Bekkehallum"
  16.     $Resultname = [PSCustomObject][ordered]@{
  17.         Lokasjon = $place
  18.         Lufttemperatur = $LocationAirTemp
  19.         Veibanetemperatur = $LocationRoadTemp
  20.         Nedbørintensitet = $LocationPrecipitation
  21.         }
  22.         $EndResult += $ResultName
  23.     }
  24.  
  25.  
  26. $EndResult
  27. $fragments = @()
  28. $fragments+= "<H1>Værstatistikk</H1>"
  29. [xml]$html = $EndResult | convertto-html -Fragment
  30.  
  31. for ($i=1;$i -le $html.table.tr.count-1;$i++) {
  32.   if ([int]$html.table.tr[$i].td[1] -le 0) {
  33.     $class = $html.CreateAttribute("class")
  34.     $class.value = 'minus'
  35.     $html.table.tr[$i].childnodes[1].attributes.append($class) #| out-null
  36.     $html.table.tr[$i].childnodes[1].'#text' = ($html.table.tr[$i].childnodes[1].'#text') + " °C"
  37.   }
  38.   else {
  39.     $class = $html.CreateAttribute("class")
  40.     $class.value = 'pluss'
  41.     $html.table.tr[$i].childnodes[2].attributes.append($class) #| out-null
  42.     $html.table.tr[$i].childnodes[1].'#text' = ($html.table.tr[$i].childnodes[1].'#text') + " °C"
  43.   }
  44. }
  45. for ($i=1;$i -le $html.table.tr.count-1;$i++) {
  46.     if ([int]$html.table.tr[$i].td[2] -le 0) {
  47.       $class = $html.CreateAttribute("class")
  48.       $class.value = 'minus'
  49.       $html.table.tr[$i].childnodes[2].attributes.append($class) #| out-null
  50.       $html.table.tr[$i].childnodes[2].'#text' = ($html.table.tr[$i].childnodes[2].'#text') + " °C"
  51.     }
  52.     else {
  53.       $class = $html.CreateAttribute("class")
  54.       $class.value = 'pluss'
  55.       $html.table.tr[$i].childnodes[2].attributes.append($class) #| out-null
  56.       $html.table.tr[$i].childnodes[2].'#text' = ($html.table.tr[$i].childnodes[2].'#text') + " °C"
  57.     }
  58.   }
  59. $fragments += $html.InnerXml
  60. $fragments += "Here there be stuff, kanskje kamera?<br>Andre kameraer?"
  61. $fragments += "<p class='footer'>$(get-date)</p>"
  62.  
  63. $convertParams = @{
  64.   head = @"
  65. <Title>Mesta Værstatistikk</Title>
  66. <style>
  67. body { background-color:#E5E4E2;
  68.       font-family:Monospace;
  69.       font-size:10pt; }
  70. td, th { border:0px solid black;
  71.         border-collapse:collapse;
  72.         white-space:pre;
  73.         text-align:center; }
  74. th { color:white;
  75.     background-color:black; }
  76. table, tr, td, th { padding: 2px; margin: 0px ;white-space:pre; }
  77. tr:nth-child(odd) {background-color: lightgray}
  78. table { width:500px;margin-left:5px; margin-bottom:20px;}
  79. h2 {
  80. font-family:Tahoma;
  81. color:#6D7B8D;
  82. }
  83. .minus {
  84. color: blue;
  85. }
  86. .pluss {
  87.    color: red;
  88. }
  89. .footer
  90. { color:green;
  91.  margin-left:10px;
  92.  font-family:Tahoma;
  93.  font-size:8pt;
  94.  font-style:italic;
  95. }
  96. </style>
  97. <meta charset="UTF-8">
  98. "@
  99.  body = $fragments
  100. }
  101.  
  102. convertto-html @convertParams | out-file c:\temp\mesta.html
  103.  
  104. Write-host -fore Yellow "## Starting FTP upload.."
  105. $File = "C:\temp\mesta.html";
  106. $ftp = "ftp://morten:redacted@web.home.zyrex.org//home/httpd/sites/zyrex.org/temp/mesta.html";
  107.  
  108. $webclient = New-Object -TypeName System.Net.WebClient;
  109. $uri = New-Object -TypeName System.Uri -ArgumentList $ftp;
  110.  
  111. Write-Host -fore Yellow "## Uploading $File...";
  112. $webclient.UploadFile($uri, $File);
  113.