Compare commits

...

2 Commits

4 changed files with 42 additions and 6 deletions

View File

@ -19,6 +19,7 @@ urlpatterns = [
url(r'^karma/', include('karma.urls')),
url(r'^markov/', include('markov.urls')),
url(r'^races/', include('races.urls')),
url(r'^weather/', include('weather.urls')),
url(r'^accounts/', include('registration.backends.default.urls')),
url(r'^admin/', admin.site.urls),

View File

@ -36,12 +36,15 @@ class Weather(Plugin):
weather = weather_summary(queryitems[0])
weather_output = (f"Weather in {weather['location']}: {weather['current']['description']}. "
f"{weather['current']['temp_F']}/{weather['current']['temp_C']}, "
f"feels like {weather['current']['feels_like_temp_F']}/{weather['current']['feels_like_temp_C']}. "
f"Wind {weather['current']['wind_speed']} from the {weather['current']['wind_direction']}. "
f"feels like {weather['current']['feels_like_temp_F']}/"
f"{weather['current']['feels_like_temp_C']}. "
f"Wind {weather['current']['wind_speed']} "
f"from the {weather['current']['wind_direction']}. "
f"Visibility {weather['current']['visibility']}. "
f"Precipitation {weather['current']['precipitation']}. "
f"Pressure {weather['current']['pressure']}. "
f"Cloud cover {weather['current']['cloud_cover']}. UV index {weather['current']['uv_index']}. "
f"Cloud cover {weather['current']['cloud_cover']}. "
f"UV index {weather['current']['uv_index']}. "
f"Today: {weather['today_forecast']['noteworthy']}, "
f"High {weather['today_forecast']['high_F']}/{weather['today_forecast']['high_C']}, "
f"Low {weather['today_forecast']['low_F']}/{weather['today_forecast']['low_C']}. "
@ -49,9 +52,10 @@ class Weather(Plugin):
f"High {weather['tomorrow_forecast']['high_F']}/{weather['tomorrow_forecast']['high_C']}, "
f"Low {weather['tomorrow_forecast']['low_F']}/{weather['tomorrow_forecast']['low_C']}. "
f"Day after tomorrow: {weather['day_after_tomorrow_forecast']['noteworthy']}, "
f"High {weather['day_after_tomorrow_forecast']['high_F']}/{weather['day_after_tomorrow_forecast']['high_C']}, "
f"Low {weather['day_after_tomorrow_forecast']['low_F']}/{weather['day_after_tomorrow_forecast']['low_C']}."
)
f"High {weather['day_after_tomorrow_forecast']['high_F']}/"
f"{weather['day_after_tomorrow_forecast']['high_C']}, "
f"Low {weather['day_after_tomorrow_forecast']['low_F']}/"
f"{weather['day_after_tomorrow_forecast']['low_C']}.")
return self.bot.reply(event, weather_output)

8
weather/urls.py Normal file
View File

@ -0,0 +1,8 @@
"""URL patterns for markov stuff."""
from django.urls import path
from weather.views import rpc_weather_report
urlpatterns = [
path('rpc/<query>/', rpc_weather_report, name='weather_rpc_query'),
]

23
weather/views.py Normal file
View File

@ -0,0 +1,23 @@
"""Manipulate Markov data via the Django site."""
import logging
from rest_framework.authentication import BasicAuthentication
from rest_framework.permissions import IsAuthenticated
from rest_framework.response import Response
from rest_framework.decorators import api_view, authentication_classes, permission_classes
from weather.lib import weather_summary
logger = logging.getLogger(__name__)
@api_view(['GET'])
@authentication_classes((BasicAuthentication, ))
@permission_classes((IsAuthenticated, ))
def rpc_weather_report(request, query):
"""Provide the weather report for a given query."""
if request.method != 'GET':
return Response({'detail': "Supported method: GET."}, status=405)
report = weather_summary(query)
return Response(report)