microblog.pub/utils/__init__.py
Thomas Sileo d70c73cad7 Improve notifications
- Keep track of unread count
 - "follow back" action
2019-07-29 19:36:22 +02:00

33 lines
704 B
Python

import logging
from datetime import datetime
from datetime import timezone
from dateutil import parser
from little_boxes import activitypub as ap
logger = logging.getLogger(__name__)
def strtobool(s: str) -> bool:
if s in ["y", "yes", "true", "on", "1"]:
return True
if s in ["n", "no", "false", "off", "0"]:
return False
raise ValueError(f"cannot convert {s} to bool")
def parse_datetime(s: str) -> datetime:
# Parses the datetime with dateutil
dt = parser.parse(s)
# If no TZ is set, assumes it's UTC
if not dt.tzinfo:
dt = dt.replace(tzinfo=timezone.utc)
return dt
def now() -> str:
ap.format_datetime(datetime.now(timezone.utc))