Fix new services implementation 5
This commit is contained in:
@@ -236,11 +236,19 @@ class MadridTrafficClient(BaseTrafficClient, BaseAPIClient):
|
||||
try:
|
||||
# Process by year and month to avoid memory issues
|
||||
current_date = start_date.replace(day=1) # Start from beginning of month
|
||||
now = datetime.now()
|
||||
|
||||
while current_date <= end_date:
|
||||
year = current_date.year
|
||||
month = current_date.month
|
||||
|
||||
# Skip current month and future months (no historical data available yet)
|
||||
if (year == now.year and month >= now.month) or year > now.year:
|
||||
self.logger.info("Skipping current/future month - no historical data available",
|
||||
year=year, month=month)
|
||||
current_date = self._next_month(current_date)
|
||||
continue
|
||||
|
||||
# Build historical URL
|
||||
zip_url = self.api_client._build_historical_url(year, month)
|
||||
|
||||
@@ -251,7 +259,7 @@ class MadridTrafficClient(BaseTrafficClient, BaseAPIClient):
|
||||
zip_content = await self.api_client.fetch_historical_zip(zip_url)
|
||||
if not zip_content:
|
||||
self.logger.warning("Failed to fetch historical ZIP", url=zip_url)
|
||||
current_date = current_date.replace(month=current_date.month + 1) if current_date.month < 12 else current_date.replace(year=current_date.year + 1, month=1)
|
||||
current_date = self._next_month(current_date)
|
||||
continue
|
||||
|
||||
# Process ZIP content with enhanced parsing
|
||||
@@ -286,11 +294,8 @@ class MadridTrafficClient(BaseTrafficClient, BaseAPIClient):
|
||||
filtered_records=len(filtered_records),
|
||||
total_records=len(historical_records))
|
||||
|
||||
# Move to next month
|
||||
if current_date.month == 12:
|
||||
current_date = current_date.replace(year=current_date.year + 1, month=1)
|
||||
else:
|
||||
current_date = current_date.replace(month=current_date.month + 1)
|
||||
# Move to next month - extracted to helper method
|
||||
current_date = self._next_month(current_date)
|
||||
|
||||
return historical_records
|
||||
|
||||
@@ -347,4 +352,10 @@ class MadridTrafficClient(BaseTrafficClient, BaseAPIClient):
|
||||
zip_url=zip_url, error=str(e))
|
||||
return []
|
||||
|
||||
def _next_month(self, current_date: datetime) -> datetime:
|
||||
"""Helper method to move to next month"""
|
||||
if current_date.month == 12:
|
||||
return current_date.replace(year=current_date.year + 1, month=1)
|
||||
else:
|
||||
return current_date.replace(month=current_date.month + 1)
|
||||
|
||||
|
||||
Reference in New Issue
Block a user