Rewrote prowl-rss (minimalized)

This commit is contained in:
Henrik Lissner 2013-12-17 01:45:04 -05:00
parent 1d263926ec
commit a2dfffb53d

View file

@ -6,57 +6,34 @@
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
import feedparser
import time
import sys
import os
###
GUID_FILE = os.path.expanduser("~") + "/.prowl-rss"
CONF_FILE = os.path.expanduser("~") + "/.prowl-rss-conf"
API_DOMAIN = 'https://prowl.weks.net/publicapi' API_DOMAIN = 'https://prowl.weks.net/publicapi'
class Prowl(object): # Pulled out of prowlpy @ https://github.com/omgmovieslol/prowlpy/tree/master
def __init__(self, apikey): def prowl_post(api, app=None, event=None, desc=None, priority=0):
"""
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 # Create the http object
h = httplib2.Http() h = httplib2.Http()
# Set User-Agent # Set User-Agent
headers = {'User-Agent': "Prowlpy/%s" % str(__version__)} headers = {'User-Agent': "Prowlpy/%s" % "0.41"}
# 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 # Perform the request and get the response headers and content
data = { data = {
'apikey': self.apikey, 'apikey': api,
'application': application, 'application': app,
'event': event, 'event': event,
'description': description, 'description': desc,
'priority': priority 'priority': priority
} }
headers["Content-type"] = "application/x-www-form-urlencoded" headers["Content-type"] = "application/x-www-form-urlencoded"
@ -69,43 +46,24 @@ class Prowl(object):
else: else:
raise Exception("Failed") 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 time
import sys
import os
GUID_FILE = os.path.expanduser("~") + "/.prowl-rss"
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)