Python Forum
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Talking Weather
#1
Hello all, just wanted to post my script. This is the first one I've written and I made it to use the system default voice to speak the weather info to you. It also pulls up two satellite images from NOAA. Not real sure how optimized it is, but it works well. if you care to use you'll need to modify it for your local weather etc.
If you do use it let me know what you think.... happy coding@!

# ----  National Weather System by Python:
    # ----- weather crawler
# ----- using default system voice

from user_agent import generate_user_agent
from bs4 import BeautifulSoup
import requests, urllib.request, datetime
from pathlib import Path, os
import win32com.client as wincl


headers = {'User-Agent': generate_user_agent(device_type ='desktop', os = ('mac', 'linux'))}
page_response = requests.get('https://forecast.weather.gov/MapClick.php?lat=32.47318000000007&lon=-100.40478999999999#.XC2EbM1MFEa/', timeout = 5, headers = headers)
soup = BeautifulSoup(page_response.content, 'html.parser')

current = soup.find(id='current_conditions-summary')

weather = []
period = current.find(class_='myforecast-current').text
temp_f = current.find(class_='myforecast-current-lrg').text
temp_c = current.find(class_='myforecast-current-sm').text
weather.append(period)
weather.append(temp_f)
weather.append(temp_c)

table = soup.find('table')
for row in table.find_all('tr'):
    key = (' '.join(td.text.strip() for td in row.find_all('td')))
    weather.append(key)

seven_day = soup.find(id='seven-day-forecast')
forecast_items = seven_day.find_all(class_='tombstone-container')
current = forecast_items[0]

forecast = current.find(class_='period-name').text
short_desc = current.find(class_='short-desc').text
temp = current.select('p.temp.temp')[0].text
weather.append(forecast)
weather.append(short_desc)
weather.append(temp)

with open('current-weather.dat', 'w') as f:
    for info in weather:
        f.write(f'{info}\n')

s = wincl.Dispatch('sapi.SpVoice')  #   usinig Cortana as system default voice

currentTime = datetime.datetime.now()   # get current time for Cortana

currentTime.hour

if currentTime.hour < 12:
    s.Speak("Good morning Dawwg,... welcome to your desktop.")
else:
    if 12 <= currentTime.hour < 18:
        s.Speak("Good afternoon Dawwg,... welcome to your desktop.")
    else:
            s.Speak("Good evening Dawwg,... welcome to your desktop.")

s.Speak("Here are the local weather conditions... for the Sweetwater area.")

with open('current-weather.dat', 'r') as f:
    text = f.read()
    s.Speak (text)

with open('current-weather.dat', 'w') as f:
  f.write(f'"no current info"')

s.Speak("Here is the national weather radar")

        # grabing two satellite images & using default image viewer

urllib.request.urlretrieve("http://dsx.weather.com/util/image/map/us_radar_plus_usen_1280x720.jpg", "us_radar_plus_usen_1280x720.jpg")
urllib.request.urlretrieve("https://cdn.star.nesdis.noaa.gov/GOES16/ABI/CONUS/GEOCOLOR/2500x1500.jpg", "ABI-CONUS-GEOCOLOR-2500x1500.jpg")
os.system(r"%USERPROFILE%/Documents/weather/us_radar_plus_usen_1280x720.jpg")
os.system(r"%USERPROFILE%/Documents/weather/ABI-CONUS-GEOCOLOR-2500x1500.jpg")
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  PyQt6 Version of weather app menator01 3 3,165 Jan-30-2022, 12:32 AM
Last Post: menator01
  Tkinter Weather App menator01 1 1,952 Jan-16-2022, 11:23 PM
Last Post: menator01
  Meteostat - Historical Weather and Climate Data clampr 1 3,633 May-25-2021, 04:32 PM
Last Post: Gribouillis
  SCIKItlearn -Naive Bayes Accuracy (Weather Data) usman 0 3,285 Nov-07-2018, 05:25 PM
Last Post: usman
  A weather program. mcmxl22 0 2,829 Jul-30-2018, 03:19 AM
Last Post: mcmxl22

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020