Jul 13 - Optimize code
This commit is contained in:
@@ -11,6 +11,7 @@ use the existing `attributes` JSON and a private `_notified` sub-key so no migra
|
||||
is required. The key is prefixed with `_` to avoid colliding with user attributes.
|
||||
"""
|
||||
from datetime import datetime, timedelta
|
||||
from app.utils.time import utcnow
|
||||
from flask import current_app
|
||||
from app.extensions import db
|
||||
from app.models.listing import Listing
|
||||
@@ -25,13 +26,13 @@ def _already_notified(listing, key: str) -> bool:
|
||||
|
||||
def _mark_notified(listing, key: str):
|
||||
attrs = dict(listing.attributes or {})
|
||||
attrs[key] = datetime.utcnow().isoformat()
|
||||
attrs[key] = utcnow().isoformat()
|
||||
listing.attributes = attrs
|
||||
|
||||
|
||||
def warn_expiring(days: int = 3) -> int:
|
||||
"""Send warning emails for listings expiring within `days` days. Returns count."""
|
||||
now = datetime.utcnow()
|
||||
now = utcnow()
|
||||
window_end = now + timedelta(days=days)
|
||||
soon = (Listing.query
|
||||
.filter(Listing.status == ListingStatus.active,
|
||||
|
||||
Reference in New Issue
Block a user