Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improved Article formatting to contain stats #216

Merged
merged 1 commit into from
Sep 17, 2024
Merged
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
13 changes: 10 additions & 3 deletions tools/send_subscription_emails.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,16 @@
from zeeguu.core.emailer.zeeguu_mailer import ZeeguuMailer
from zeeguu.core.model.search_subscription import SearchSubscription
from zeeguu.api.app import create_app
from zeeguu.core.util.reading_time_estimator import estimate_read_time

app = create_app()
app.app_context().push()

def format_article_info(article):
art_info = article.article_info()
return f"""<b>{art_info["title"]}</b>\n
<p>&nbsp;&nbsp;{estimate_read_time(art_info["metrics"]["word_count"])}min, {art_info["metrics"]["cefr_level"]}, <a href="{art_info["url"]}">read</a> on <a href="{article.feed.url.domain.domain_name}">{article.feed.url.domain.domain_name}</a></p>\n"""


def send_mail_new_articles_search(to_email, new_content_dict):
body = "\r\n".join(
Expand All @@ -19,8 +25,8 @@ def send_mail_new_articles_search(to_email, new_content_dict):
" "
])

for keyword, titles in new_content_dict.items():
body += "\r\n".join([" ", f"Search: '{keyword}': "] + [f"""- <a href="{url}">{t}</a>""" for t, url in titles]) + "\n"
for keyword, articles in new_content_dict.items():
body += "\r\n".join([" ", f"<h3>{keyword}</h3>", " "] + [format_article_info(a) for a in articles]) + "\n"

body += "\r\n".join([
" ",
Expand All @@ -31,6 +37,7 @@ def send_mail_new_articles_search(to_email, new_content_dict):
)

subject = f"New articles for {"'" + "','".join(new_content_dict.keys()) + "'"}"
print(body)
emailer = ZeeguuMailer(subject, body, to_email)
emailer.send()

Expand Down Expand Up @@ -59,7 +66,7 @@ def send_subscription_emails():
]
if new_articles_found:
updated_dict = user_subscriptions.get(user.email, {})
updated_dict[subscription.search.keywords] = [(article.title, article.url) for article in new_articles_found]
updated_dict[subscription.search.keywords] = [article for article in new_articles_found]
user_subscriptions[user.email] = updated_dict
for user_email, new_content_dict in user_subscriptions.items():
send_mail_new_articles_search(user_email, new_content_dict)
Expand Down
1 change: 1 addition & 0 deletions zeeguu/core/util/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,4 @@
from zeeguu.core.util.encoding import JSONSerializable, encode, encode_error
from zeeguu.core.util.hash import text_hash, password_hash
from zeeguu.core.util.time import get_server_time_utc
from zeeguu.core.util.reading_time_estimator import estimate_read_time
9 changes: 9 additions & 0 deletions zeeguu/core/util/reading_time_estimator.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
import math


def estimate_read_time(word_count: int):
"""
Returns the estimated reading time in minutes, assuming
a reading rate of 160WPM.
"""
return math.ceil(word_count / 160)
Loading