Skip to content

Commit

Permalink
fix: if there’s a problem upstream, continue
Browse files Browse the repository at this point in the history
  • Loading branch information
andylolz committed Aug 8, 2024
1 parent f9fd0c3 commit 5277bf9
Show file tree
Hide file tree
Showing 5 changed files with 21 additions and 4 deletions.
2 changes: 2 additions & 0 deletions x_notes/exceptions.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
class DataNotFoundException(Exception):
pass
8 changes: 7 additions & 1 deletion x_notes/notes.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
from typing import Any
from urllib.parse import urlparse

from .exceptions import DataNotFoundException
from .helpers import to_isoformat
from .tsv import get_generator

Expand Down Expand Up @@ -52,7 +53,12 @@ def get_notes(notes: dict[str, dict[str, Any]]) -> dict[str, dict[str, Any]]:
for k, v in notes.items()
if datetime.fromisoformat(v["created_at"]).timestamp() >= one_week_ago
}
for row in get_generator("notes/notes"):
try:
gen = get_generator("notes/notes")
except DataNotFoundException:
return notes

for row in gen:
note_id = row["noteId"]
created_at = to_isoformat(row["createdAtMillis"])
if float(row["createdAtMillis"]) / 1000 < one_week_ago:
Expand Down
3 changes: 2 additions & 1 deletion x_notes/ratings.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
from typing import Any

from .exceptions import DataNotFoundException
from .helpers import load_notes, save_notes
from .tsv import get_generator

Expand All @@ -21,7 +22,7 @@ def add_ratings(notes: dict[str, dict[str, Any]]) -> None:
while True:
try:
gen = get_generator("noteRatings/ratings", index)
except Exception:
except DataNotFoundException:
break
for row in gen:
if row["noteId"] in notes:
Expand Down
8 changes: 7 additions & 1 deletion x_notes/statuses.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
from typing import Any

from .exceptions import DataNotFoundException
from .helpers import to_isoformat
from .tsv import get_generator

Expand All @@ -8,7 +9,12 @@


def add_statuses(notes: dict[str, dict[str, Any]]) -> dict[str, dict[str, Any]]:
for row in get_generator("noteStatusHistory/noteStatusHistory"):
try:
gen = get_generator("noteStatusHistory/noteStatusHistory")
except DataNotFoundException:
return notes

for row in gen:
note_id = row["noteId"]
if note_id not in notes:
continue
Expand Down
4 changes: 3 additions & 1 deletion x_notes/tsv.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@

import requests

from .exceptions import DataNotFoundException


def get_data(date: date, fname: str, index: int = 0) -> Generator:
url_tmpl = (
Expand Down Expand Up @@ -35,4 +37,4 @@ def get_generator(fname: str, index: int = 0) -> Generator:
return get_data(n_days_ago, fname, index)
except Exception:
pass
raise Exception
raise DataNotFoundException

0 comments on commit 5277bf9

Please sign in to comment.