Commit e26ad3eb authored by echel0n's avatar echel0n
Browse files

Converted Timezone Updater to class

parent 7e3baa8f
# Changelog
- * 30d75a7 - 2018-10-28: Disabled warning for when no nzb/torrent provider is picked if no nzb/torrent client enabled. Disabled search column for display show view if no nzb/torrent is picked.
- * 8000c60 - 2018-10-28: Converted Timezone Updater to class
- * 7e3baa8 - 2018-10-28: Disabled warning for when no nzb/torrent provider is picked if no nzb/torrent client enabled. Disabled search column for display show view if no nzb/torrent is picked.
- * 9969a0b - 2018-10-28: Added function to strip accents to encoding functions
- * bf93454 - 2018-10-27: Release v9.4.1
- * 3dbd257 - 2018-10-27: Release v9.3.100
......
......@@ -68,7 +68,7 @@ from sickrage.core.searchers.trakt_searcher import TraktSearcher
from sickrage.core.tv.show import TVShow
from sickrage.core.ui import Notifications
from sickrage.core.updaters.show_updater import ShowUpdater
from sickrage.core.updaters.tz_updater import update_network_dict
from sickrage.core.updaters.tz_updater import TimeZoneUpdater
from sickrage.core.upnp import UPNPClient
from sickrage.core.version_updater import VersionUpdater
from sickrage.core.webserver import WebServer
......@@ -139,6 +139,7 @@ class Core(object):
self.postprocessor_queue = None
self.version_updater = None
self.show_updater = None
self.tz_updater = None
self.daily_searcher = None
self.backlog_searcher = None
self.proper_searcher = None
......@@ -175,6 +176,7 @@ class Core(object):
self.postprocessor_queue = PostProcessorQueue()
self.version_updater = VersionUpdater()
self.show_updater = ShowUpdater()
self.tz_updater = TimeZoneUpdater()
self.daily_searcher = DailySearcher()
self.failed_snatch_searcher = FailedSnatchSearcher()
self.backlog_searcher = BacklogSearcher()
......@@ -350,13 +352,13 @@ class Core(object):
# add network timezones updater job
self.scheduler.add_job(
update_network_dict,
self.tz_updater.run,
IntervalTrigger(
days=1
),
next_run_time=datetime.datetime.now(),
name="TZUPDATER",
id="TZUPDATER"
name=self.tz_updater.name,
id=self.tz_updater.name
)
# add show updater job
......
......@@ -24,12 +24,11 @@ import datetime
import sickrage
from sickrage.core import helpers
from sickrage.core.common import UNAIRED, SKIPPED, statusStrings
from sickrage.core.updaters import tz_updater
def new_episode_finder():
curDate = datetime.date.today()
if tz_updater.network_dict:
if sickrage.app.tz_updater.network_dict:
curDate += datetime.timedelta(days=1)
else:
curDate += datetime.timedelta(days=2)
......@@ -55,7 +54,7 @@ def new_episode_finder():
if show.airs and show.network:
# This is how you assure it is always converted to local time
air_time = tz_updater.parse_date_time(episode['airdate'],
air_time = sickrage.app.tz_updater.parse_date_time(episode['airdate'],
show.airs, show.network).astimezone(sickrage.app.tz)
# filter out any episodes that haven't started airing yet,
......
......@@ -38,7 +38,6 @@ from sickrage.core.helpers import is_media_file, try_int, replaceExtension, \
from sickrage.core.nameparser import NameParser, InvalidNameException, InvalidShowException
from sickrage.core.processors.post_processor import PostProcessor
from sickrage.core.scene_numbering import get_scene_absolute_numbering, get_scene_numbering
from sickrage.core.updaters import tz_updater
from sickrage.indexers import IndexerApi
from sickrage.indexers.exceptions import indexer_seasonnotfound, indexer_error, indexer_episodenotfound
from sickrage.notifiers import Notifiers
......@@ -943,7 +942,7 @@ class TVEpisode(object):
if airdate_ordinal < 1:
return
airdatetime = tz_updater.parse_date_time(airdate_ordinal, self.show.airs, self.show.network)
airdatetime = sickrage.app.tz_updater.parse_date_time(airdate_ordinal, self.show.airs, self.show.network)
if sickrage.app.config.file_timestamp_timezone == 'local':
airdatetime = airdatetime.astimezone(sickrage.app.tz)
......
......@@ -23,7 +23,6 @@ import datetime
import sickrage
from sickrage.core.common import Quality, get_quality_string, WANTED, UNAIRED, timeFormat, dateFormat
from sickrage.core.helpers.srdatetime import srDateTime
from sickrage.core.updaters.tz_updater import parse_date_time
class ComingEpisodes:
......@@ -111,7 +110,8 @@ class ComingEpisodes:
results += result(s, e)
for index, item in enumerate(results):
results[index]['localtime'] = srDateTime(parse_date_time(item['airdate'], item['airs'], item['network']),
results[index]['localtime'] = srDateTime(
sickrage.app.tz_updater.parse_date_time(item['airdate'], item['airs'], item['network']),
convert=True).dt
results.sort(ComingEpisodes.sorts[sort])
......
......@@ -20,6 +20,7 @@
from __future__ import unicode_literals
import re
import threading
from datetime import datetime
from CodernityDB.database import RecordNotFound
......@@ -30,12 +31,22 @@ from sickrage.core.helpers import try_int
from sickrage.core.helpers.encoding import ss
from sickrage.core.websession import WebSession
network_dict = {}
time_regex = re.compile(r'(?P<hour>\d{1,2})(?:[:.]?(?P<minute>\d{2})?)? ?(?P<meridiem>[PA]\.? ?M?)?\b', re.I)
class TimeZoneUpdater(object):
def __init__(self):
self.name = "TZUPDATER"
self.network_dict = {}
self.time_regex = re.compile(r'(?P<hour>\d{1,2})(?:[:.]?(?P<minute>\d{2})?)? ?(?P<meridiem>[PA]\.? ?M?)?\b',
re.I)
# update the network timezone table
def update_network_dict():
def run(self):
# set thread name
threading.currentThread().setName(self.name)
self.update_network_dict()
# update the network timezone table
def update_network_dict(self):
"""Update timezone information from SR repositories"""
url = 'https://cdn.sickrage.ca/network_timezones/'
......@@ -57,9 +68,8 @@ def update_network_dict():
except (IOError, OSError):
pass
queries = []
for network, timezone in d.items():
existing = network in network_dict
existing = network in self.network_dict
if not existing:
try:
sickrage.app.cache_db.get('network_timezones', network)
......@@ -69,7 +79,7 @@ def update_network_dict():
'network_name': ss(network),
'timezone': timezone
})
elif network_dict[network] is not timezone:
elif self.network_dict[network] is not timezone:
try:
dbData = sickrage.app.cache_db.get('network_timezones', network)
dbData['timezone'] = timezone
......@@ -78,29 +88,27 @@ def update_network_dict():
continue
if existing:
del network_dict[network]
del self.network_dict[network]
for x in network_dict:
for x in self.network_dict:
try:
sickrage.app.cache_db.delete(sickrage.app.cache_db.get('network_timezones', x))
except RecordNotFound:
continue
load_network_dict()
self.load_network_dict()
# load network timezones from db into dict
def load_network_dict():
# load network timezones from db into dict
def load_network_dict(self):
"""
Return network timezones from db
"""
global network_dict
network_dict = dict([(x['network_name'], x['timezone']) for x in sickrage.app.cache_db.all('network_timezones')])
self.network_dict = dict(
[(x['network_name'], x['timezone']) for x in sickrage.app.cache_db.all('network_timezones')])
# get timezone of a network or return default timezone
def get_network_timezone(network):
# get timezone of a network or return default timezone
def get_network_timezone(self, network):
"""
Get a timezone of a network from a given network dict
......@@ -111,13 +119,12 @@ def get_network_timezone(network):
return sickrage.app.tz
try:
return tz.gettz(network_dict[network]) or sickrage.app.tz
return tz.gettz(self.network_dict[network]) or sickrage.app.tz
except Exception:
return sickrage.app.tz
# parse date and time string into local time
def parse_date_time(d, t, network):
# parse date and time string into local time
def parse_date_time(self, d, t, network):
"""
Parse date and time string into local time
:param d: date string
......@@ -126,11 +133,11 @@ def parse_date_time(d, t, network):
:return: datetime object containing local time
"""
if not network_dict:
load_network_dict()
if not self.network_dict:
self.load_network_dict()
parsed_time = time_regex.search(t)
network_tz = get_network_timezone(network)
parsed_time = self.time_regex.search(t)
network_tz = self.get_network_timezone(network)
hr = 0
m = 0
......@@ -154,6 +161,5 @@ def parse_date_time(d, t, network):
return result.replace(hour=hr, minute=m, tzinfo=network_tz)
def test_timeformat(t):
return time_regex.search(t) is not None
def test_timeformat(self, t):
return self.time_regex.search(t) is not None
......@@ -55,7 +55,6 @@ from sickrage.core.media.poster import Poster
from sickrage.core.queues.search import BacklogQueueItem, ManualSearchQueueItem
from sickrage.core.tv.show.coming_episodes import ComingEpisodes
from sickrage.core.tv.show.history import History
from sickrage.core.updaters import tz_updater
from sickrage.indexers import IndexerApi
from sickrage.indexers.exceptions import indexer_error, \
indexer_showincomplete, indexer_shownotfound
......@@ -733,7 +732,7 @@ class CMD_Episode(ApiCall):
# convert stuff to human form
if try_int(episode['airdate'], 1) > 693595: # 1900
episode['airdate'] = srdatetime.srDateTime(srdatetime.srDateTime(
tz_updater.parse_date_time(int(episode['airdate']), showObj.airs, showObj.network),
sickrage.app.tz_updater.parse_date_time(int(episode['airdate']), showObj.airs, showObj.network),
convert=True).dt).srfdate(d_preset=dateFormat)
else:
episode['airdate'] = 'Never'
......@@ -1810,7 +1809,7 @@ class CMD_Show(ApiCall):
if try_int(showObj.next_aired, 1) > 693595:
dtEpisodeAirs = srdatetime.srDateTime(
tz_updater.parse_date_time(showObj.next_aired, showDict['airs'], showDict['network']), convert=True).dt
sickrage.app.tz_updater.parse_date_time(showObj.next_aired, showDict['airs'], showDict['network']), convert=True).dt
showDict['airs'] = srdatetime.srDateTime(dtEpisodeAirs).srftime(t_preset=timeFormat).lstrip('0').replace(
' 0', ' ')
showDict['next_ep_airdate'] = srdatetime.srDateTime(dtEpisodeAirs).srfdate(d_preset=dateFormat)
......@@ -2413,7 +2412,7 @@ class CMD_ShowSeasons(ApiCall):
if try_int(row['airdate'], 1) > 693595: # 1900
dtEpisodeAirs = srdatetime.srDateTime(
tz_updater.parse_date_time(row['airdate'], showObj.airs, showObj.network), convert=True).dt
sickrage.app.tz_updater.parse_date_time(row['airdate'], showObj.airs, showObj.network), convert=True).dt
row['airdate'] = srdatetime.srDateTime(dtEpisodeAirs).srfdate(d_preset=dateFormat)
else:
row['airdate'] = 'Never'
......@@ -2445,7 +2444,7 @@ class CMD_ShowSeasons(ApiCall):
row["quality"] = get_quality_string(quality)
if try_int(row['airdate'], 1) > 693595: # 1900
dtEpisodeAirs = srdatetime.srDateTime(
tz_updater.parse_date_time(row['airdate'], showObj.airs, showObj.network), convert=True).dt
sickrage.app.tz_updater.parse_date_time(row['airdate'], showObj.airs, showObj.network), convert=True).dt
row['airdate'] = srdatetime.srDateTime(dtEpisodeAirs).srfdate(d_preset=dateFormat)
else:
row['airdate'] = 'Never'
......@@ -2693,7 +2692,7 @@ class CMD_Shows(ApiCall):
if try_int(curShow.next_aired, 1) > 693595: # 1900
dtEpisodeAirs = srdatetime.srDateTime(
tz_updater.parse_date_time(curShow.next_aired, curShow.airs, showDict['network']), convert=True).dt
sickrage.app.tz_updater.parse_date_time(curShow.next_aired, curShow.airs, showDict['network']), convert=True).dt
showDict['next_ep_airdate'] = srdatetime.srDateTime(dtEpisodeAirs).srfdate(d_preset=dateFormat)
else:
showDict['next_ep_airdate'] = ''
......
......@@ -79,7 +79,6 @@ from sickrage.core.traktapi import srTraktAPI
from sickrage.core.tv.episode import TVEpisode
from sickrage.core.tv.show.coming_episodes import ComingEpisodes
from sickrage.core.tv.show.history import History as HistoryTool
from sickrage.core.updaters import tz_updater
from sickrage.core.webserver import ApiHandler
from sickrage.core.webserver.routes import Route
from sickrage.indexers import IndexerApi
......@@ -372,7 +371,8 @@ class CalendarHandler(BaseHandler):
for episode in (x for x in sickrage.app.main_db.get_many('tv_episodes', int(show.indexerid))
if past_date <= x['airdate'] < future_date):
air_date_time = tz_updater.parse_date_time(episode['airdate'], show.airs, show.network).astimezone(utc)
air_date_time = sickrage.app.tz_updater.parse_date_time(episode['airdate'], show.airs,
show.network).astimezone(utc)
air_date_time_end = air_date_time + datetime.timedelta(minutes=try_int(show.runtime, 60))
# Create event for episode
......@@ -1216,7 +1216,8 @@ class Home(WebHandler):
today = datetime.datetime.now().replace(tzinfo=sickrage.app.tz)
airDate = datetime.datetime.fromordinal(curEp['airdate'])
if airDate.year >= 1970 or showObj.network:
airDate = srDateTime(tz_updater.parse_date_time(curEp['airdate'], showObj.airs, showObj.network),
airDate = srDateTime(
sickrage.app.tz_updater.parse_date_time(curEp['airdate'], showObj.airs, showObj.network),
convert=True).dt
if curEpCat == Overview.WANTED and airDate < today:
......
......@@ -7,7 +7,6 @@
import sickrage
import sickrage.subtitles
from sickrage.core.updaters import tz_updater
from sickrage.core.common import SKIPPED, WANTED, UNAIRED, ARCHIVED, IGNORED, FAILED, DOWNLOADED
from sickrage.core.common import Quality, qualityPresets, statusStrings, Overview
from sickrage.core.helpers import anon_url, srdatetime, pretty_filesize, get_size
......@@ -162,7 +161,7 @@
% if show.network and show.airs:
<tr>
<td class="showLegend">${_('Originally Airs:')}</td>
<td>${show.airs} ${("<span style='color: red;'><b>(invalid Timeformat)</b></span> ", "")[tz_updater.test_timeformat(show.airs)]}
<td>${show.airs} ${("<span style='color: red;'><b>(invalid Timeformat)</b></span> ", "")[sickrage.app.tz_updater.test_timeformat(show.airs)]}
on ${show.network}</td>
</tr>
% elif show.network:
......@@ -173,7 +172,7 @@
% elif show.airs:
<tr>
<td class="showLegend">${_('Originally Airs:')}</td>
<td>${show.airs} ${("<span style='color: red;'><b>(invalid Timeformat)</b></span>", "")[tz_updater.test_timeformat(show.airs)]}</td>
<td>${show.airs} ${("<span style='color: red;'><b>(invalid Timeformat)</b></span>", "")[sickrage.app.tz_updater.test_timeformat(show.airs)]}</td>
</tr>
% endif
......@@ -640,7 +639,7 @@
<% airDate = datetime.datetime.fromordinal(epResult['airdate']) %>
% if airDate.year >= 1970 or show.network:
<% airDate = srdatetime.srDateTime(tz_updater.parse_date_time(epResult['airdate'], show.airs, show.network), convert=True).dt %>
<% airDate = srdatetime.srDateTime(sickrage.app.tz_updater.parse_date_time(epResult['airdate'], show.airs, show.network), convert=True).dt %>
% endif
<time datetime="${airDate.isoformat()}" class="date text-nowrap">
${srdatetime.srDateTime(airDate).srfdatetime()}
......
......@@ -6,7 +6,6 @@
import sickrage
from sickrage.core.helpers import srdatetime, pretty_filesize
from sickrage.core.updaters import tz_updater
from sickrage.core.media.util import showImage
%>
<%block name="metas">
......@@ -182,7 +181,7 @@
data_date = '6000000000.0'
if cur_airs_next:
data_date = calendar.timegm(srdatetime.srDateTime(tz_updater.parse_date_time(cur_airs_next, curShow.airs, curShow.network), convert=True).dt.timetuple())
data_date = calendar.timegm(srdatetime.srDateTime(sickrage.app.tz_updater.parse_date_time(cur_airs_next, curShow.airs, curShow.network), convert=True).dt.timetuple())
elif display_status:
if 'nded' not in display_status and 1 == int(curShow.paused):
data_date = '5000000500.0'
......@@ -223,7 +222,7 @@
<div class="show-date" style="color: grey">
% if cur_airs_next:
<% ldatetime = srdatetime.srDateTime(tz_updater.parse_date_time(cur_airs_next, curShow.airs, curShow.network), convert=True).dt %>
<% ldatetime = srdatetime.srDateTime(sickrage.app.tz_updater.parse_date_time(cur_airs_next, curShow.airs, curShow.network), convert=True).dt %>
<%
try:
out = srdatetime.srDateTime(ldatetime).srfdate()
......@@ -377,7 +376,7 @@
%>
<tr>
% if cur_airs_next:
<% airDate = srdatetime.srDateTime(tz_updater.parse_date_time(cur_airs_next, curShow.airs, curShow.network), convert=True).dt %>
<% airDate = srdatetime.srDateTime(sickrage.app.tz_updater.parse_date_time(cur_airs_next, curShow.airs, curShow.network), convert=True).dt %>
% try:
<td class="table-fit align-middle">
<time datetime="${airDate.isoformat()}"
......@@ -391,7 +390,7 @@
% endif
% if cur_airs_prev:
<% airDate = srdatetime.srDateTime(tz_updater.parse_date_time(cur_airs_prev, curShow.airs, curShow.network), convert=True).dt %>
<% airDate = srdatetime.srDateTime(sickrage.app.tz_updater.parse_date_time(cur_airs_prev, curShow.airs, curShow.network), convert=True).dt %>
% try:
<td class="table-fit align-middle">
<time datetime="${airDate.isoformat()}" class="date">
......
......@@ -8,7 +8,6 @@
from sickrage.core.common import SKIPPED, WANTED, UNAIRED, ARCHIVED, IGNORED, SNATCHED, SNATCHED_PROPER, SNATCHED_BEST, FAILED
from sickrage.core.common import Quality, qualityPresets, qualityPresetStrings
from sickrage.core.helpers import srdatetime
from sickrage.core.updaters import tz_updater
%>
<%block name="content">
<div class="row">
......
......@@ -6,7 +6,6 @@
import sickrage
from sickrage.core import API
from sickrage.core.updaters import tz_updater
from sickrage.core.helpers import pretty_filesize, memory_usage
%>
......
......@@ -6,7 +6,6 @@
from sickrage.core.common import SKIPPED, WANTED, UNAIRED, ARCHIVED, IGNORED, SNATCHED, SNATCHED_PROPER, SNATCHED_BEST, FAILED
from sickrage.core.common import Overview, Quality, qualityPresets, qualityPresetStrings
from sickrage.core.helpers import srdatetime
from sickrage.core.updaters import tz_updater
%>
<%block name="content">
<% totalWanted = totalQual = 0 %>
......@@ -91,7 +90,7 @@
${curResult["name"]}
</td>
<td>
<% airDate = srdatetime.srDateTime(tz_updater.parse_date_time(curResult['airdate'], curShow.airs, curShow.network), convert=True).dt %>
<% airDate = srdatetime.srDateTime(sickrage.app.tz_updater.parse_date_time(curResult['airdate'], curShow.airs, curShow.network), convert=True).dt %>
% if int(curResult['airdate']) != 1:
<time datetime="${airDate.isoformat()}"
class="date">${srdatetime.srDateTime(airDate).srfdatetime()}</time>
......
Supports Markdown
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