Add scrobble log option and CLI tool

This commit is contained in:
2023-01-05 13:39:56 -05:00
parent 68c1b3c6f0
commit 41a74f46c8
6 changed files with 100 additions and 10 deletions

34
vrobbler/cli.py Normal file
View File

@ -0,0 +1,34 @@
# cli.py
import logging
import sys
from os import environ as env
if not 'DJANGO_SETTINGS_MODULE' in env:
from vrobbler import settings
env.setdefault('DJANGO_SETTINGS_MODULE', settings.__name__)
import django
django.setup()
# this line must be after django.setup() for logging configure
logger = logging.getLogger('vrobbler')
def main():
# to get configured settings
from django.conf import settings
try:
from django.core.management import execute_from_command_line
except ImportError as exc:
raise ImportError(
"Couldn't import Django. Are you sure it's installed and "
"available on your PYTHONPATH environment variable? Did you "
"forget to activate a virtual environment?"
) from exc
execute_from_command_line(sys.argv)
if __name__ == '__main__':
main()

View File

@ -32,6 +32,12 @@ DEBUG = os.getenv("VROBBLER_DEBUG", False)
TESTING = len(sys.argv) > 1 and sys.argv[1] == "test"
KEEP_DETAILED_SCROBBLE_LOGS = os.getenv(
"VROBBLER_KEEP_DETAILED_SCROBBLE_LOGS", False
)
DELETE_STALE_SCROBBLES = os.getenv("VROBBLER_DELETE_STALE_SCROBBLES", True)
TMDB_API_KEY = os.getenv("VROBBLER_TMDB_API_KEY", "")
DEFAULT_AUTO_FIELD = 'django.db.models.BigAutoField'
@ -61,7 +67,6 @@ INSTALLED_APPS = [
"django_filters",
"django_extensions",
'rest_framework.authtoken',
"vrobbler",
"scrobbles",
"videos",
"rest_framework",