CLI: Add cachefile flag

pull/105/head
Filipe Santos 5 years ago committed by desimaniac
parent 80b7d54360
commit 5694839734

@ -1,4 +1,4 @@
FROM python:3.6-alpine3.7
FROM python:3.7-alpine3.10
# Arguments for build tracking
ARG BRANCH=
@ -9,6 +9,7 @@ ENV \
BRANCH=${BRANCH} \
COMMIT=${COMMIT} \
TRAKTARR_CONFIG=/config/config.json \
TRAKTARR_CACHEFILE=/config/cache.db \
TRAKTARR_LOGFILE=/config/traktarr.log
COPY . /${APP_DIR}

@ -8,9 +8,10 @@ from cashier import cache
from helpers.misc import backoff_handler, dict_merge
from helpers.trakt import extract_list_user_and_key_from_url
from misc.log import logger
from misc.config import Config
log = logger.get_logger(__name__)
cachefile = Config().cachefile
class Trakt:
non_user_lists = ['anticipated', 'trending', 'popular', 'boxoffice', 'watched', 'played']
@ -378,7 +379,7 @@ class Trakt:
object_name='show',
)
@cache(cache_file='cache.db', retry_if_blank=True)
@cache(cache_file=cachefile, retry_if_blank=True)
def get_trending_shows(self, limit=1000, languages=None, genres=None):
return self._make_items_request(
url='https://api.trakt.tv/shows/trending',
@ -389,7 +390,7 @@ class Trakt:
genres=genres
)
@cache(cache_file='cache.db', retry_if_blank=True)
@cache(cache_file=cachefile, retry_if_blank=True)
def get_popular_shows(self, limit=1000, languages=None, genres=None):
return self._make_items_request(
url='https://api.trakt.tv/shows/popular',
@ -400,7 +401,7 @@ class Trakt:
genres=genres
)
@cache(cache_file='cache.db', retry_if_blank=True)
@cache(cache_file=cachefile, retry_if_blank=True)
def get_anticipated_shows(self, limit=1000, languages=None, genres=None):
return self._make_items_request(
url='https://api.trakt.tv/shows/anticipated',
@ -411,7 +412,7 @@ class Trakt:
genres=genres
)
@cache(cache_file='cache.db', retry_if_blank=True)
@cache(cache_file=cachefile, retry_if_blank=True)
def get_person_shows(self, person, limit=1000, languages=None, genres=None):
return self._make_items_request(
url='https://api.trakt.tv/people/%s/shows' % person,
@ -422,7 +423,7 @@ class Trakt:
genres=genres
)
@cache(cache_file='cache.db', retry_if_blank=True)
@cache(cache_file=cachefile, retry_if_blank=True)
def get_most_played_shows(self, limit=1000, languages=None, genres=None, most_type=None):
return self._make_items_request(
url='https://api.trakt.tv/shows/played/%s' % ('weekly' if not most_type else most_type),
@ -433,7 +434,7 @@ class Trakt:
genres=genres
)
@cache(cache_file='cache.db', retry_if_blank=True)
@cache(cache_file=cachefile, retry_if_blank=True)
def get_most_watched_shows(self, limit=1000, languages=None, genres=None, most_type=None):
return self._make_items_request(
url='https://api.trakt.tv/shows/watched/%s' % ('weekly' if not most_type else most_type),
@ -444,7 +445,7 @@ class Trakt:
genres=genres
)
@cache(cache_file='cache.db', retry_if_blank=True)
@cache(cache_file=cachefile, retry_if_blank=True)
def get_recommended_shows(self, authenticate_user=None, limit=1000, languages=None, genres=None):
return self._make_items_request(
url='https://api.trakt.tv/recommendations/shows',
@ -490,7 +491,7 @@ class Trakt:
object_name='movie',
)
@cache(cache_file='cache.db', retry_if_blank=True)
@cache(cache_file=cachefile, retry_if_blank=True)
def get_trending_movies(self, limit=1000, languages=None, genres=None):
return self._make_items_request(
url='https://api.trakt.tv/movies/trending',
@ -501,7 +502,7 @@ class Trakt:
genres=genres
)
@cache(cache_file='cache.db', retry_if_blank=True)
@cache(cache_file=cachefile, retry_if_blank=True)
def get_popular_movies(self, limit=1000, languages=None, genres=None):
return self._make_items_request(
url='https://api.trakt.tv/movies/popular',
@ -512,7 +513,7 @@ class Trakt:
genres=genres
)
@cache(cache_file='cache.db', retry_if_blank=True)
@cache(cache_file=cachefile, retry_if_blank=True)
def get_anticipated_movies(self, limit=1000, languages=None, genres=None):
return self._make_items_request(
url='https://api.trakt.tv/movies/anticipated',
@ -523,7 +524,7 @@ class Trakt:
genres=genres
)
@cache(cache_file='cache.db', retry_if_blank=True)
@cache(cache_file=cachefile, retry_if_blank=True)
def get_person_movies(self, person, limit=1000, languages=None, genres=None):
return self._make_items_request(
url='https://api.trakt.tv/people/%s/movies' % person,
@ -534,7 +535,7 @@ class Trakt:
genres=genres
)
@cache(cache_file='cache.db', retry_if_blank=True)
@cache(cache_file=cachefile, retry_if_blank=True)
def get_most_played_movies(self, limit=1000, languages=None, genres=None, most_type=None):
return self._make_items_request(
url='https://api.trakt.tv/movies/played/%s' % ('weekly' if not most_type else most_type),
@ -545,7 +546,7 @@ class Trakt:
genres=genres
)
@cache(cache_file='cache.db', retry_if_blank=True)
@cache(cache_file=cachefile, retry_if_blank=True)
def get_most_watched_movies(self, limit=1000, languages=None, genres=None, most_type=None):
return self._make_items_request(
url='https://api.trakt.tv/movies/watched/%s' % ('weekly' if not most_type else most_type),

@ -104,11 +104,12 @@ class Config(object, metaclass=Singleton):
}
}
def __init__(self, config_path, logfile):
def __init__(self, configfile, cachefile, logfile):
"""Initializes config"""
self.conf = None
self.config_path = config_path
self.config_path = configfile
self.cache_path = cachefile
self.log_path = logfile
@property
@ -134,6 +135,10 @@ class Config(object, metaclass=Singleton):
return self.conf
@property
def cachefile(self):
return self.cache_path
@property
def logfile(self):
return self.log_path

@ -27,6 +27,14 @@ notify = None
show_default=True,
default=os.path.join(os.path.dirname(os.path.realpath(sys.argv[0])), "config.json")
)
@click.option(
'--cachefile',
envvar='TRAKTARR_CACHEFILE',
type=click.Path(file_okay=True, dir_okay=False),
help='Cache file',
show_default=True,
default=os.path.join(os.path.dirname(os.path.realpath(sys.argv[0])), "cache.db")
)
@click.option(
'--logfile',
envvar='TRAKTARR_LOGFILE',
@ -35,13 +43,13 @@ notify = None
show_default=True,
default=os.path.join(os.path.dirname(os.path.realpath(sys.argv[0])), "activity.log")
)
def app(config, logfile):
def app(config, cachefile, logfile):
# Setup global variables
global cfg, log, notify
# Load config
from misc.config import Config
cfg = Config(config_path=config, logfile=logfile).cfg
cfg = Config(configfile=config, cachefile=cachefile, logfile=logfile).cfg
# Load logger
from misc.log import logger

Loading…
Cancel
Save