Skip to content

Commit

Permalink
Don't send tweets that are older than the oldest read tweet
Browse files Browse the repository at this point in the history
Nitter increased the amount of tweets from 11 to 19 so we sent 8 old tweets to Discord
  • Loading branch information
TheLovinator1 committed Jul 21, 2023
1 parent a9c01f8 commit a494d84
Showing 1 changed file with 13 additions and 4 deletions.
17 changes: 13 additions & 4 deletions discord_twitter_webhooks/send_to_discord.py
Original file line number Diff line number Diff line change
Expand Up @@ -250,10 +250,6 @@ def send_to_discord(reader: Reader) -> None: # noqa: C901, PLR0912
Args:
reader: The reader which contains the entries.
"""
if True:
logger.info("This bot has been temporarily disabled.")
return

reader.update_feeds(workers=4)

# Loop through the unread (unsent) entries.
Expand All @@ -265,6 +261,19 @@ def send_to_discord(reader: Reader) -> None: # noqa: C901, PLR0912

entry: Entry | EntryLike
for entry in entries:
# Don't send tweets that are older than the oldest tweet we have
the_oldest_tweet = reader.get_entries(read=True)

# Sort the tweets by date
the_oldest_tweet = sorted(the_oldest_tweet, key=lambda x: x.published)

# Check if the entry is older than the oldest tweet we have
if entry.published < the_oldest_tweet[-1].published:
# Related: https://github.com/TheLovinator1/discord-twitter-webhooks/issues/129#issuecomment-1646086754
logger.info("Skipping entry {} as it is older than the oldest tweet we have", entry)
reader.mark_entry_as_read(entry)
continue

for _group in reader.get_tag((), "groups", []):
group = get_group(reader, str(_group))
if not group:
Expand Down

0 comments on commit a494d84

Please sign in to comment.