feat(gismeteo): add gismeteo auth cookie support

This commit is contained in:
2026-08-21 11:05:49 +03:00
parent ca08bc282d
commit 1b5d009cdf
4 changed files with 11 additions and 13 deletions
+2 -1
View File
@@ -6,4 +6,5 @@ PYTHON_VERSION=$(grep -m 1 'python' ./pyproject.toml | grep -oP 'python\s*=\s*"\
DOCKER_PROJECTS=("gallery") DOCKER_PROJECTS=("gallery")
DOCKER_TAG=latest DOCKER_TAG=latest
OPENWEATHER_KEY="<EMPTY>" OPENWEATHER_KEY=""
GISMETEO_AUTH=""
+1
View File
@@ -13,6 +13,7 @@ services:
environment: environment:
- REDIS_HOST=redis - REDIS_HOST=redis
- OPENWEATHER_KEY=$OPENWEATHER_KEY - OPENWEATHER_KEY=$OPENWEATHER_KEY
- GISMETEO_AUTH=$GISMETEO_AUTH
- DEBUG=1 - DEBUG=1
ports: ports:
- 8000:80 - 8000:80
+1
View File
@@ -13,6 +13,7 @@ services:
environment: environment:
- REDIS_HOST=redis - REDIS_HOST=redis
- OPENWEATHER_KEY=$OPENWEATHER_KEY - OPENWEATHER_KEY=$OPENWEATHER_KEY
- GISMETEO_AUTH=$GISMETEO_AUTH
depends_on: depends_on:
- redis - redis
ports: ports:
+7 -12
View File
@@ -1,6 +1,7 @@
import datetime import datetime
import json import json
import logging import logging
from os import environ
from typing import Any from typing import Any
from bs4 import BeautifulSoup from bs4 import BeautifulSoup
@@ -9,6 +10,7 @@ from fastapi import HTTPException, status
from gallery.sketch.source import ApiSource from gallery.sketch.source import ApiSource
from gallery.sketch.weather.api import WeatherApi from gallery.sketch.weather.api import WeatherApi
from gallery.sketch.weather.model import Location, WeatherResponse, WeatherValue from gallery.sketch.weather.model import Location, WeatherResponse, WeatherValue
from gallery.sketch.weather.util import merge_weather_values
from . import datehelp from . import datehelp
from .parser import DAYS_PARSER, LOCATION_PARSER, ONE_DAY_PARSER, ROW_PARSERS from .parser import DAYS_PARSER, LOCATION_PARSER, ONE_DAY_PARSER, ROW_PARSERS
@@ -20,18 +22,7 @@ class GismeteoApi(WeatherApi):
PROVIDER = "gismeteo" PROVIDER = "gismeteo"
SOURCE = ApiSource( SOURCE = ApiSource(
"https://www.gismeteo.ru", "https://www.gismeteo.ru",
cookies={ cookies={"xauth": auth} if (auth := environ.get("GISMETEO_AUTH")) else None,
"cf_clearance": (
"zPj8qeaYZWp5BUZsWIRD7kd32s59IDWWaVvD7GGf6b4-1724254262-1.2.1.1-"
"R1PaHoqlm4OEgHfrOg6oAJmVmFJ7053JI_QDjIFlCAmbNY0oyw1J4QtgmEkAkTWF4C99X5hpXmZB2en."
"9Ey3NL0kzaE10UGBHPli5OLxHNKC3wQ34xmxTxg6GcKouXOPRgqo92lVRpQP7ghvDmvvT_"
"S6YXDbRonkamptWhZiAsIhsnIQg2Mt7Lk1fxSEVbaey_RXVQBvaR2ofiFgIavcbQPRFSvJ."
"Ct_FujmymTAZWh1XHTptK32kur81NXyPuARThetOKQm8AklaMa855Oom6Bms1a4F9b0yEHSd2inA4j3FR7uauu8hhwO0Z2goa3."
"ktpXXAQLz6dm.fBEWIHD7wooda15X57tCcDOely4hxhO4LK2lIH6TbOr."
"rZQAiRRhltHiCizP1Ou2SiF_81lb1umoDh739tQD1cnw_USnL."
"JwTHvkB00ZnaHRMi4FCBrsKIE0NxJO6kiv1QANqumzf5.8_pSIGRo2cKeO8xCydduDNFbStdOmLR6FU7ZKqVu"
)
},
) )
def _parse_oneday(self, date: datetime.date, data: str) -> WeatherResponse: def _parse_oneday(self, date: datetime.date, data: str) -> WeatherResponse:
@@ -45,6 +36,10 @@ class GismeteoApi(WeatherApi):
result.append({}) result.append({})
result[index][parser.KEY] = value result[index][parser.KEY] = value
values = [WeatherValue(**item) for item in result] values = [WeatherValue(**item) for item in result]
# group values by 3 hours
if len(values) > 8:
n = 3
values = [merge_weather_values(values[i].date, values[i : i + n]) for i in range(0, len(values), n)]
return WeatherResponse( return WeatherResponse(
location=location or "n/a", location=location or "n/a",
date=date, date=date,