Adding scheduler

pull/26/head
Louis Vézina 7 years ago
parent f479676b08
commit 5bc8cd9070

@ -11,6 +11,8 @@ import itertools
import operator
import requests
import pycountry
import pretty
import datetime
from PIL import Image
from io import BytesIO
from fdsend import send_file
@ -27,6 +29,7 @@ from get_sonarr_settings import *
from list_subtitles import *
from get_subtitle import *
from utils import *
from scheduler import *
import logging
from logging.handlers import TimedRotatingFileHandler
@ -223,16 +226,7 @@ def wanted():
def wanted_search_missing_subtitles():
ref = request.environ['HTTP_REFERER']
db = sqlite3.connect(os.path.join(os.path.dirname(__file__), 'data/db/bazarr.db'))
db.create_function("path_substitution", 1, path_replace)
c = db.cursor()
c.execute("SELECT path_substitution(path) FROM table_episodes WHERE table_episodes.missing_subtitles != '[]'")
data = c.fetchall()
c.close()
for episode in data:
wanted_download_subtitles(episode[0])
wanted_search_missing_subtitles()
redirect(ref)
@ -304,8 +298,12 @@ def system():
logs = []
for line in reversed(open(os.path.join(os.path.dirname(__file__), 'data/log/bazarr.log')).readlines()):
logs.append(line.rstrip())
task_list = []
for job in scheduler.get_jobs():
task_list.append([job.name, job.trigger.interval.__str__(), pretty.date(job.next_run_time.replace(tzinfo=None))])
return template('system', tasks=tasks, logs=logs, base_url=base_url)
return template('system', tasks=tasks, logs=logs, base_url=base_url, task_list=task_list)
@route(base_url + '/remove_subtitles', method='POST')
def remove_subtitles():

@ -65,3 +65,14 @@ def wanted_download_subtitles(path):
list_missing_subtitles(episode[3])
history_log(1, episode[3], episode[2], message)
def wanted_search_missing_subtitles():
db = sqlite3.connect(os.path.join(os.path.dirname(__file__), 'data/db/bazarr.db'))
db.create_function("path_substitution", 1, path_replace)
c = db.cursor()
c.execute("SELECT path_substitution(path) FROM table_episodes WHERE table_episodes.missing_subtitles != '[]'")
data = c.fetchall()
c.close()
for episode in data:
wanted_download_subtitles(episode[0])

@ -1,3 +1,4 @@
apscheduler
babelfish
bottle
bottle-fdsend

@ -1,12 +1,11 @@
import datetime, threading, time
from get_series import *
from get_episodes import *
from get_subtitle import *
def foo():
next_call = time.time()
while True:
print datetime.datetime.now()
next_call = next_call+1;
time.sleep(next_call - time.time())
from apscheduler.schedulers.background import BackgroundScheduler
timerThread = threading.Thread(target=foo)
timerThread.daemon = True
timerThread.start()
scheduler = BackgroundScheduler()
scheduler.add_job(update_series, 'interval', minutes=1, id='update_series', name='Update series list from Sonarr')
scheduler.add_job(add_new_episodes, 'interval', minutes=1, id='add_new_episodes', name='Add new episodes from Sonarr')
scheduler.add_job(wanted_search_missing_subtitles, 'interval', minutes=15, id='wanted_search_missing_subtitles', name='Search for wanted subtitles')
scheduler.start()

@ -78,7 +78,26 @@
<a class="item" data-tab="about">About</a>
</div>
<div class="ui bottom attached tab segment active" data-tab="tasks">
Tasks
<div class="content">
<table class="ui very basic selectable table">
<thead>
<tr>
<th>Name</th>
<th>Interval</th>
<th>Next Execution</th>
</tr>
</thead>
<tbody>
%for task in task_list:
<tr>
<td>{{task[0]}}</td>
<td>{{task[1]}}</td>
<td>{{task[2]}}</td>
</tr>
%end
</tbody>
</table>
</div>
</div>
<div class="ui bottom attached tab segment" data-tab="logs">
<div class="content">

Loading…
Cancel
Save