Rewrote prowl-rss (minimalized)
This commit is contained in:
parent
1d263926ec
commit
a2dfffb53d
|
@ -6,57 +6,34 @@
|
|||
|
||||
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 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'
|
||||
|
||||
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):
|
||||
# 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" % 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))
|
||||
headers = {'User-Agent': "Prowlpy/%s" % "0.41"}
|
||||
|
||||
# Perform the request and get the response headers and content
|
||||
data = {
|
||||
'apikey': self.apikey,
|
||||
'application': application,
|
||||
'apikey': api,
|
||||
'application': app,
|
||||
'event': event,
|
||||
'description': description,
|
||||
'description': desc,
|
||||
'priority': priority
|
||||
}
|
||||
headers["Content-type"] = "application/x-www-form-urlencoded"
|
||||
|
@ -69,43 +46,24 @@ class Prowl(object):
|
|||
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 time
|
||||
import sys
|
||||
import os
|
||||
|
||||
GUID_FILE = os.path.expanduser("~") + "/.prowl-rss"
|
||||
###
|
||||
|
||||
try:
|
||||
|
||||
guids = [line.strip() for line in open(GUID_FILE)]
|
||||
except IOError:
|
||||
print("{0} file couldn't be found/opened".format(GUID_FILE))
|
||||
sys.exit(1)
|
||||
conf = [line.strip() for line in open(CONF_FILE)]
|
||||
|
||||
p = Prowl(apikey)
|
||||
apikey = conf[0]
|
||||
feeds = conf[1:]
|
||||
|
||||
try:
|
||||
##
|
||||
fo = open(GUID_FILE, "a")
|
||||
for feed in feeds:
|
||||
xml = feedparser.parse(feed)
|
||||
|
||||
for e in xml.entries:
|
||||
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")
|
||||
|
||||
|
@ -117,7 +75,8 @@ try:
|
|||
|
||||
fo.close()
|
||||
|
||||
except IOError, e:
|
||||
print("{0} file couldn't be found/opened".format(e.filename))
|
||||
sys.exit(1)
|
||||
except Exception, msg:
|
||||
print(msg)
|
||||
|
||||
|
||||
|
|
Loading…
Reference in a new issue