Skip to content
Open
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
3 changes: 3 additions & 0 deletions google-news-drive-sync/.flake8
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
[flake8]
max-line-length = 100
extend-ignore = E203
14 changes: 11 additions & 3 deletions google-news-drive-sync/src/article_repository.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,12 @@
import sqlite3
from contextlib import contextmanager
from dataclasses import dataclass
from datetime import datetime
from datetime import datetime, timezone
from pathlib import Path
from typing import Dict, Iterable, Iterator, List, Optional

from .news_fetcher import NewsArticle
from .utils import utcnow


@dataclass(frozen=True)
Expand Down Expand Up @@ -73,13 +74,20 @@ def _article_id(self, article: NewsArticle) -> str:
return article.url or article.title

def persist(self, articles: Iterable[NewsArticle]) -> None:
now = datetime.utcnow().isoformat()
now = utcnow().isoformat()
payload: List[tuple[str, str, str | None, str, str | None, str | None, str]] = []
for article in articles:
identifier = self._article_id(article)
if not identifier:
continue
published = article.published_at.isoformat() if article.published_at else None
published = None
if article.published_at is not None:
published_dt = article.published_at
if published_dt.tzinfo is None:
published_dt = published_dt.replace(tzinfo=timezone.utc)
else:
published_dt = published_dt.astimezone(timezone.utc)
published = published_dt.isoformat()
payload.append(
(
identifier,
Expand Down
15 changes: 12 additions & 3 deletions google-news-drive-sync/src/cache.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,12 @@
import hashlib
import sqlite3
from contextlib import contextmanager
from datetime import datetime, timedelta
from datetime import datetime, timedelta, timezone
from pathlib import Path
from typing import Iterable, Iterator, List

from .news_fetcher import NewsArticle
from .utils import utcnow


class ArticleCache:
Expand Down Expand Up @@ -64,7 +65,7 @@ def filter_new(self, articles: Iterable[NewsArticle]) -> List[NewsArticle]:
return fresh

def record(self, articles: Iterable[NewsArticle]) -> None:
now = datetime.utcnow()
now = utcnow()
cutoff = now - timedelta(days=self.retention_days)
with self._connect() as conn:
conn.executemany(
Expand All @@ -73,7 +74,7 @@ def record(self, articles: Iterable[NewsArticle]) -> None:
(
self._article_key(article),
article.url or article.title,
(article.published_at or now).isoformat(),
_normalise_datetime(article.published_at, fallback=now).isoformat(),
)
for article in articles
],
Expand All @@ -85,4 +86,12 @@ def record(self, articles: Iterable[NewsArticle]) -> None:
conn.commit()


def _normalise_datetime(value: datetime | None, *, fallback: datetime) -> datetime:
if value is None:
return fallback
if value.tzinfo is None:
return value.replace(tzinfo=timezone.utc)
return value.astimezone(timezone.utc)


__all__ = ["ArticleCache"]
13 changes: 11 additions & 2 deletions google-news-drive-sync/src/monitor.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,11 @@
from threading import Lock
from time import perf_counter
from typing import ContextManager, Dict, Iterator, List, Optional
codex/implement-google-news-drive-sync-project-pipeline-xuy9hr

Check notice

Code scanning / CodeQL

Statement has no effect Note

This statement has no effect.

Copilot Autofix

AI about 1 year ago

To fix the issue, simply delete the extraneous line on line 14: codex/implement-google-news-drive-sync-project-pipeline-xuy9hr. This line does not contribute any functionality or documentation and is, at best, a distraction and source of confusion. No imports or new definitions are needed, nor do surrounding lines require any alteration. Ensure that the code’s functional or logical behavior is not changed by this removal.

Suggested changeset 1
google-news-drive-sync/src/monitor.py

Autofix patch

Autofix patch
Run the following command in your local git repository to apply this patch
cat << 'EOF' | git apply
diff --git a/google-news-drive-sync/src/monitor.py b/google-news-drive-sync/src/monitor.py
--- a/google-news-drive-sync/src/monitor.py
+++ b/google-news-drive-sync/src/monitor.py
@@ -11,7 +11,6 @@
 from threading import Lock
 from time import perf_counter
 from typing import ContextManager, Dict, Iterator, List, Optional
-codex/implement-google-news-drive-sync-project-pipeline-xuy9hr
 
 from .utils import utcnow
 
EOF
@@ -11,7 +11,6 @@
from threading import Lock
from time import perf_counter
from typing import ContextManager, Dict, Iterator, List, Optional
codex/implement-google-news-drive-sync-project-pipeline-xuy9hr

from .utils import utcnow

Copilot is powered by AI and may make mistakes. Always verify output.

from .utils import utcnow



logger = logging.getLogger(__name__)

Expand Down Expand Up @@ -60,13 +65,17 @@

def start_run(self) -> None:
with self._lock:
self._last_run_started = datetime.utcnow()
codex/implement-google-news-drive-sync-project-pipeline-xuy9hr

Check notice

Code scanning / CodeQL

Statement has no effect Note

This statement has no effect.

Copilot Autofix

AI about 1 year ago

To fix the problem, the statement codex/implement-google-news-drive-sync-project-pipeline-xuy9hr on line 68 of google-news-drive-sync/src/monitor.py should be removed. This would eliminate the invalid, ineffective statement and clean up the code. No other changes are necessary, as deleting this line will not impact the function or flow of the code.

Suggested changeset 1
google-news-drive-sync/src/monitor.py

Autofix patch

Autofix patch
Run the following command in your local git repository to apply this patch
cat << 'EOF' | git apply
diff --git a/google-news-drive-sync/src/monitor.py b/google-news-drive-sync/src/monitor.py
--- a/google-news-drive-sync/src/monitor.py
+++ b/google-news-drive-sync/src/monitor.py
@@ -65,7 +65,6 @@
 
     def start_run(self) -> None:
         with self._lock:
- codex/implement-google-news-drive-sync-project-pipeline-xuy9hr
             self._last_run_started = utcnow()
   
 
@@ -74,7 +73,6 @@
     def complete_run(self, *, status: str = "success") -> None:
         with self._lock:
             self._runs += 1
-codex/implement-google-news-drive-sync-project-pipeline-xuy9hr
             self._last_run_completed = utcnow()
             self._last_status = status
 
EOF
@@ -65,7 +65,6 @@

def start_run(self) -> None:
with self._lock:
codex/implement-google-news-drive-sync-project-pipeline-xuy9hr
self._last_run_started = utcnow()


@@ -74,7 +73,6 @@
def complete_run(self, *, status: str = "success") -> None:
with self._lock:
self._runs += 1
codex/implement-google-news-drive-sync-project-pipeline-xuy9hr
self._last_run_completed = utcnow()
self._last_status = status

Copilot is powered by AI and may make mistakes. Always verify output.
self._last_run_started = utcnow()


self._last_status = "running"

def complete_run(self, *, status: str = "success") -> None:
with self._lock:
self._runs += 1
self._last_run_completed = datetime.utcnow()
codex/implement-google-news-drive-sync-project-pipeline-xuy9hr

Check notice

Code scanning / CodeQL

Statement has no effect Note

This statement has no effect.

Copilot Autofix

AI about 1 year ago

The best way to fix this issue is to simply remove the line codex/implement-google-news-drive-sync-project-pipeline-xuy9hr from line 77 of google-news-drive-sync/src/monitor.py. This line has no effect and is, in fact, a confusing artifact that should not remain in production or development code. No replacement is needed; the function will remain logically identical, but cleaner.

No changes are required to any imports, definitions, or methods beyond deleting this line.


Suggested changeset 1
google-news-drive-sync/src/monitor.py

Autofix patch

Autofix patch
Run the following command in your local git repository to apply this patch
cat << 'EOF' | git apply
diff --git a/google-news-drive-sync/src/monitor.py b/google-news-drive-sync/src/monitor.py
--- a/google-news-drive-sync/src/monitor.py
+++ b/google-news-drive-sync/src/monitor.py
@@ -74,7 +74,6 @@
     def complete_run(self, *, status: str = "success") -> None:
         with self._lock:
             self._runs += 1
-codex/implement-google-news-drive-sync-project-pipeline-xuy9hr
             self._last_run_completed = utcnow()
             self._last_status = status
 
EOF
@@ -74,7 +74,6 @@
def complete_run(self, *, status: str = "success") -> None:
with self._lock:
self._runs += 1
codex/implement-google-news-drive-sync-project-pipeline-xuy9hr
self._last_run_completed = utcnow()
self._last_status = status

Copilot is powered by AI and may make mistakes. Always verify output.
self._last_run_completed = utcnow()
self._last_status = status

def record_document_upload(self) -> None:
Expand Down
7 changes: 7 additions & 0 deletions google-news-drive-sync/src/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
import logging
import os
import time
from datetime import datetime, timezone
from pathlib import Path
from typing import Any, Callable, Iterable, Optional, TypeVar

Expand Down Expand Up @@ -144,3 +145,9 @@ def decrypt(self, payload: bytes) -> bytes:
if self._fernet is not None:
return self._fernet.decrypt(payload)
return _xor_bytes(payload, self._key)


def utcnow() -> datetime:
"""Return a timezone-aware ``datetime`` in UTC."""

return datetime.now(timezone.utc)
4 changes: 2 additions & 2 deletions google-news-drive-sync/tests/test_cache.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from datetime import datetime, timedelta
from datetime import datetime, timedelta, timezone

from src.cache import ArticleCache
from src.news_fetcher import NewsArticle
Expand Down Expand Up @@ -31,7 +31,7 @@ def test_cache_prunes_expired_entries(tmp_path):
old = make_article(
"https://example.com/old",
"Old",
published_at=datetime.utcnow() - timedelta(days=2),
published_at=datetime.now(timezone.utc) - timedelta(days=2),
)
cache.record([old])
cache.record([]) # trigger retention cleanup
Expand Down
Loading