diff --git a/.DS_Store b/.DS_Store new file mode 100644 index 00000000..bace6d35 Binary files /dev/null and b/.DS_Store differ diff --git a/config.py b/config.py index d5c8e5e8..dae88c02 100644 --- a/config.py +++ b/config.py @@ -6,3 +6,4 @@ JOKES_SOURCE_FILE = 'data/jokes.json' MAPQUEST_CONSUMER_KEY = '' TIME_ZONE_DB_API_KEY = '' +OPEN_WEATHER_MAP_ACCESS_TOKEN = '7af6de37fc4d3517129290b740663142' diff --git a/modules/.DS_Store b/modules/.DS_Store new file mode 100644 index 00000000..797705bb Binary files /dev/null and b/modules/.DS_Store differ diff --git a/modules/src/.DS_Store b/modules/src/.DS_Store new file mode 100644 index 00000000..9e6217b8 Binary files /dev/null and b/modules/src/.DS_Store differ diff --git a/modules/src/__init__.py b/modules/src/__init__.py index 956e3df9..dbf22076 100644 --- a/modules/src/__init__.py +++ b/modules/src/__init__.py @@ -12,5 +12,7 @@ 'quote', 'request', 'time', + 'weather', 'wiki', + ] diff --git a/modules/src/weather.py b/modules/src/weather.py new file mode 100644 index 00000000..8bb7a084 --- /dev/null +++ b/modules/src/weather.py @@ -0,0 +1,22 @@ +import re +import config +import os +import requests +from templates.button import * + +OPEN_WEATHER_MAP_ACCESS_TOKEN = os.environ.get('OPEN_WEATHER_MAP_ACCESS_TOKEN', config.OPEN_WEATHER_MAP_ACCESS_TOKEN) +def process(input, entities): + output = {} + + try: + location = entities['location'][0]['value'] + r = requests.get('http://api.openweathermap.org/data/2.5/weather?q=' + location + '&appid=' + OPEN_WEATHER_MAP_ACCESS_TOKEN) + data = r.json() + output['input'] = input + template = TextTemplate('The weather in ' + data['name'] + 'is: ' + data['weather'][0]['description'] + ' with a temperature of ' + data['main']['temp'] + '. Info provided by OpenWeatherMap.') + output['output'] = template.get_message() + output['success'] = True + except: + output['error_msg'] = TextTemplate('Sorry, I was not able to get weather info for ' + location + '. Please try again.').get_message() + output['success'] = False + return output diff --git a/modules/tests/.DS_Store b/modules/tests/.DS_Store new file mode 100644 index 00000000..702ad6c1 Binary files /dev/null and b/modules/tests/.DS_Store differ diff --git a/modules/tests/test_weather.py b/modules/tests/test_weather.py new file mode 100644 index 00000000..a12eea64 --- /dev/null +++ b/modules/tests/test_weather.py @@ -0,0 +1,7 @@ +import modules + +def test_weather(): + assert('weather' == modules.process_query('tell me the weather in London')[0]) + assert('weather' == modules.process_query('weather London')[0]) + assert('weather' == modules.process_query('whats the weather in London')[0]) + assert('weather' != modules.process_query('something random')[0]) \ No newline at end of file