-
Notifications
You must be signed in to change notification settings - Fork 209
/
notifier.py
127 lines (93 loc) · 3.23 KB
/
notifier.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
# coding=utf-8
from __future__ import absolute_import
import apprise
import os
import logging
from get_args import args
from database import TableSettingsNotifier, TableShows, TableEpisodes, TableMovies
def update_notifier():
# define apprise object
a = apprise.Apprise()
# Retrieve all of the details
results = a.details()
notifiers_new = []
notifiers_old = []
notifiers_current_db = TableSettingsNotifier.select(
TableSettingsNotifier.name
)
notifiers_current = []
for notifier in notifiers_current_db:
notifiers_current.append(notifier.name)
for x in results['schemas']:
if x['service_name'] not in notifiers_current:
notifiers_new.append(x['service_name'])
logging.debug('Adding new notifier agent: ' + x['service_name'])
else:
notifiers_old.append(x['service_name'])
notifier_current = [i for i in notifiers_current]
notifiers_to_delete = list(set(notifier_current) - set(notifiers_old))
for notifier_new in notifiers_new:
TableSettingsNotifier.insert(
{
TableSettingsNotifier.name: notifier_new,
TableSettingsNotifier.enabled: 0
}
).execute()
for notifier_to_delete in notifiers_to_delete:
TableSettingsNotifier.delete().where(
TableSettingsNotifier.name == notifier_to_delete
).execute()
def get_notifier_providers():
providers = TableSettingsNotifier.select(
TableSettingsNotifier.name,
TableSettingsNotifier.url
).where(
TableSettingsNotifier.enabled == 1
)
return providers
def get_series_name(sonarrSeriesId):
data = TableShows.select(
TableShows.title
).where(
TableShows.sonarr_series_id == sonarrSeriesId
).first()
return data.title
def get_episode_name(sonarrEpisodeId):
data = TableEpisodes.select(
TableEpisodes.title,
TableEpisodes.season,
TableEpisodes.episode
).where(
TableEpisodes.sonarr_episode_id == sonarrEpisodeId
).first()
return data.title, data.season, data.episode
def get_movies_name(radarrId):
data = TableMovies.select(
TableMovies.title
).where(
TableMovies.radarr_id == radarrId
).first()
return data.title
def send_notifications(sonarrSeriesId, sonarrEpisodeId, message):
providers = get_notifier_providers()
series = get_series_name(sonarrSeriesId)
episode = get_episode_name(sonarrEpisodeId)
apobj = apprise.Apprise()
for provider in providers:
if provider.url is not None:
apobj.add(provider.url)
apobj.notify(
title='Bazarr notification',
body=(series + ' - S' + str(episode[1]).zfill(2) + 'E' + str(episode[2]).zfill(2) + ' - ' + episode[0] + ' : ' + message),
)
def send_notifications_movie(radarrId, message):
providers = get_notifier_providers()
movie = get_movies_name(radarrId)
apobj = apprise.Apprise()
for provider in providers:
if provider.url is not None:
apobj.add(provider.url)
apobj.notify(
title='Bazarr notification',
body=movie + ' : ' + message,
)