Skip to content

Commit

Permalink
Made update dates explicit
Browse files Browse the repository at this point in the history
  • Loading branch information
luord committed Dec 12, 2024
1 parent e01f0a7 commit 4d36ed1
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 4 deletions.
2 changes: 1 addition & 1 deletion pelicanconf.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
(1, '{url}', '{save_as}'),
(2, '{base_name}/p/{number}', '{base_name}/p/{number}.html'),
)
DEFAULT_DATE = 'fs'
DEFAULT_DATE = None
SUMMARY_MAX_LENGTH = 100

# POST SETTINGS
Expand Down
12 changes: 9 additions & 3 deletions scripts/notifier.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,20 +34,24 @@
logging.basicConfig(level=logging.INFO)


def get_new_items(feed_url: str) -> list[feedparser.util.FeedParserDict]:
def get_new_items(
feed_url: str, date_attribute: str = 'published'
) -> list[feedparser.util.FeedParserDict]:
feed = feedparser.parse(feed_url)
zone = dt.datetime.fromisoformat(feed.feed.updated).astimezone().tzinfo
base_date = dt.datetime.now(tz=zone) - dt.timedelta(days=FEED_DELTA_DAYS)

return [
entry
for entry in feed.entries
if dt.datetime.fromisoformat(entry.published) >= base_date
if dt.datetime.fromisoformat(entry[date_attribute]) >= base_date
]


def send_newsletter(items: list[feedparser.util.FeedParserDict]) -> None:
for item in items:
logging.info(f"Sending newsletter for item {item.title}")

data = {
"from": MAIL_SENDER,
"to": MAIL_RECIPIENT,
Expand Down Expand Up @@ -85,6 +89,8 @@ def send_newsletter(items: list[feedparser.util.FeedParserDict]) -> None:

def send_webmentions(items: list[feedparser.util.FeedParserDict]) -> None:
for item in items:
logging.info(f"Sending webmentions for {item.title}, if any")

reply_links = iw.get_reply_urls(item.link)
for link in reply_links:
try:
Expand All @@ -104,7 +110,7 @@ def main() -> None:
logging.info(f"Getting items for last {FEED_DELTA_DAYS} days")

full_items = get_new_items(FEED_FULL)
note_items = get_new_items(FEED_NOTES)
note_items = get_new_items(FEED_NOTES, date_attribute="updated")

send_newsletter(full_items)
send_webmentions(full_items + note_items)
Expand Down

0 comments on commit 4d36ed1

Please sign in to comment.