mirror of
https://github.com/simon987/gabtv_feed.git
synced 2025-04-10 14:16:46 +00:00
35 lines
1.3 KiB
Python
35 lines
1.3 KiB
Python
from time import time
|
|
|
|
from hexlib.db import VolatileState, VolatileBooleanState
|
|
|
|
|
|
class GabTvState:
|
|
def __init__(self, prefix, host, port):
|
|
self._episodes = VolatileState(prefix, host=host, port=port)
|
|
self._visited = VolatileBooleanState(prefix, host=host, port=port)
|
|
|
|
def has_visited(self, item_id):
|
|
return self._visited["byid"][item_id]
|
|
|
|
def mark_visited(self, item_id):
|
|
self._visited["byid"][item_id] = True
|
|
|
|
def has_visited_episode(self, episode):
|
|
# TODO: This doesn't actually work because the 'stats' object never actually updates (?!?)
|
|
# if episode["stats"]["commentCount"] == 0:
|
|
# # No comments, don't need to visit
|
|
# return True
|
|
# com_count = self._episodes["episodes"][episode["_id"]]
|
|
# return not com_count or episode["stats"]["commentCount"] == com_count
|
|
last_visited = self._episodes["ep_ts"][episode["_id"]]
|
|
return last_visited and int(time()) - int(last_visited) <= 3600 * 24 * 3
|
|
|
|
def mark_visited_episode(self, episode):
|
|
self._episodes["ep_ts"][episode["_id"]] = int(time())
|
|
|
|
def has_visited_channel(self, channel_id):
|
|
return self._visited["channel"][channel_id]
|
|
|
|
def mark_visited_channel(self, item_id):
|
|
self._visited["channel"][item_id] = True
|