Rewrote prowl-rss (minimalized)
This commit is contained in:
parent
1d263926ec
commit
a2dfffb53d
125
bin/prowl-rss
125
bin/prowl-rss
|
@ -6,106 +6,64 @@
|
||||||
|
|
||||||
from __future__ import print_function
|
from __future__ import print_function
|
||||||
|
|
||||||
apikey = "... API KEY HERE ..."
|
|
||||||
feeds = [
|
|
||||||
# Put your feeds here
|
|
||||||
]
|
|
||||||
|
|
||||||
"""
|
|
||||||
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__ = 'jacobburch@gmail.com'
|
|
||||||
__version__ = 0.41
|
|
||||||
|
|
||||||
import httplib2
|
import httplib2
|
||||||
import urllib
|
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__)}
|
|
||||||
|
|
||||||
# URL-encode and string-ify keywords. Better type/content testing is needed here
|
|
||||||
# url.encode below fixes need for url quotes
|
|
||||||
# string-ify-ing might still be required. haven't tested that
|
|
||||||
#application = urllib.quote(str(application))
|
|
||||||
#event = urllib.quote(str(event))
|
|
||||||
#description = urllib.quote(str(description))
|
|
||||||
#priority = urllib.quote(str(priority))
|
|
||||||
|
|
||||||
# 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
|
|
||||||
|
|
||||||
|
|
||||||
#########################################################################
|
|
||||||
|
|
||||||
import feedparser
|
import feedparser
|
||||||
import time
|
import time
|
||||||
import sys
|
import sys
|
||||||
import os
|
import os
|
||||||
|
|
||||||
|
###
|
||||||
|
|
||||||
GUID_FILE = os.path.expanduser("~") + "/.prowl-rss"
|
GUID_FILE = os.path.expanduser("~") + "/.prowl-rss"
|
||||||
|
CONF_FILE = os.path.expanduser("~") + "/.prowl-rss-conf"
|
||||||
|
|
||||||
|
API_DOMAIN = 'https://prowl.weks.net/publicapi'
|
||||||
|
|
||||||
|
# Pulled out of prowlpy @ https://github.com/omgmovieslol/prowlpy/tree/master
|
||||||
|
def prowl_post(api, app=None, event=None, desc=None, priority=0):
|
||||||
|
# Create the http object
|
||||||
|
h = httplib2.Http()
|
||||||
|
|
||||||
|
# Set User-Agent
|
||||||
|
headers = {'User-Agent': "Prowlpy/%s" % "0.41"}
|
||||||
|
|
||||||
|
# Perform the request and get the response headers and content
|
||||||
|
data = {
|
||||||
|
'apikey': api,
|
||||||
|
'application': app,
|
||||||
|
'event': event,
|
||||||
|
'description': desc,
|
||||||
|
'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")
|
||||||
|
|
||||||
|
###
|
||||||
|
|
||||||
try:
|
try:
|
||||||
|
|
||||||
guids = [line.strip() for line in open(GUID_FILE)]
|
guids = [line.strip() for line in open(GUID_FILE)]
|
||||||
except IOError:
|
conf = [line.strip() for line in open(CONF_FILE)]
|
||||||
print("{0} file couldn't be found/opened".format(GUID_FILE))
|
|
||||||
sys.exit(1)
|
|
||||||
|
|
||||||
p = Prowl(apikey)
|
apikey = conf[0]
|
||||||
|
feeds = conf[1:]
|
||||||
|
|
||||||
try:
|
##
|
||||||
fo = open(GUID_FILE, "a")
|
fo = open(GUID_FILE, "a")
|
||||||
for feed in feeds:
|
for feed in feeds:
|
||||||
xml = feedparser.parse(feed)
|
xml = feedparser.parse(feed)
|
||||||
|
|
||||||
for e in xml.entries:
|
for e in xml.entries:
|
||||||
if e.guid not in guids:
|
if e.guid not in guids:
|
||||||
p.add("RSS", e.title, "{0} - {1} <{2}>".format(e.title, xml.feed.title, e.link))
|
prowl_post(apikey, "RSS", e.title, "{0} - {1} <{2}>".format(e.title, xml.feed.title, e.link))
|
||||||
|
|
||||||
fo.write(e.guid+"\n")
|
fo.write(e.guid+"\n")
|
||||||
|
|
||||||
|
@ -117,7 +75,8 @@ try:
|
||||||
|
|
||||||
fo.close()
|
fo.close()
|
||||||
|
|
||||||
|
except IOError, e:
|
||||||
|
print("{0} file couldn't be found/opened".format(e.filename))
|
||||||
|
sys.exit(1)
|
||||||
except Exception, msg:
|
except Exception, msg:
|
||||||
print(msg)
|
print(msg)
|
||||||
|
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue