2022-07-09 10:32:49 +00:00
|
|
|
import time
|
|
|
|
from files.classes.comment import Comment
|
|
|
|
from files.classes.submission import Submission
|
2022-07-10 09:32:53 +00:00
|
|
|
from files.helpers.const import *
|
2022-10-11 16:41:09 +00:00
|
|
|
from sqlalchemy.sql import func
|
2022-07-09 10:32:49 +00:00
|
|
|
|
|
|
|
def apply_time_filter(t, objects, Class):
|
|
|
|
now = int(time.time())
|
|
|
|
if t == 'hour':
|
|
|
|
cutoff = now - 3600
|
|
|
|
elif t == 'day':
|
|
|
|
cutoff = now - 86400
|
|
|
|
elif t == 'week':
|
|
|
|
cutoff = now - 604800
|
|
|
|
elif t == 'month':
|
|
|
|
cutoff = now - 2592000
|
|
|
|
elif t == 'year':
|
|
|
|
cutoff = now - 31536000
|
|
|
|
else:
|
|
|
|
cutoff = 0
|
|
|
|
|
|
|
|
return objects.filter(Class.created_utc >= cutoff)
|