CAVEDU EducationDFRobot
Published © GPL3+

Lattepanda Weather Bot - Weather API & Google Cloud Service

This project shows you how to make a weather bot using python to get real-time weather data, and use DFrobot Lattepanda as SBC.

IntermediateFull instructions provided3 hours1,117
Lattepanda Weather Bot - Weather API & Google Cloud Service

Things used in this project

Hardware components

DFRobot Lattepanda Windows SBC
×1

Software apps and online services

darksky weather api

Story

Read more

Code

weather-test.py

Python
# This version is for windows, and there must be a mpv application in this work directory

import forecastio #import weather module
from gtts import gTTS #import google tts engine
import subprocessapi_key = 'Enter your api key' #your api key

# the following coordinate is Taipei/Taiwan
lat = 25.0391667 #set latitude and longitude interested
lng =  121.525
lang = 'EN' #language, 
file_name = 'weather.mp3'
player = './mpv' #set mpv as audio player

forecast = forecastio.load_forecast(api_key, lat, lng)

by_hour = forecast.hourly()
 
for data in by_hour.data:
   #get current time and temperature
   text = 'now is' + str(data.time) + 'the current temperature is' +  str(data.temperature) + 'degree celsius'
   print(text)
   tts = gTTS(text, lang) 
   tts.save(file_name)
   subprocess.call([player, file_name]) 
   #start a subprocess to play audio file

Credits

CAVEDU Education

CAVEDU Education

11 projects • 28 followers
We provide tutorials of robotics, Arduino, Raspberry Pi and IoT topics. http://www.cavedu.com
DFRobot

DFRobot

62 projects • 144 followers
Empowering Creation for Future Innovators

Comments