mirror of
https://github.com/ansible-collections/community.general.git
synced 2026-02-04 07:51:50 +00:00
Reformat everything.
This commit is contained in:
parent
3f2213791a
commit
340ff8586d
1008 changed files with 61301 additions and 58309 deletions
|
|
@ -93,8 +93,9 @@ from ansible.module_utils.urls import fetch_url
|
|||
|
||||
|
||||
class Pushover:
|
||||
''' Instantiates a pushover object, use it to send notifications '''
|
||||
base_uri = 'https://api.pushover.net'
|
||||
"""Instantiates a pushover object, use it to send notifications"""
|
||||
|
||||
base_uri = "https://api.pushover.net"
|
||||
|
||||
def __init__(self, module, user, token):
|
||||
self.module = module
|
||||
|
|
@ -102,55 +103,51 @@ class Pushover:
|
|||
self.token = token
|
||||
|
||||
def run(self, priority, msg, title, device):
|
||||
''' Do, whatever it is, we do. '''
|
||||
"""Do, whatever it is, we do."""
|
||||
|
||||
url = f'{self.base_uri}/1/messages.json'
|
||||
url = f"{self.base_uri}/1/messages.json"
|
||||
|
||||
# parse config
|
||||
options = dict(user=self.user,
|
||||
token=self.token,
|
||||
priority=priority,
|
||||
message=msg)
|
||||
options = dict(user=self.user, token=self.token, priority=priority, message=msg)
|
||||
|
||||
if title is not None:
|
||||
options = dict(options,
|
||||
title=title)
|
||||
options = dict(options, title=title)
|
||||
|
||||
if device is not None:
|
||||
options = dict(options,
|
||||
device=device)
|
||||
options = dict(options, device=device)
|
||||
|
||||
data = urlencode(options)
|
||||
|
||||
headers = {"Content-type": "application/x-www-form-urlencoded"}
|
||||
r, info = fetch_url(self.module, url, method='POST', data=data, headers=headers)
|
||||
if info['status'] != 200:
|
||||
r, info = fetch_url(self.module, url, method="POST", data=data, headers=headers)
|
||||
if info["status"] != 200:
|
||||
raise Exception(info)
|
||||
|
||||
return r.read()
|
||||
|
||||
|
||||
def main():
|
||||
|
||||
module = AnsibleModule(
|
||||
argument_spec=dict(
|
||||
title=dict(type='str'),
|
||||
title=dict(type="str"),
|
||||
msg=dict(required=True),
|
||||
app_token=dict(required=True, no_log=True),
|
||||
user_key=dict(required=True, no_log=True),
|
||||
pri=dict(default='0', choices=['-2', '-1', '0', '1', '2']),
|
||||
device=dict(type='str'),
|
||||
pri=dict(default="0", choices=["-2", "-1", "0", "1", "2"]),
|
||||
device=dict(type="str"),
|
||||
),
|
||||
)
|
||||
|
||||
msg_object = Pushover(module, module.params['user_key'], module.params['app_token'])
|
||||
msg_object = Pushover(module, module.params["user_key"], module.params["app_token"])
|
||||
try:
|
||||
response = msg_object.run(module.params['pri'], module.params['msg'], module.params['title'], module.params['device'])
|
||||
response = msg_object.run(
|
||||
module.params["pri"], module.params["msg"], module.params["title"], module.params["device"]
|
||||
)
|
||||
except Exception:
|
||||
module.fail_json(msg='Unable to send msg via pushover')
|
||||
module.fail_json(msg="Unable to send msg via pushover")
|
||||
|
||||
module.exit_json(msg=f'message sent successfully: {response}', changed=False)
|
||||
module.exit_json(msg=f"message sent successfully: {response}", changed=False)
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
if __name__ == "__main__":
|
||||
main()
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue