这是indexloc提供的服务,不要输入任何密码
Skip to content
Closed
Show file tree
Hide file tree
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
Binary file added .DS_Store
Binary file not shown.
1 change: 1 addition & 0 deletions config.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,3 +6,4 @@
JOKES_SOURCE_FILE = 'data/jokes.json'
MAPQUEST_CONSUMER_KEY = '<MAPQUEST_CONSUMER_KEY>'
TIME_ZONE_DB_API_KEY = '<TIME_ZONE_DB_API_KEY>'
OPEN_WEATHER_MAP_ACCESS_TOKEN = '7af6de37fc4d3517129290b740663142'
Binary file added modules/.DS_Store
Binary file not shown.
Binary file added modules/src/.DS_Store
Binary file not shown.
2 changes: 2 additions & 0 deletions modules/src/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,5 +12,7 @@
'quote',
'request',
'time',
'weather',
Copy link
Owner

Choose a reason for hiding this comment

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

alphabetical

'wiki',

Copy link
Owner

Choose a reason for hiding this comment

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

extra line

]
22 changes: 22 additions & 0 deletions modules/src/weather.py
Original file line number Diff line number Diff line change
@@ -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
Binary file added modules/tests/.DS_Store
Binary file not shown.
7 changes: 7 additions & 0 deletions modules/tests/test_weather.py
Original file line number Diff line number Diff line change
@@ -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])