-
Notifications
You must be signed in to change notification settings - Fork 20
/
loc.py
37 lines (28 loc) · 1.07 KB
/
loc.py
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
import geocoder
import requests
import json
import pyttsx3
g = geocoder.ip('me')
engine = pyttsx3.init()
voices = engine.getProperty('voices')
engine.setProperty('voice', voices[0].id)
def speak(audio):
engine.say(audio)
engine.runAndWait()
def weather():
api_url = "https://fcc-weather-api.glitch.me/api/current?lat=" + \
str(g.latlng[0]) + "&lon=" + str(g.latlng[1])
data = requests.get(api_url)
data_json = data.json()
if data_json['cod'] == 200:
main = data_json['main']
wind = data_json['wind']
weather_desc = data_json['weather'][0]
speak(str(data_json['coord']['lat']) + 'latitude' + str(data_json['coord']['lon']) + 'longitude')
speak('Current location is ' + data_json['name'] + data_json['sys']['country'] + 'dia')
speak('weather type ' + weather_desc['main'])
speak('Wind speed is ' + str(wind['speed']) + ' metre per second')
speak('Temperature: ' + str(main['temp']) + 'degree celcius')
speak('Humidity is ' + str(main['humidity']))
if __name__ == '__main__':
weather()