Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Updated loc.py #21

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
63 changes: 45 additions & 18 deletions loc.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
import geocoder
# I have made changes to this file as geocoder is not functioning well
import requests
import json
import pyttsx3

g = geocoder.ip('me')

engine = pyttsx3.init()
voices = engine.getProperty('voices')
Expand All @@ -14,24 +13,52 @@ 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']))
api_key = "give-your-api-key"
base_url = "http://api.openweathermap.org/data/2.5/weather?" #Now Taking weather data from openweather.org

speak("Tell me the name of the city")

city_name = takeCommand()
speak("Please Wait ...")

complete_url = base_url + "appid=" + api_key + "&q=" + city_name

response = requests.get(complete_url)

x = response.json()

if x["cod"] != "404":

y = x["main"]

current_temperature = y["temp"]

current_pressure = y["pressure"]

current_humidiy = y["humidity"]

z = x["weather"]

minimum_temperature = y["temp_min"]

weather_description = z[0]["description"]

speak(" Temperature (in kelvin unit) " +
str(current_temperature) +
"\n atmospheric pressure (in hPa unit) " +
str(current_pressure) +
"\n humidity (in percentage) " +
str(current_humidiy) +
"\n minimum temperature (in percentage) " +
str(minimum_temperature) +
"\n description " +
str(weather_description))

else:
speak(" City Not Found ")

if __name__ == '__main__':
weather()

# Happy Coding