Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[STTNHUB-348] fix(ingests): Use midnight for planning date if no time provided #77

Merged
merged 1 commit into from
Jul 2, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions server/features/ingest_planning.feature
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ Feature: Ingest STT Planning items
"ingest_provider": "#providers.sttplanningml#",
"slugline": "Miten tilanne Ukrainan sodan ymp\u00e4rill\u00e4 ja Ukrainassa kehittyy?",
"name": "Miten tilanne Ukrainan sodan ymp\u00e4rill\u00e4 ja Ukrainassa kehittyy?",
"planning_date": "2022-03-29T21:00:00+0000",
"planning_date": "2022-03-30T00:00:00+0000",
"source": "stt",
"state": "ingested",
"subject": [{
Expand All @@ -83,7 +83,7 @@ Feature: Ingest STT Planning items
"planning": {
"g2_content_type": "text",
"slugline": "UKRAINA // Y\u00f6n seurantaa",
"scheduled": "2022-03-29T21:00:00+0000",
"scheduled": "2022-03-30T00:00:00+0000",
"genre": [{
"qcode": "sttgenre:1",
"name": "P\u00e4\u00e4juttu"
Expand All @@ -101,7 +101,7 @@ Feature: Ingest STT Planning items
"planning": {
"g2_content_type": "picture",
"slugline": "Miten tilanne Ukrainan sodan ymp\u00e4rill\u00e4 ja Ukrainassa kehittyy?",
"scheduled": "2022-03-29T21:00:00+0000",
"scheduled": "2022-03-30T00:00:00+0000",
"genre": [{
"qcode": "sttimage:27",
"name": "Kv. kuvaa"
Expand Down
12 changes: 12 additions & 0 deletions server/stt/stt_planning_ml.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
from typing import Dict, Any, Optional, Set
from xml.etree.ElementTree import Element
from eve.utils import config
from datetime import datetime
import pytz

from superdesk import get_resource_service
from superdesk.utc import local_to_utc
Expand Down Expand Up @@ -46,6 +48,16 @@ def parse_item(self, tree: Element, original: Optional[Planning]) -> Optional[Pl

def datetime(self, value: str):
"""When there is no timezone info, assume it's Helsinki timezone."""

# First check if the value provided is a date only
# And store the date/time as midnight in UTC
try:
date_value = datetime.strptime(value, "%Y-%m-%d")
return date_value.replace(tzinfo=pytz.utc)
except ValueError:
pass

# Value provides more than date, try other formats
parsed = super().datetime(value)
if "+" not in value:
return local_to_utc(TIMEZONE, parsed)
Expand Down
2 changes: 1 addition & 1 deletion server/tests/stt_planning_ml_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ def test_placeholder_coverage(self):
"planning": {
"slugline": "",
"g2_content_type": "text",
"scheduled": datetime(2023, 5, 28, 21, 0, tzinfo=tzutc()),
"scheduled": datetime(2023, 5, 29, 0, 0, tzinfo=tzutc()),
},
"flags": {"placeholder": True},
"news_coverage_status": {
Expand Down
Loading