diff --git a/datex.ps1 b/datex.ps1
index 9fef4e3..853ab05 100644
--- a/datex.ps1
+++ b/datex.ps1
@@ -1,30 +1,49 @@
+# Used everytime
+$User = "username"
+#$password = Get-Content /home/httpd/sites/datex/cred.txt | ConvertTo-SecureString
+#$credential = New-Object System.Management.Automation.PsCredential($User,$password)
-#[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
+# Magic
+#[xml]$Weather = Invoke-WebRequest -Credential $credential https://www.vegvesen.no/ws/no/vegvesen/veg/trafikkpublikasjon/vaer/2/GetMeasurementWeatherSiteTable
+
+
+$securepassword = ConvertTo-SecureString "password" -AsPlainText -Force
+$credentials = New-Object System.Management.Automation.PSCredential($User, $securepassword)
+[xml]$Weather = Invoke-WebRequest -Uri "https://www.vegvesen.no/ws/no/vegvesen/veg/trafikkpublikasjon/vaer/2/GetMeasuredWeatherData" -Credential $credentials
+
+#MET
+Invoke-webrequest https://api.met.no/weatherapi/textforecast/2.0/?forecast=landoverview -Outfile "response.xml"
+[xml]$met = New-Object -TypeName xml
+$met.load("response.xml")
+$ostlandet_24 = $met.textforecast.time[0].forecasttype.location[0].innertext | Out-File /home/httpd/sites/datex/met24.inc
+
+$ostlandet_48 = $met.textforecast.time[1].forecasttype.location[0].innertext | Out-File /home/httpd/sites/datex/met48.inc
+# MET SLUTT
+
$EndResult = @()
-#$IDs = "206","207","228","1125","277","95"
-$IDs = "1740","206","174"
-
+$IDs = "206","217","342","1740","73","175","202","142","341","277","210","249","163"
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
+# $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 = "-"}
+ # $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")
+ $Place = $Place.Replace("206","Lygna").Replace("217","Bekkehallum").Replace("342","Vardalsåsen").Replace("1740","Vingromåsen").Replace("73","Eggemoen").Replace("175","Stryken").Replace("202","Brovoll").Replace("142","Gjelleråsen").Replace("341","Tonsåsen").Replace("277","Andelva").Replace("210","Minnesund").Replace("249","Espa").Replace("163","Vikselv")
+
+
$Resultname = [PSCustomObject][ordered]@{
Lokasjon = $place
Lufttemperatur = $LocationAirTemp
@@ -32,33 +51,48 @@ Foreach ($place in $IDs) {
Veibanetemperatur = $LocationRoadTemp
Nedbørintensitet = $LocationPrecipitation
Vindhastighet = $LocationWindSpeed
- Snødybde = $LocationSnowDepth
+ # Snødybde = $LocationSnowDepth
Luftfuktighet = $LocationHumidity
- Siktrekkevidde = $LocationVisibility
+ # Siktrekkevidde = $LocationVisibility
}
$EndResult += $ResultName
}
-
-
+
+
$EndResult|Format-Table
$fragments = @()
-
-$fragments+= "
Værstatistikk
"
+$fragments += @'
+
+
+
+'@
+$fragments+= '
Værstatistikk
'
[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"
+ 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].innertext = ($html.table.tr[$i].childnodes[1].innertext) + " °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"
+ $html.table.tr[$i].childnodes[1].innertext = ($html.table.tr[$i].childnodes[1].innertext) + " °C"
}
}
# Duggpunkt
@@ -67,13 +101,13 @@ for ($i=1;$i -le $html.table.tr.count-1;$i++) {
$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"
+ $html.table.tr[$i].childnodes[2].InnerText = ($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"
+ $html.table.tr[$i].childnodes[2].InnerText = ($html.table.tr[$i].childnodes[2].'#text') + " °C"
}
}
# Veibanetemp
@@ -82,93 +116,149 @@ for ($i=1;$i -le $html.table.tr.count-1;$i++) {
$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"
+ $html.table.tr[$i].childnodes[3].InnerText = ($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"
+ $html.table.tr[$i].childnodes[3].InnerText = ($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"
+ $html.table.tr[$i].childnodes[5].InnerText = ($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"
- }
-}
+#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"
+ #}
+#s}
# 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"
- }
-}
+#for ($i=1;$i -le $html.table.tr.count-1;$i++) {
+# if ($html.table.tr[$i].td[7] -ne "-") {
+# $html.table.tr[$i].childnodes[7].'#text' = ($html.table.tr[$i].childnodes[7].'#text') + " meter"
+# }
+#}
+
+
+#:Send-MailMessage -From 'User01 ' -To 'User02 ' -Subject 'Test mail' -SmtpServer 'smtp.domeneshop.no'
+
#$fragments += $html.InnerXml
-$html.InnerXml |Out-File C:\temp\mestatable.inc
+$html.InnerXml | Out-File /home/httpd/sites/datex/mestatable.inc
$fragments += @'
include 'mestatable.inc'; ?>
+'@
+$fragments +="Værvarsel fra met.no
+Østlandet 24 timer:$ostlandet_24
+Østlandet 48 timer:$ostlandet_48
"
+$fragments += @'
+
+
-
-
+
+
+

+

+

+

+

+

+

+

+

+

+

+

+
+
+
+
+
+
+
+
+
+
+
+
+
'@
-
-
-$convertParams = @{
+
+
+$convertParams = @{
head = @"
- Mesta Værstatistikk
+Mesta Værstatistikk - datex.glaeserud.no
@@ -176,21 +266,6 @@ h2 {
"@
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);
+
+convertto-html @convertParams | out-file /home/httpd/sites/datex/index7.php
+
\ No newline at end of file