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

Weather add #13

Closed
wants to merge 9 commits into from
Closed
Show file tree
Hide file tree
Changes from 1 commit
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
6 changes: 6 additions & 0 deletions .idea/vcs.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 2 additions & 1 deletion modules/src/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,6 @@
'help',
'joke',
'movie',
'request'
'request',
'weather'
]
2 changes: 1 addition & 1 deletion modules/src/movie.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ def process(input, entities):
r = requests.get('http://www.omdbapi.com/?t=' + movie + '&plot=short&r=json')
data = r.json()
output['input'] = input
output['output'] = data['Title'] + '\nPlot: ' + data['Plot'] + '\nIMDb Rating: ' + data['imdbRating']
output['output'] = data['Title'] + '\nPlot: ' + data['Plot'] + '\nIMDb Rating: ' + data['imdbRating'] + data['Year']
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We want to make this PR about weather only (so that someone can refer it in the future for adding another module). Can you make another PR with this change?

output['success'] = True
except:
output['success'] = False
Expand Down
16 changes: 16 additions & 0 deletions modules/src/weather.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
import re
import requests

def process(input, entities=None):
output = {}

try:
city = entities['city'][0]['value']
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

change city to location

r = requests.get('http://api.openweathermap.org/data/2.5/weather?q=' + city + '&appid=adee94563461cdf1dcfe25956aea10ae')
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

appid needs to go in config.py

data = r.json()
output['input'] = input
output['output'] = 'Current weather: ' + data['main.temp']
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

access it as data['main']['temp']
also output data['weather'][0]['description']
and "the OpenWeatherMap name must be mentioned as a weather source in a visible part of the application." see here

output['success'] = True
except:
output['success'] = False
return output
6 changes: 6 additions & 0 deletions modules/tests/test_weather.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
import modules

def test_request():
assert('request' == modules.process_query('request')[0])
assert('request' == modules.process_query('report')[0])
assert('request' != modules.process_query('something random')[0])
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

add some relevant tests