-
Notifications
You must be signed in to change notification settings - Fork 0
/
sms_free_fr.py
77 lines (57 loc) · 2.16 KB
/
sms_free_fr.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
# from __future__ import unicode_literals, division, absolute_import
# from builtins import * # noqa pylint: disable=unused-import, redefined-builtin
from loguru import logger
from flexget import plugin
from flexget.event import event
from flexget.plugin import PluginWarning
from flexget.utils.requests import Session as RequestSession, TimedLimiter
from requests.exceptions import RequestException
plugin_name = 'sms_free_fr'
logger = logger.bind(name=plugin_name)
SMS_SEND_URL = 'https://smsapi.free-mobile.fr/sendmsg'
requests = RequestSession(max_retries=3)
requests.add_domain_limiter(TimedLimiter('smsapi.free-mobile.fr', '5 seconds'))
class SMSFreeFrNotifier(object):
"""
Sends SMS notification through smsapi.free-mobile.fr
Informations:
https://www.freenews.fr/freenews-edition-nationale-299/free-mobile-170/nouvelle-option-notifications-par-sms-chez-free-mobile-14817
Example:
sms_free_fr:
user: your login (accepted format example: '12345678')
password: <PASSWORD>
Full example:
notify:
entries:
via:
- sms_free_fr:
user: '{? free_sms.user ?}'
password: '{? free_sms.password ?}'
"""
schema = {
'type': 'object',
'properties': {
'user': {"oneOf": [{"type": "string"}, {"type": "integer"}]},
'password': {'type': 'string'}
},
'additionalProperties': False,
'required': ['user', 'password']
}
def notify(self, title, message, config):
"""
Send an SMS via mobile free.fr notification
"""
# Build request params
notification = {'user': config['user'],
'pass': config['password'],
'msg': message}
try:
response = requests.get(SMS_SEND_URL, params=notification)
except RequestException as e:
raise PluginWarning(e.args[0])
else:
if not response.status_code == 200:
raise PluginWarning(response.text)
@event('plugin.register')
def register_plugin():
plugin.register(SMSFreeFrNotifier, plugin_name, api_ver=2, interfaces=['notifiers'])