This repository has been archived by the owner on Dec 27, 2023. It is now read-only.
forked from infincia/AEServmon
-
Notifications
You must be signed in to change notification settings - Fork 1
/
prowlpy.py
executable file
·62 lines (49 loc) · 1.83 KB
/
prowlpy.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
# -*- coding: utf-8 -*-
"""
Prowlpy V0.4.1
Written by Jacob Burch, 7/6/2009
Python module for posting to the iPhone Push Notification service Prowl: http://prowl.weks.net/
"""
__author__ = '[email protected]'
__version__ = 0.41
import httplib2
import urllib
API_DOMAIN = 'https://prowl.weks.net/publicapi'
class Prowl(object):
def __init__(self, apikey):
"""
Initialize a Prowl instance.
"""
self.apikey = apikey
# Aliasing
self.add = self.post
def post(self, application=None, event=None, description=None,priority=0):
# Create the http object
h = httplib2.Http()
# Set User-Agent
headers = {'User-Agent': "Prowlpy/%s" % str(__version__)}
# Perform the request and get the response headers and content
data = {
'apikey': self.apikey,
'application': application,
'event': event,
'description': description,
'priority': priority
}
headers["Content-type"] = "application/x-www-form-urlencoded"
resp,content = h.request("%s/add/" % API_DOMAIN, "POST", headers=headers, body=urllib.urlencode(data))
if resp['status'] == '200':
return True
elif resp['status'] == '401':
raise Exception("Auth Failed: %s" % content)
else:
raise Exception("Failed")
def verify_key(self):
h = httplib2.Http()
headers = {'User-Agent': "Prowlpy/%s" % str(__version__)}
verify_resp,verify_content = h.request("%s/verify?apikey=%s" % \
(API_DOMAIN,self.apikey))
if verify_resp['status'] != '200':
raise Exception("Invalid API Key %s" % verify_content)
else:
return True