Compare commits

...
2 Commits
Author SHA1 Message Date
stefankoelle 4c743036d5 special search last updated 2026-08-11 20:32:32 +02:00
stefankoelle 619ea84c5f mailer test if today already sent 2026-08-11 20:29:29 +02:00
4 changed files with 38 additions and 0 deletions
+2
View File
@@ -536,6 +536,7 @@ def web_search_special(
"no_photo": db.search_contacts_without_photo,
"no_city": db.search_contacts_without_city,
"no_social": db.search_contacts_without_social,
"last_updated": db.search_contacts_last_updated,
}.get(type)
if not query_fn:
@@ -545,6 +546,7 @@ def web_search_special(
"no_photo": "Kontakte ohne Bild",
"no_city": "Kontakte ohne Stadt",
"no_social": "Kontakte ohne Social Profil",
"last_updated": "Zuletzt aktualisiert",
}
with db.get_connection() as conn:
+1
View File
@@ -92,5 +92,6 @@
<a href="/search/special?type=no_photo" class="special-search-link">ohne Bild</a>
<a href="/search/special?type=no_city" class="special-search-link">ohne City</a>
<a href="/search/special?type=no_social" class="special-search-link">ohne Social</a>
<a href="/search/special?type=last_updated" class="special-search-link">last updated</a>
</div>
</div>
+18
View File
@@ -232,6 +232,24 @@ def search_contacts_without_social(conn, account: str | None) -> list[dict]:
return cur.fetchall()
def search_contacts_last_updated(conn, account: str | None) -> list[dict]:
where_clause, params = _account_filter_clause(account)
op = "AND" if where_clause else "WHERE"
with conn.cursor() as cur:
cur.execute(
f"""SELECT id, full_name, given_name, middle_name, family_name,
prefix, suffix, organization, birthday, account, photo_url
FROM contacts {where_clause}
{op} given_name IS NOT NULL AND given_name != ''
AND family_name IS NOT NULL AND family_name != ''
AND family_name != 'X'
ORDER BY updated_at DESC
LIMIT 200""",
params,
)
return cur.fetchall()
def get_most_common_birthday(conn) -> date | None:
with conn.cursor() as cur:
cur.execute(
+17
View File
@@ -107,6 +107,23 @@ def main():
last_sync = datetime.now(Config.TIMEZONE)
next_mailer = next_run_time(MAIL_SEND_HOUR)
if MAILER_ENABLED:
try:
today = datetime.now(Config.TIMEZONE).date()
with db.get_connection() as conn:
with conn.cursor() as cur:
cur.execute(
"SELECT 1 FROM birthday_mail_log WHERE sent_date = %s LIMIT 1",
(today,),
)
already_sent = cur.fetchone() is not None
if not already_sent and next_mailer.date() > today:
logger.info("Mailer fuer heute noch nicht gesendet — hole nach")
run_mailer()
next_mailer = next_run_time(MAIL_SEND_HOUR)
except Exception:
logger.exception("Pruefung/Nachholen des Mailers fehlgeschlagen")
while not _shutdown:
now = datetime.now(Config.TIMEZONE)