Skip to content

Commit 5a71190

Browse files
committed
Resolve conflicts
2 parents a366014 + aeb28ff commit 5a71190

4 files changed

Lines changed: 20 additions & 15 deletions

File tree

src/mutations/create_article.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,11 +14,10 @@ class Arguments:
1414
article = Field(lambda: ArticleType)
1515

1616
def mutate(self, info, title, sports_type, published_at, url, slug, image=None):
17-
from datetime import datetime
1817
article_data = {
1918
"title": title,
2019
"sports_type": sports_type,
21-
"published_at": datetime.fromisoformat(published_at),
20+
"published_at": published_at, # Already in ISO 8601 format
2221
"url": url,
2322
"slug": slug,
2423
"image": image

src/repositories/article_repository.py

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
from src.database import daily_sun_db
22
from src.models.article import Article
33
from pymongo import UpdateOne
4-
from datetime import datetime, timedelta
4+
from datetime import datetime, timedelta, timezone
55

66
class ArticleRepository:
77
@staticmethod
@@ -52,7 +52,9 @@ def find_recent(limit_days=3):
5252
Retrieve articles from the last N days, sorted by published_at descending.
5353
"""
5454
article_collection = daily_sun_db["news_articles"]
55-
query = {"published_at": {"$gte": datetime.now() - timedelta(days=limit_days)}}
55+
# Calculate threshold as ISO 8601 string
56+
threshold = (datetime.now(timezone.utc) - timedelta(days=limit_days)).isoformat().replace('+00:00', 'Z')
57+
query = {"published_at": {"$gte": threshold}}
5658
articles = article_collection.find(query).sort("published_at", -1)
5759
return [Article.from_dict(article) for article in articles]
5860

@@ -62,9 +64,11 @@ def find_by_sports_type(sports_type, limit_days=3):
6264
Retrieve articles by sports_type from the last N days, sorted by published_at descending.
6365
"""
6466
article_collection = daily_sun_db["news_articles"]
67+
# Calculate threshold as ISO 8601 string
68+
threshold = (datetime.now(timezone.utc) - timedelta(days=limit_days)).isoformat().replace('+00:00', 'Z')
6569
query = {
6670
"sports_type": sports_type,
67-
"published_at": {"$gte": datetime.now() - timedelta(days=limit_days)}
71+
"published_at": {"$gte": threshold}
6872
}
6973
articles = article_collection.find(query).sort("published_at", -1)
7074
return [Article.from_dict(article) for article in articles]
@@ -75,5 +79,7 @@ def delete_not_recent(limit_days=3):
7579
Delete articles older than N days, sorted by published_at descending.
7680
"""
7781
article_collection = daily_sun_db["news_articles"]
78-
query = {"published_at": {"$lt": datetime.now() - timedelta(days=limit_days)}}
82+
# Calculate threshold as ISO 8601 string
83+
threshold = (datetime.now(timezone.utc) - timedelta(days=limit_days)).isoformat().replace('+00:00', 'Z')
84+
query = {"published_at": {"$lt": threshold}}
7985
article_collection.delete_many(query)

src/scrapers/daily_sun_scrape.py

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import os
22
import requests
3-
from datetime import datetime, timedelta
3+
from datetime import datetime, timedelta, timezone
44
from dotenv import load_dotenv
55
from ..services import ArticleService
66
from ..utils.constants import ARTICLE_IMG_TAG
@@ -24,14 +24,17 @@ def fetch_news():
2424
response.raise_for_status()
2525
data = response.json()
2626

27-
# Current date and 3-day threshold
28-
current_date = datetime.now()
27+
# Current date and 3-day threshold (in UTC)
28+
current_date = datetime.now(timezone.utc)
2929
three_days_ago = current_date - timedelta(days=3)
3030

3131
# Process articles
3232
articles_to_store = []
3333
for article in data.get("articles", []):
34-
published_at = datetime.strptime(article["published_at"], "%Y-%m-%d %H:%M:%S")
34+
published_at_dt = datetime.strptime(article["published_at"], "%Y-%m-%d %H:%M:%S")
35+
# Assume the timezone is UTC and convert to ISO 8601 format string
36+
published_at_dt = published_at_dt.replace(tzinfo=timezone.utc)
37+
published_at = published_at_dt.isoformat().replace('+00:00', 'Z')
3538

3639
if published_at >= three_days_ago:
3740
# Extract sport type from title
@@ -61,7 +64,7 @@ def fetch_news():
6164
"published_at": published_at,
6265
"url": article_url,
6366
"slug": article["slug"],
64-
"created_at": datetime.now()
67+
"created_at": datetime.now(timezone.utc).isoformat().replace('+00:00', 'Z')
6568
}
6669
articles_to_store.append(article_doc)
6770

src/types.py

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -190,7 +190,4 @@ class ArticleType(ObjectType):
190190

191191
def __init__(self, **kwargs):
192192
for key, value in kwargs.items():
193-
if key == "published_at" and isinstance(value, datetime):
194-
setattr(self, key, value.isoformat())
195-
else:
196-
setattr(self, key, value)
193+
setattr(self, key, value)

0 commit comments

Comments
 (0)