forked from nickrod518/PowerShell-Scripts
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathGet-Weather.ps1
More file actions
110 lines (103 loc) · 3.94 KB
/
Copy pathGet-Weather.ps1
File metadata and controls
110 lines (103 loc) · 3.94 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
$UtilityName = 'Archaic Weather Gathering Utility - Nick Rodriguez'
# Default values
$City = 'Asheville'
$Country = 'United States'
$ZipCode = '28803'
$Days = '6'
Function Get-Weather {
param([string]$City, [string]$Country)
$webservice = New-WebServiceProxy -Uri 'http://www.webservicex.net/globalweather.asmx?WSDL'
$CurrentWeather = ([xml]$webservice.GetWeather($City, $Country)).CurrentWeather
return $CurrentWeather
}
Function Get-Forecast {
Param([string]$ZipCode, [int]$Days)
$URI = 'http://www.weather.gov/forecasts/xml/DWMLgen/wsdl/ndfdXML.wsdl'
$Proxy = New-WebServiceProxy -uri $URI -namespace WebServiceProxy
[xml]$latlon=$proxy.LatLonListZipCode($ZipCode)
$Forecast = foreach($l in $latlon) {
$a = $l.dwml.latlonlist -split ","
$lat = $a[0]
$lon = $a[1]
$sDate = get-date -UFormat %Y-%m-%d
$format = "Item24hourly"
[xml]$weather = $Proxy.NDFDgenByDay($lat,$lon,$sDate,$Days,'e',$format)
For($i = 0 ; $i -le $Days -1 ; $i ++) {
New-Object psObject -Property @{
"Date" = ((Get-Date).addDays($i)).tostring("MM/dd/yyyy") ;
"maxTemp" = $weather.dwml.data.parameters.temperature[0].value[$i] ;
"minTemp" = $weather.dwml.data.parameters.temperature[1].value[$i] ;
"Summary" = $weather.dwml.data.parameters.weather."weather-conditions"[$i]."Weather-summary"
}
}
}
return $Forecast | Format-Table -Property date, maxTemp, minTemp, Summary -AutoSize
}
Function LoadMenuSystem {
[INT]$MenuLevel1=0
[INT]$xMenuLevel2=0
[BOOLEAN]$xValidSelection=$false
while ( $MenuLevel1 -lt 1 -or $MenuLevel1 -gt 3 ) {
CLS
#… Present the Menu Options
Write-Host "`n`t$UtilityName`n" -ForegroundColor Magenta
Write-Host "`t`tPlease select an option`n" -Fore Cyan
Write-Host "`t`t`t1. Current Weather" -Fore Cyan
Write-Host "`t`t`t2. Forecast" -Fore Cyan
Write-Host "`t`t`t3. Exit`n" -Fore Cyan
#… Retrieve the response from the user
[int]$MenuLevel1 = Read-Host "`t`tEnter Menu Option Number"
if( $MenuLevel1 -lt 1 -or $MenuLevel1 -gt 3 ) {
Write-Host "`tPlease select one of the options available.`n" -Fore Red; Start-Sleep -Seconds 1
}
}
Switch ($MenuLevel1){ #… User has selected a valid entry.. load next menu
1 {
while ( $xMenuLevel2 -lt 1 -or $xMenuLevel2 -gt 4 ) {
CLS
# Present the Menu Options
Write-Host "`n`t$UtilityName`n" -Fore Magenta
Write-Host "`t`tCurrent weather for $City, $Country`n" -Fore Cyan
Write-Host "`t`t`t1. Refresh" -Fore Cyan
Write-Host "`t`t`t2. Change City" -Fore Cyan
Write-Host "`t`t`t3. Change Country" -Fore Cyan
Write-Host "`t`t`t4. Go to Main Menu`n" -Fore Cyan
[int]$xMenuLevel2 = Read-Host "`t`tEnter Menu Option Number"
if( $xMenuLevel2 -lt 1 -or $xMenuLevel2 -gt 4 ) {
Write-Host "`tPlease select one of the options available.`n" -Fore Red; Start-Sleep -Seconds 1
}
}
Switch ($xMenuLevel2) {
1{ Get-Weather $City $Country; pause }
2{ $City = Read-Host "`n`tEnter a city name" }
3{ $Country = Read-Host "`n`tEnter a country name" }
default { break}
}
}
2 {
while ( $xMenuLevel2 -lt 1 -or $xMenuLevel2 -gt 4 ) {
CLS
# Present the Menu Options
Write-Host "`n`t$UtilityName`n" -Fore Magenta
Write-Host "`t`t$Days day forecast for area code $ZipCode`n" -Fore Cyan
Write-Host "`t`t`t1. Refresh" -Fore Cyan
Write-Host "`t`t`t2. Change Zip Code" -Fore Cyan
Write-Host "`t`t`t3. Change Number of Days" -Fore Cyan
Write-Host "`t`t`t4. Go to Main Menu`n" -Fore Cyan
[int]$xMenuLevel2 = Read-Host "`t`tEnter Menu Option Number"
}
if( $xMenuLevel2 -lt 1 -or $xMenuLevel2 -gt 4 ){
Write-Host "`tPlease select one of the options available.`n" -Fore Red; Start-Sleep -Seconds 1
}
Switch ($xMenuLevel2) {
1{ Get-Forecast $ZipCode $Days; pause }
2{ $ZipCode = Read-Host "`n`tEnter a zip code" }
3{ $Days = Read-Host "`n`tEnter the number of days to forecast" }
default { break}
}
}
default { exit }
}
LoadMenuSystem
}
LoadMenuSystem