Commit 7e294c51 authored by echel0n's avatar echel0n

Added scheduled job to retrieve announcements from backend API.

Refactored announcement cards and layout for view.
parent 73f90725
......@@ -498,6 +498,17 @@ class Core(object):
id=self.name_cache.name
)
# add announcements job
self.scheduler.add_job(
self.announcements.run,
IntervalTrigger(
minutes=15,
timezone='utc'
),
name=self.announcements.name,
id=self.announcements.name
)
# start scheduler service
self.scheduler.start()
......@@ -511,6 +522,7 @@ class Core(object):
self.io_loop.run_in_executor(None, self.name_cache.run)
self.io_loop.run_in_executor(None, self.version_updater.run)
self.io_loop.run_in_executor(None, self.tz_updater.run)
self.io_loop.run_in_executor(None, self.announcements.run)
# start web server
self.wserver.start()
......@@ -526,13 +538,8 @@ class Core(object):
self.log.info("SiCKRAGE :: CONFIG VERSION:[v{}]".format(self.config.config_version))
self.log.info("SiCKRAGE :: DATABASE VERSION:[v{}]".format(self.main_db.version))
self.log.info("SiCKRAGE :: DATABASE TYPE:[{}]".format(self.db_type))
self.log.info("SiCKRAGE :: URL:[{}://{}:{}{}]".format(('http', 'https')[self.config.enable_https], self.config.web_host, self.config.web_port,
self.config.web_root))
self.announcements.add('test', 'test', 'test', 'test')
self.announcements.add('test', 'test', 'test', 'test')
self.announcements.add('test', 'test', 'test', 'test')
self.announcements.add('test', 'test', 'test', 'test')
self.log.info("SiCKRAGE :: URL:[{}://{}:{}{}]".format(('http', 'https')[self.config.enable_https],
self.config.web_host, self.config.web_port, self.config.web_root))
# start io_loop
self.io_loop.add_callback(started)
......
......@@ -18,6 +18,10 @@
# You should have received a copy of the GNU General Public License
# along with SiCKRAGE. If not, see <http://www.gnu.org/licenses/>.
# ##############################################################################
import threading
from sickrage.core.api import APIError
from sickrage.core.api.announcements import AnnouncementsAPI
class Announcement(object):
......@@ -39,16 +43,30 @@ class Announcements(object):
"""
def __init__(self):
self.announcements = []
self.name = "ANNOUNCEMENTS"
self.announcements = {}
self.seen = 0
def run(self):
threading.currentThread().setName(self.name)
try:
resp = AnnouncementsAPI().get_announcements()
if resp and 'data' in resp:
for announcement in resp['data']:
self.add(announcement['hash'], announcement['title'], announcement['description'], announcement['image'], announcement['date'])
except APIError:
pass
def add(self, title, description, image, date):
self.announcements += [Announcement(title, description, image, date)]
def add(self, ahash, title, description, image, date):
self.announcements[ahash] = Announcement(title, description, image, date)
def clear(self):
self.announcements = []
self.announcements.clear()
def get(self):
return self.announcements
self.seen = len(self.announcements)
return sorted(self.announcements.values(), key=lambda k: k.date)
def count(self):
return len(self.announcements)
return len(self.announcements) - self.seen
......@@ -31,7 +31,6 @@ from tornado.web import authenticated
import sickrage
from sickrage.core import AccountAPI
from sickrage.core.api import API
from sickrage.core.api.announcements import AnnouncementsAPI
from sickrage.core.helpers import remove_article
from sickrage.core.tv.episode import TVEpisode
from sickrage.core.tv.show.coming_episodes import ComingEpisodes
......
<%inherit file="./layouts/main.mako"/>
<%!
from datetime import datetime
import sickrage
%>
<%block name="content">
<div class="row">
% for announcement in sickrage.app.announcements.get():
<div class="col-lg-2 mx-auto">
<div class="announcement-container">
<div class="card mb-3" style="max-width: 540px;">
<div class="row no-gutters">
<div class="col-md-4">
<img src="${announcement.image}" class="card-img" alt="">
</div>
<div class="col-md-8">
<div class="card-body">
<div class="container">
<div class="row">
% for announcement in sickrage.app.announcements.get():
<div class="col-md-4 offset-md-0 offset-sm-1 mx-auto">
<div class="card-group">
<div class="card mb-3" style="max-width: 540px; height: 250px">
<div class="row ml-3 mt-3">
<div class="col">
<h5 class="card-title">${announcement.title}</h5>
<p class="card-text">${announcement.description}</p>
<p class="card-text"><small class="text-muted">${announcement.date}</small></p>
</div>
</div>
<div class="row no-gutters mx-3">
<div class="col-md-2">
<img src="${announcement.image}" class="card-img rounded-circle" alt=""
style="width: 85px;height: 85px;">
</div>
<div class="col-md-10">
<div class="card-body pt-0">
<div class="card-text"><div class="text-muted">${datetime.strptime(announcement.date, '%Y-%m-%d').strftime("%b %d, %Y")}</div></div>
<div class="card-text">${announcement.description}</div>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
% endfor
% endfor
</div>
</div>
</%block>
\ No newline at end of file
......@@ -110,7 +110,7 @@
aria-label="{{ __('Toggle navigation') }}">
<span class="navbar-toggler-icon"></span>
</button>
<div align="center" class="collapse navbar-collapse" id="navbarSupportedContent">
<div class="collapse navbar-collapse text-center" id="navbarSupportedContent">
<!-- Left Side Of Navbar -->
<ul class="navbar-nav mr-auto">
<li>
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment