Powershell is very useful for getting information from the Internet. The Invoke-RestMethod cmdlet is used as an alternative to curl on Linux.
PS C:\Users\Intel i5> (Invoke-RestMethod "https://www.wttr.in") Weather report: Sydney, Australia \ / Partly cloudy _ /"".-. +10(9) °C \_( ). ↘ 15 km/h /(___(__) 10 km 0.0 mm ┌─────────────┐ ┌──────────────────────────────┬───────────────────────┤ Thu 22 Jun ├───────────────────────┬──────────────────────────────┐ │ Morning │ Noon └──────┬──────┘ Evening │ Night │ ├──────────────────────────────┼──────────────────────────────┼──────────────────────────────┼──────────────────────────────┤ │ \ / Sunny │ \ / Partly cloudy │ \ / Partly cloudy │ _`/"".-. Patchy rain po…│ │ .-. +12(11) °C │ _ /"".-. 15 °C │ _ /"".-. 16 °C │ ,\_( ). +14(13) °C │ │ ― ( ) ― → 9-12 km/h │ \_( ). ↓ 8-9 km/h │ \_( ). ↙ 22-30 km/h │ /(___(__) ↓ 16-23 km/h │ │ `-’ 10 km │ /(___(__) 10 km │ /(___(__) 10 km │ ‘ ‘ ‘ ‘ 10 km │ │ / \ 0.0 mm | 0% │ 0.0 mm | 0% │ 0.0 mm | 0% │ ‘ ‘ ‘ ‘ 0.1 mm | 86% │ └──────────────────────────────┴──────────────────────────────┴──────────────────────────────┴──────────────────────────────┘ ┌─────────────┐ ┌──────────────────────────────┬───────────────────────┤ Fri 23 Jun ├───────────────────────┬──────────────────────────────┐ │ Morning │ Noon └──────┬──────┘ Evening │ Night │ ├──────────────────────────────┼──────────────────────────────┼──────────────────────────────┼──────────────────────────────┤ │ _`/"".-. Patchy rain po…│ \ / Sunny │ \ / Clear │ \ / Clear │ │ ,\_( ). +13(10) °C │ .-. 17 °C │ .-. 17 °C │ .-. +13(11) °C │ │ /(___(__) ↘ 21-30 km/h │ ― ( ) ― → 21-24 km/h │ ― ( ) ― → 20-23 km/h │ ― ( ) ― ↘ 20-32 km/h │ │ ‘ ‘ ‘ ‘ 10 km │ `-’ 10 km │ `-’ 10 km │ `-’ 10 km │ │ ‘ ‘ ‘ ‘ 0.1 mm | 86% │ / \ 0.0 mm | 0% │ / \ 0.0 mm | 0% │ / \ 0.0 mm | 0% │ └──────────────────────────────┴──────────────────────────────┴──────────────────────────────┴──────────────────────────────┘ ┌─────────────┐ ┌──────────────────────────────┬───────────────────────┤ Sat 24 Jun ├───────────────────────┬──────────────────────────────┐ │ Morning │ Noon └──────┬──────┘ Evening │ Night │ ├──────────────────────────────┼──────────────────────────────┼──────────────────────────────┼──────────────────────────────┤ │ \ / Sunny │ \ / Sunny │ \ / Clear │ \ / Clear │ │ .-. +12(10) °C │ .-. 19 °C │ .-. 19 °C │ .-. +13(12) °C │ │ ― ( ) ― → 17-21 km/h │ ― ( ) ― ↘ 16-19 km/h │ ― ( ) ― ↘ 18-20 km/h │ ― ( ) ― ↘ 19-33 km/h │ │ `-’ 10 km │ `-’ 10 km │ `-’ 10 km │ `-’ 10 km │ │ / \ 0.0 mm | 0% │ / \ 0.0 mm | 0% │ / \ 0.0 mm | 0% │ / \ 0.0 mm | 0% │ └──────────────────────────────┴──────────────────────────────┴──────────────────────────────┴──────────────────────────────┘ |
This is a simple way to get a simple weather report. This uses the location of your Internet-facing IP address.
Another way is to scrape the web and get information about the weather from a website.
PS C:\Users\Intel i5> ([regex]::Matches((Invoke-RestMethod "http://weather.maniac.com/?&state=NY&county=2658"), '(?<=</b>).*?(?=<br>)') | ForEach-Object { $_.Value }) </font> </a>7:34 pm EDT Jun 21, 2023</td></tr><tr><td colspan="2" valign="top" align="center"><hr> Showers likely between 8pm and 5am, then rain after 5am. Low around 59. Northeast wind 8 to 13 mph. Chance of precipitation is 80%. New precipitation amounts between a tenth and quarter of an inch possible. Rain. High near 66. Northeast wind 15 to 17 mph. Chance of precipitation is 80%. New precipitation amounts between a quarter and half of an inch possible. Showers likely, then showers and possibly a thunderstorm after 2am. Low around 64. Northeast wind 3 to 8 mph. Chance of precipitation is 80%. New rainfall amounts between a tenth and quarter of an inch, except higher amounts possible in thunderstorms. Showers and possibly a thunderstorm before 8am, then showers likely between 8am and 11am, then showers likely and possibly a thunderstorm after 11am. High near 79. South wind 7 to 14 mph. Chance of precipitation is 80%. New rainfall amounts between a quarter and half of an inch possible. Showers likely and possibly a thunderstorm. Cloudy, with a low around 69. South wind 8 to 11 mph. Chance of precipitation is 70%. New rainfall amounts between a tenth and quarter of an inch, except higher amounts possible in thunderstorms. Showers likely, with thunderstorms also possible after 11am. Cloudy, with a high near 80. Chance of precipitation is 70%. New rainfall amounts between a tenth and quarter of an inch, except higher amounts possible in thunderstorms. A 50 percent chance of showers before 2am. Mostly cloudy, with a low around 68. Showers likely and possibly a thunderstorm, mainly after 2pm. Partly sunny, with a high near 82. Chance of precipitation is 70%. Showers likely and possibly a thunderstorm before 8pm, then a chance of showers between 8pm and 2am. Mostly cloudy, with a low around 69. Chance of precipitation is 60%. Showers likely, mainly after 2pm. Mostly cloudy, with a high near 83. Chance of precipitation is 60%. Showers likely and possibly a thunderstorm. Mostly cloudy, with a low around 69. Chance of precipitation is 60%. Showers likely. Mostly cloudy, with a high near 80. Chance of precipitation is 70%. A 50 percent chance of showers. Mostly cloudy, with a low around 67. Showers likely. Mostly cloudy, with a high near 79. Chance of precipitation is 60%. |
This is a nice Powershell one-liner to get the weather report from New York 2658 and print the plain-text report.
([regex]::Matches((Invoke-RestMethod "http://weather.maniac.com/?&state=NY&county=2658"), '(?<=</b>).*?(?=<br>)') | ForEach-Object { $_.Value } |
This prints all text between the </b> and <br> tags. Web scraping is fun and this is a good example of this using Powershell.
This is another example. This gets the weather for Chicago IL.
PS C:\Users\Intel i5> ([regex]::Matches((Invoke-RestMethod "https://forecast.weather.gov/MapClick.php?CityName=Chicago&state=IL&site=LOT&textField1=41.837&textField2=-87.685"), '(?<=<div class="col-sm-10 forecast-text">).*?(?=</div>)') | ForEach-Object { $_.Value }) Partly cloudy, with a low around 65. Northeast wind 5 to 10 mph, with gusts as high as 15 mph. Mostly sunny, with a high near 78. Northeast wind 5 to 10 mph, with gusts as high as 15 mph. Mostly clear, with a low around 63. Northeast wind 5 to 10 mph becoming light north northeast in the evening. Sunny, with a high near 80. Northeast wind 5 to 10 mph. Mostly clear, with a low around 63. Northeast wind 5 to 10 mph becoming west after midnight. Sunny, with a high near 84. A 30 percent chance of showers and thunderstorms after 1am. Partly cloudy, with a low around 68. A chance of showers, with thunderstorms also possible after 1pm. Partly sunny, with a high near 90. A chance of showers and thunderstorms before 10pm, then a chance of showers between 10pm and 1am. Partly cloudy, with a low around 66. A chance of showers. Mostly sunny, with a high near 81. A chance of showers. Partly cloudy, with a low around 62. Mostly sunny, with a high near 75. Partly cloudy, with a low around 59. Mostly sunny, with a high near 73. |
Yet another way is to use the OpenWeather API.
PS C:\Users\Intel i5> (Invoke-RestMethod "https://api.openweathermap.org/data/2.5/weather?q=Sydney&appid=MY_API_KEY&units=metric") coord : @{lon=151.2073; lat=-33.8679} weather : {@{id=800; main=Clear; description=clear sky; icon=01d}} base : stations main : @{temp=15.15; feels_like=14.1; temp_min=13.75; temp_max=16.32; pressure=1015; humidity=53} visibility : 10000 wind : @{speed=6.17; deg=310} clouds : @{all=0} dt : 1687566726 sys : @{type=2; id=2002865; country=AU; sunrise=1687554026; sunset=1687589657} timezone : 36000 id : 2147714 name : Sydney cod : 200 |
Use your OpenWeather API key and type a location such as Chicago and you will get the weather for your location.