from datetime import datetime from zoneinfo import ZoneInfo from app import db from models.postmodel import Post from sqlalchemy.exc import (DatabaseError, DataError, IntegrityError, InterfaceError, InvalidRequestError) def schedule_post(request): if request.form["text"]: return _schedule_text(request) if request.form["file"]: return _schedule_file(request) return "no correct header found" def _schedule_file(request): print(request.form["file"]) return "not yet implemented" def _schedule_text(request): print(request.form["text"]) try: text = request.form["text"] content = f"
{text}
" zoneinfo = ZoneInfo("Europe/Berlin") post = Post( content=content, last_updated=datetime.now().astimezone(tz=zoneinfo), scheduled_time=datetime.now().astimezone(tz=zoneinfo), ) db.session.add(post) db.session.commit() except DatabaseError: db.session.rollback() return "post scheduled"