Skip to content

Commit

Permalink
Even more unclosed sessions!
Browse files Browse the repository at this point in the history
  • Loading branch information
Cobular committed May 3, 2020
1 parent 3d3c78d commit 6b3e62e
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 0 deletions.
4 changes: 4 additions & 0 deletions api/routes/online.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,23 +37,27 @@ def prepare_json(self, start_date=None, end_date=None):
"""Return all data"""
session = session_creator()
results = session.query(Online).all()
session.close()
return [i.as_dict() for i in results]
if start_date is not None and end_date is None:
"""Return all data since datetime"""
session = session_creator()
results = session.query(Online).filter(Online.date >= start_date)
session.close()
return [i.as_dict() for i in results]
if start_date is None and end_date is not None:
"""Return all data after datetime"""
session = session_creator()
results = session.query(Online).filter(Online.date <= end_date)
session.close()
return [i.as_dict() for i in results]
if start_date is not None and end_date is not None:
"""Return all data between two datetimes"""
session = session_creator()
results = session.query(Online).filter(
Online.date <= end_date, Online.date >= start_date
)
session.close()
return [i.as_dict() for i in results]

def get(self):
Expand Down
4 changes: 4 additions & 0 deletions api/routes/text.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,23 +35,27 @@ def prepare_json(self, start_date=None, end_date=None):
if start_date is None and end_date is None:
session = session_creator()
results = session.query(Text).all()
session.close()
return [i.as_dict() for i in results]
if start_date is not None and end_date is None:
"""Return all data since datetime"""
session = session_creator()
results = session.query(Text).filter(Text.date >= start_date)
session.close()
return [i.as_dict() for i in results]
if start_date is None and end_date is not None:
"""Return all data after datetime"""
session = session_creator()
results = session.query(Text).filter(Text.date <= end_date)
session.close()
return [i.as_dict() for i in results]
if start_date is not None and end_date is not None:
"""Return all data between two datetimes"""
session = session_creator()
results = session.query(Text).filter(
Text.date <= end_date, Text.date >= start_date
)
session.close()
return [i.as_dict() for i in results]

def get(self):
Expand Down
4 changes: 4 additions & 0 deletions api/routes/voice.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,23 +34,27 @@ def prepare_json(self, start_date=None, end_date=None):
if start_date is None and end_date is None:
session = session_creator()
results = session.query(Voice).all()
session.close()
return [i.as_dict() for i in results]
if start_date is not None and end_date is None:
"""Return all data since datetime"""
session = session_creator()
results = session.query(Voice).filter(Voice.date >= start_date)
session.close()
return [i.as_dict() for i in results]
if start_date is None and end_date is not None:
"""Return all data after datetime"""
session = session_creator()
results = session.query(Voice).filter(Voice.date <= end_date)
session.close()
return [i.as_dict() for i in results]
if start_date is not None and end_date is not None:
"""Return all data between two datetimes"""
session = session_creator()
results = session.query(Voice).filter(
Voice.date <= end_date, Voice.date >= start_date
)
session.close()
return [i.as_dict() for i in results]

def get(self):
Expand Down

0 comments on commit 6b3e62e

Please sign in to comment.