Skip to content

Commit

Permalink
- Added an RSS adapter
Browse files Browse the repository at this point in the history
  • Loading branch information
mattweber committed Feb 12, 2010
1 parent e1a3897 commit 70b7183
Show file tree
Hide file tree
Showing 9 changed files with 2,968 additions and 0 deletions.
2,858 changes: 2,858 additions & 0 deletions ui/pypesvds/lib/extras/feedparser.py

Large diffs are not rendered by default.

10 changes: 10 additions & 0 deletions ui/pypesvds/plugins/RSSAdapter.egg-info/PKG-INFO
@@ -0,0 +1,10 @@
Metadata-Version: 1.0
Name: rssadapter
Version: 1.0
Summary: UNKNOWN
Home-page: UNKNOWN
Author: UNKNOWN
Author-email: UNKNOWN
License: UNKNOWN
Description: UNKNOWN
Platform: UNKNOWN
8 changes: 8 additions & 0 deletions ui/pypesvds/plugins/RSSAdapter.egg-info/SOURCES.txt
@@ -0,0 +1,8 @@
setup.py
rssadapter/rssadapter.py
rssadapter/__init__.py
RSSAdapter.egg-info/PKG-INFO
RSSAdapter.egg-info/SOURCES.txt
RSSAdapter.egg-info/dependency_links.txt
RSSAdapter.egg-info/entry_points.txt
RSSAdapter.egg-info/top_level.txt
@@ -0,0 +1 @@

3 changes: 3 additions & 0 deletions ui/pypesvds/plugins/RSSAdapter.egg-info/entry_points.txt
@@ -0,0 +1,3 @@
[pypesvds.plugins]
rssadapter = rssadapter.rssadapter:RSS

1 change: 1 addition & 0 deletions ui/pypesvds/plugins/RSSAdapter.egg-info/paster_plugins.txt
@@ -0,0 +1 @@
studio_plugin
1 change: 1 addition & 0 deletions ui/pypesvds/plugins/RSSAdapter.egg-info/top_level.txt
@@ -0,0 +1 @@
rssadapter
Empty file.
86 changes: 86 additions & 0 deletions ui/pypesvds/plugins/rssadapter/rssadapter.py
@@ -0,0 +1,86 @@
import logging
#import traceback

from pypes.component import Component
from pypesvds.lib.extras import feedparser

log = logging.getLogger(__name__)

class RSS(Component):
__metatype__ = 'ADAPTER'

def __init__(self):
# initialize parent class
Component.__init__(self)
log.info('Component Initialized: %s' % self.__class__.__name__)

def run(self):
# Define our components entry point
while True:

# for each document waiting on our input port
for doc in self.receive_all('in'):
try:
data = doc.get('data')
mime = doc.get('mimetype')

# if there is no data, move on to the next doc
if data is None:
continue

# if this is not a xml file, move on to the next doc
if mime != 'application/xml':
continue

# adapters should delete the data
doc.delete('data')

parsedfeed = feedparser.parse(data)
feeditems = ['author', 'language', 'link', 'publisher',
'title', 'subtitle', 'updated', 'description']
itemitems = ['author', 'summary', 'link', 'id', 'title',
'updated', 'published']

# set feed attributes as metadata
for fitem in feeditems:
try:
fval = parsedfeed.feed[fitem]
if isinstance(fval, (str, unicode)):
doc.set_meta('feed_%s' % fitem, fval)
else:
log.debug('Feed attribute %s is not a string' \
', skipping' % fval)
except:
log.debug('Feed attribute %s does not exist' % \
fitem)

# loop though each item (story) in the rss and send it
# as a separate packet. Set any attributes as
# attributes on the packet.
for item in parsedfeed.entries:
cloned = doc.clone(metas=True)
for iitem in itemitems:
try:
ival = item[iitem]
if isinstance(ival, (str, unicode)):
if iitem == 'link':
iitem = 'url'

cloned.set(iitem, ival)
else:
log.info('Item attribute %s is not a ' \
'string, skipping' % iitem)
except:
log.debug('Item attribute %s does not exist' \
% iitem)

self.send('out', cloned)

except Exception as e:
log.error('Component Failed: %s' % self.__class__.__name__)
log.error('Reason: %s' % str(e))
#log.error(traceback.print_exc())

# yield the CPU, allowing another component to run
self.yield_ctrl()

0 comments on commit 70b7183

Please sign in to comment.