Merge pull request #64 from ekimekim/gunner/additional-thrimbletrimmer-integration

Gunner/additional thrimbletrimmer integration
pull/66/head
MasterGunner 5 years ago committed by GitHub
commit 6fa9d9d388
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -40,6 +40,25 @@ def metrics():
"""Expose Prometheus metrics.""" """Expose Prometheus metrics."""
return prometheus_client.generate_latest() return prometheus_client.generate_latest()
@app.route('/thrimshim')
def get_all_rows():
"""Gets all rows from the events table from the database"""
conn = app.db_manager.get_conn()
results = database.query(conn, """
SELECT *
FROM events""")
rows = []
for row in results:
row = row._asdict()
row['id'] = str(row['id'])
row = {
key: (
value.isoformat() if isinstance(value, datetime.datetime)
else value
) for key, value in row.items()
}
rows.append(row)
return json.dumps(rows)
@app.route('/thrimshim/<uuid:ident>', methods=['GET', 'POST']) @app.route('/thrimshim/<uuid:ident>', methods=['GET', 'POST'])
def thrimshim(ident): def thrimshim(ident):
@ -50,7 +69,6 @@ def thrimshim(ident):
else: else:
return get_row(ident) return get_row(ident)
def get_row(ident): def get_row(ident):
"""Gets the row from the database with id == ident.""" """Gets the row from the database with id == ident."""
conn = app.db_manager.get_conn() conn = app.db_manager.get_conn()
@ -73,7 +91,6 @@ def get_row(ident):
} }
return json.dumps(response) return json.dumps(response)
def update_row(ident, new_row): def update_row(ident, new_row):
"""Updates row of database with id = ident with the edit columns in """Updates row of database with id = ident with the edit columns in
new_row.""" new_row."""
@ -94,6 +111,13 @@ def update_row(ident, new_row):
for extra in extras: for extra in extras:
del new_row[extra] del new_row[extra]
#validate title length - YouTube titles are limited to 100 characters.
if len(new_row['video_title']) > 100:
return 'Title must be 100 characters or less', 400
#validate start time is less than end time
if new_row['video_start'] > new_row['video_end']:
return 'Video Start must be less than Video End.', 400
conn = app.db_manager.get_conn() conn = app.db_manager.get_conn()
#check a row with id = ident is in the database #check a row with id = ident is in the database
results = database.query(conn, """ results = database.query(conn, """
@ -140,7 +164,6 @@ def update_row(ident, new_row):
logging.info('Row {} updated to state {}'.format(ident, new_row['state'])) logging.info('Row {} updated to state {}'.format(ident, new_row['state']))
return '' return ''
@app.route('/thrimshim/manual-link/<uuid:ident>', methods=['POST']) @app.route('/thrimshim/manual-link/<uuid:ident>', methods=['POST'])
def manual_link(ident): def manual_link(ident):
"""Manually set a video_link if the state is 'UNEDITED' or 'DONE' and the """Manually set a video_link if the state is 'UNEDITED' or 'DONE' and the

Loading…
Cancel
Save