put posts in database
This commit is contained in:
parent
53a9f313c0
commit
396e41dd8c
0
__init.py__
Normal file
0
__init.py__
Normal file
0
models/__init.py__
Normal file
0
models/__init.py__
Normal file
0
scheduler/__init.py__
Normal file
0
scheduler/__init.py__
Normal file
23
scheduler/schedule_text.py
Normal file
23
scheduler/schedule_text.py
Normal 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"
|
5
start.py
5
start.py
@ -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__":
|
||||
|
Loading…
Reference in New Issue
Block a user