diff --git a/dr_botzo/urls.py b/dr_botzo/urls.py index e0a8a41..3abb52b 100644 --- a/dr_botzo/urls.py +++ b/dr_botzo/urls.py @@ -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), diff --git a/weather/urls.py b/weather/urls.py new file mode 100644 index 0000000..26bf7fd --- /dev/null +++ b/weather/urls.py @@ -0,0 +1,8 @@ +"""URL patterns for markov stuff.""" +from django.urls import path + +from weather.views import rpc_weather_report + +urlpatterns = [ + path('rpc//', rpc_weather_report, name='weather_rpc_query'), +] diff --git a/weather/views.py b/weather/views.py new file mode 100644 index 0000000..f9db0dd --- /dev/null +++ b/weather/views.py @@ -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)