From d75c278a4874b32e3777806324adfc1240e3b95e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Louis=20V=C3=A9zina?= <5130500+morpheus65535@users.noreply.github.com> Date: Tue, 20 Aug 2019 15:07:33 -0400 Subject: [PATCH] Continuing development. --- bazarr/utils.py | 53 ++++++++++++++++++++++++------------------------- 1 file changed, 26 insertions(+), 27 deletions(-) diff --git a/bazarr/utils.py b/bazarr/utils.py index b9721921c..5362d13a0 100644 --- a/bazarr/utils.py +++ b/bazarr/utils.py @@ -1,7 +1,6 @@ # coding=utf-8 import os -import sqlite3 import time import platform import sys @@ -9,6 +8,7 @@ import logging from whichcraft import which from get_args import args +from database import TableHistory, TableHistoryMovie from subliminal import region as subliminal_cache_region import datetime @@ -17,36 +17,35 @@ import glob def history_log(action, sonarrSeriesId, sonarrEpisodeId, description, video_path=None, language=None, provider=None, score=None, forced=False): - # Open database connection - db = sqlite3.connect(os.path.join(args.config_dir, 'db', 'bazarr.db'), timeout=30) - c = db.cursor() - - history = c.execute( - '''INSERT INTO table_history(action, sonarrSeriesId, sonarrEpisodeId, timestamp, description, video_path, language, provider, score) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?)''', - (action, sonarrSeriesId, sonarrEpisodeId, time.time(), description, video_path, language, provider, score)) - - # Commit changes to DB - db.commit() - - # Close database connection - db.close() + TableHistory.insert( + { + TableHistory.action: action, + TableHistory.sonarr_series_id: sonarrSeriesId, + TableHistory.sonarr_episode_id: sonarrEpisodeId, + TableHistory.timestamp: time.time(), + TableHistory.description: description, + TableHistory.video_path: video_path, + TableHistory.language: language, + TableHistory.provider: provider, + TableHistory.score: score + } + ).execute() def history_log_movie(action, radarrId, description, video_path=None, language=None, provider=None, score=None, forced=False): - # Open database connection - db = sqlite3.connect(os.path.join(args.config_dir, 'db', 'bazarr.db'), timeout=30) - c = db.cursor() - - history = c.execute( - '''INSERT INTO table_history_movie(action, radarrId, timestamp, description, video_path, language, provider, score) VALUES (?, ?, ?, ?, ?, ?, ?, ?)''', - (action, radarrId, time.time(), description, video_path, language, provider, score)) - - # Commit changes to DB - db.commit() - - # Close database connection - db.close() + TableHistoryMovie.insert( + { + TableHistoryMovie.action: action, + TableHistoryMovie.radarr_id: radarrId, + TableHistoryMovie.timestamp: time.time(), + TableHistoryMovie.description: description, + TableHistoryMovie.video_path: video_path, + TableHistoryMovie.language: language, + TableHistoryMovie.provider: provider, + TableHistoryMovie.score: score + } + ).execute() def get_binary(name):