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

204 gmail detects the text contents to be the same and hides them in continuous emails #211

Merged
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
31 changes: 17 additions & 14 deletions tools/send_subscription_emails.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,24 +10,28 @@
app.app_context().push()


def send_mail_new_articles_search(to_email, search):
def send_mail_new_articles_search(to_email, new_content_dict):
body = "\r\n".join(
[
"Hi there,",
" ",
"There are new articles related to your subscribed search: "
+ str(search)
+ ".",
" ",
"You can find your subscriptions here: https://www.zeeguu.org/articles/mySearches"
"There are new articles related to your subscribed " + ("searches" if len(new_content_dict) > 1 else "search") + ". You can find your subscriptions here: https://www.zeeguu.org/articles/mySearches",
" "
])

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"

body += "\r\n".join([
" ",
" ",
"Cheers,",
"The Zeeguu Team",
]
)
print(f"""Sending to '{to_email}': ''{body}''""")
emailer = ZeeguuMailer("New articles to your subscribed search", body, to_email)

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


Expand All @@ -47,12 +51,11 @@ def send_subscription_emails():
if article.published_time > previous_day_datetime
]
if new_articles_found:
user_subscriptions[user.email] = user_subscriptions.get(user.email, []) + [
subscription.search.keywords
]
for user_email, keywords in user_subscriptions.items():
send_mail_new_articles_search(user_email, f"'{"','".join(keywords)}'")

updated_dict = user_subscriptions.get(user.email, {})
updated_dict[subscription.search.keywords] = [(article.title, article.url) 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)

if __name__ == "__main__":
send_subscription_emails()
Loading