This is a sample of weather bot written in python
The following installation steps is for windows, for posix users, it's recomended to use your system package manager.
- Install python3 https://www.python.org/downloads/windows/
Remember to check the option to add the python system variable during the installation.
- Launch command line prompt
Press shortcut win+R and type in cmd to launch command line prompt, it's recommended to use powershell for windows users, just replace cmd with powershell.
- Install python package
pip install SpeechRecognition pyaudio python-forecastio gtts
- Download this project from github
- Download mpv player, if you want to use windows media player, you can replace the player location in the code with the new location.
Download mpv https://mpv.srsfckn.biz/
Download 7z http://www.developershome.com/7-zip/ , if you can unzip the 7zip file.
Finally move the mpv.exe into this project folder.
- Execute the following code
open the folder and open the weather-test.py with editor(ex. python IDLE)
Edit the following code, replace the api key with your own weather api key got from this website. https://darksky.net/dev/
Sign up a new account and get an api key.
# This version is for windows, and there must be a mpv application in this work directory import forecastio from gtts import gTTS import subprocess api_key = 'Enter your api key' # the following coordinate is Taipei/Taiwan lat = 25.0391667 lng = 121.525 lang = 'zh-TW' file_name = 'weather.mp3' player = './mpv' forecast = forecastio.load_forecast(api_key, lat, lng) by_hour = forecast.hourly() for data in by_hour.data: text = '在' + str(data.time) + '氣溫是' + str(data.temperature) + '度西' print(text) tts = gTTS(text, lang) tts.save(file_name) subprocess.call([player, file_name])