Commit ca8aaefd authored by echel0n's avatar echel0n
Browse files

fixed issue with network timezones and search provider urls not being updated on first use of app

fixed issue with search provider newnab migration
parent 5b76026c
......@@ -6,7 +6,6 @@ Create Date: 2017-12-29 14:39:27.854291
"""
from alembic import op
import sqlalchemy as sa
# revision identifiers, used by Alembic.
revision = '3'
......@@ -14,15 +13,6 @@ down_revision = '2'
def upgrade():
conn = op.get_bind()
meta = sa.MetaData(bind=conn)
search_providers_newznab = sa.Table('search_providers_newznab', meta, autoload=True)
with op.get_context().begin_transaction():
for row in conn.execute(search_providers_newznab.select()):
if row.key:
conn.execute(f'UPDATE search_providers_newznab SET api_key = "{row.key}" WHERE search_providers_newznab.id = {row.id}')
with op.batch_alter_table('search_providers_newznab') as batch_op:
batch_op.drop_column('key')
......
......@@ -23,6 +23,7 @@ import re
from dateutil import tz
from sqlalchemy import orm
from tornado.ioloop import IOLoop
import sickrage
from sickrage.core.databases.cache import CacheDB
......@@ -57,6 +58,17 @@ class TimeZoneUpdater(object):
def update_network_timezones(self):
"""Update timezone information from SR repositories"""
if not sickrage.app.api.token:
IOLoop.current().call_later(5, self.update_network_timezones)
return
if sickrage.app.api.token_time_remaining < (int(sickrage.app.api.token['expires_in']) / 2):
if not sickrage.app.api.refresh_token():
IOLoop.current().call_later(5, self.update_network_timezones)
return
sickrage.app.log.debug('Updating network timezones')
session = sickrage.app.cache_db.session()
resp = sickrage.app.api.network_timezones()
......@@ -97,6 +109,8 @@ class TimeZoneUpdater(object):
# cleanup
del network_timezones
sickrage.app.log.debug('Updating network timezones finished')
def get_network_timezone(self, network):
"""
Get a timezone of a network from a given network dict
......
......@@ -30,7 +30,6 @@ import os
import pkgutil
import random
import re
import threading
from base64 import b16encode, b32decode
from collections import OrderedDict, defaultdict
from time import sleep
......@@ -40,16 +39,16 @@ from xml.sax import SAXParseException
from bencode3 import bdecode, bencode
from feedparser import FeedParserDict
from requests.utils import add_dict_to_cookiejar, dict_from_cookiejar
from tornado.ioloop import IOLoop
import sickrage
from sickrage.core.caches.tv_cache import TVCache
from sickrage.core.common import MULTI_EP_RESULT, SEASON_RESULT
from sickrage.core.enums import SearchFormat, CpuPreset
from sickrage.core.helpers import chmod_as_parent, sanitize_file_name, clean_url, bs4_parser, \
validate_url, try_int, convert_size
from sickrage.core.common import Quality, Qualities
from sickrage.core.enums import SearchFormat
from sickrage.core.helpers import chmod_as_parent, sanitize_file_name, clean_url, bs4_parser, validate_url, try_int, convert_size
from sickrage.core.helpers.show_names import all_possible_show_names
from sickrage.core.nameparser import InvalidNameException, InvalidShowException, NameParser
from sickrage.core.common import Quality, Qualities
from sickrage.core.tv.show.helpers import find_show
from sickrage.core.websession import WebSession
......@@ -1493,6 +1492,15 @@ class SearchProviders(dict):
provider._urls = json.loads(provider_urls)
def update_urls(self):
if not sickrage.app.api.token:
IOLoop.current().call_later(5, self.update_urls)
return
if sickrage.app.api.token_time_remaining < (int(sickrage.app.api.token['expires_in']) / 2):
if not sickrage.app.api.refresh_token():
IOLoop.current().call_later(5, self.update_urls)
return
sickrage.app.log.debug('Updating search provider URLs')
for pID, pObj in self.all().items():
......
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