[moods] Add weather lookup to moods
This commit is contained in:
@ -5,6 +5,7 @@ from django.shortcuts import redirect, render
|
||||
from django.urls import reverse
|
||||
from django.utils import timezone
|
||||
from moods.models import Mood, MoodLogData, MoodQuality, MoodReason
|
||||
from moods.utils import fetch_current_weather
|
||||
from scrobbles.models import Scrobble
|
||||
|
||||
logger = logging.getLogger(__name__)
|
||||
@ -66,6 +67,25 @@ def checkin(request):
|
||||
mood_reason_ids=[int(reason_id)] if reason_id else [],
|
||||
)
|
||||
|
||||
# Attempt to add current weather from most recent location
|
||||
last_loc = (
|
||||
Scrobble.objects.filter(
|
||||
user=request.user,
|
||||
media_type=Scrobble.MediaType.GEO_LOCATION,
|
||||
geo_location__isnull=False,
|
||||
)
|
||||
.order_by("-timestamp")
|
||||
.first()
|
||||
)
|
||||
if last_loc and last_loc.geo_location:
|
||||
weather = fetch_current_weather(
|
||||
last_loc.geo_location.lat,
|
||||
last_loc.geo_location.lon,
|
||||
)
|
||||
if weather:
|
||||
log_data.weather_temp = weather["temp"]
|
||||
log_data.weather_description = weather["description"]
|
||||
|
||||
scrobble = Scrobble.objects.create(
|
||||
user=request.user,
|
||||
mood=mood,
|
||||
|
||||
Reference in New Issue
Block a user