put posts in database

This commit is contained in:
crunk 2023-10-01 21:34:49 +02:00
parent 53a9f313c0
commit 396e41dd8c
6 changed files with 26 additions and 2 deletions

0
__init.py__ Normal file
View File

0
models/__init.py__ Normal file
View File

0
scheduler/__init.py__ Normal file
View File

View File

@ -0,0 +1,23 @@
from datetime import datetime
from app import db
from models.postmodel import Post
from sqlalchemy.exc import (DatabaseError, DataError, IntegrityError,
InterfaceError, InvalidRequestError)
def schedule_text(request):
print(request.form["text"])
try:
post = Post(
content=request.form["text"],
last_updated=datetime.now(),
scheduled_time=datetime.now(),
)
db.session.add(post)
db.session.commit()
except DatabaseError:
db.session.rollback()
return "post scheduled"

View File

@ -1,6 +1,7 @@
from flask import Flask
from flask import Flask, request
from app import create_app
from scheduler.schedule_text import schedule_text
APP = create_app()
@ -12,7 +13,7 @@ def index():
@APP.route("/schedule", methods=["POST"])
def schedule_post():
return "post scheduled"
return schedule_text(request)
if __name__ == "__main__":