From slakan, 4 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.   }
  37.   else {
  38.     $class = $html.CreateAttribute("class")
  39.     $class.value = 'pluss'
  40.     $html.table.tr[$i].childnodes[2].attributes.append($class) #| out-null
  41.   }
  42. }
  43. for ($i=1;$i -le $html.table.tr.count-1;$i++) {
  44.     if ([int]$html.table.tr[$i].td[2] -le 0) {
  45.       $class = $html.CreateAttribute("class")
  46.       $class.value = 'minus'
  47.       $html.table.tr[$i].childnodes[2].attributes.append($class) #| out-null
  48.     }
  49.     else {
  50.       $class = $html.CreateAttribute("class")
  51.       $class.value = 'pluss'
  52.       $html.table.tr[$i].childnodes[2].attributes.append($class) #| out-null
  53.     }
  54.   }
  55. $fragments += $html.InnerXml
  56. $fragments += "Here there be stuff, kanskje kamera?<br>Andre kameraer?"
  57. $fragments += "<p class='footer'>$(get-date)</p>"
  58.  
  59. $convertParams = @{
  60.   head = @"
  61. <Title>Mesta Værstatistikk</Title>
  62. <style>
  63. body { background-color:#E5E4E2;
  64.       font-family:Monospace;
  65.       font-size:10pt; }
  66. td, th { border:0px solid black;
  67.         border-collapse:collapse;
  68.         white-space:pre;
  69.         text-align:center; }
  70. th { color:white;
  71.     background-color:black; }
  72. table, tr, td, th { padding: 2px; margin: 0px ;white-space:pre; }
  73. tr:nth-child(odd) {background-color: lightgray}
  74. table { width:500px;margin-left:5px; margin-bottom:20px;}
  75. h2 {
  76. font-family:Tahoma;
  77. color:#6D7B8D;
  78. }
  79. .minus {
  80. color: blue;
  81. }
  82. .pluss {
  83.    color: red;
  84. }
  85. .footer
  86. { color:green;
  87.  margin-left:10px;
  88.  font-family:Tahoma;
  89.  font-size:8pt;
  90.  font-style:italic;
  91. }
  92. </style>
  93. <meta charset="UTF-8">
  94. "@
  95.  body = $fragments
  96. }
  97.  
  98. convertto-html @convertParams | out-file c:\temp\mesta.html
  99.  
  100. Write-host -fore Yellow "## Starting FTP upload.."
  101. $File = "C:\temp\mesta.html";
  102. $ftp = "ftp://morten:[email protected]//home/httpd/sites/zyrex.org/temp/mesta.html";
  103.  
  104. $webclient = New-Object -TypeName System.Net.WebClient;
  105. $uri = New-Object -TypeName System.Uri -ArgumentList $ftp;
  106.  
  107. Write-Host -fore Yellow "## Uploading $File...";
  108. $webclient.UploadFile($uri, $File);
  109.