Created
November 4, 2011 21:42
-
-
Save freddyb/1340561 to your computer and use it in GitHub Desktop.
grep for keywords in rss files
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import feedparser | |
| import datetime | |
| def main(urls, keywords): | |
| keywords = map(lambda x: x.lower(), keywords) | |
| for url in urls: | |
| print "Starting to parse", url | |
| feed = feedparser.parse(url) | |
| for item in feed['items']: | |
| title_text = item['title_detail']['value'] | |
| link = item['link'] | |
| struct_time = item['updated_parsed'] | |
| dtime = item['updated'] | |
| summary = item['summary'] | |
| for w in keywords: | |
| if w in str(item).lower(): | |
| print '%s:\n "%s" <%s> ' % (dtime, title_text, link) | |
| print summary | |
| print "-"*50 | |
| print "Finished parsing", url | |
| print 'Done' | |
| if __name__ == '__main__': | |
| ''' | |
| TODO | |
| maybe import argparse and ask for keywords and urls on commandline | |
| ''' | |
| urls = ['http://zone-h.org/rss/defacements', 'http://data.xssed.com/xss.rss'] | |
| keywords = ['mozilla'] | |
| main(urls, keywords) | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment