def main(): """ Build aggregator report pages with Bayes rating links. """ # Create a new Bayes guesser guesser = Bayes() # Attempt to load Bayes data, ignoring IOError on first run. try: guesser.load(BAYES_DATA_FN) except IOError: pass # Open up the databases, load the subscriptions, get new entries. feed_db, entry_db = openDBs(FEED_DB_FN, ENTRY_DB_FN) feeds = [x.strip() for x in open(FEEDS_FN, "r").readlines()] entries = getNewFeedEntries(feeds, feed_db, entry_db) # Score the new entries using the Bayesian guesser entries = scoreEntries(guesser, entries) # Write out the current run's aggregator report. out_fn = time.strftime(HTML_FN) writeAggregatorPage(entries, out_fn, DATE_HDR_TMPL, FEED_HDR_TMPL, ENTRY_TMPL, PAGE_TMPL) # Close the databases and save the current guesser's state to disk. closeDBs(feed_db, entry_db) guesser.save(BAYES_DATA_FN)
def main(): """ Poll subscribed feeds and email out entries. """ feed_db, entry_db = openDBs(FEED_DB_FN, ENTRY_DB_FN) feeds = [ x.strip() for x in open(FEEDS_FN, "r").readlines() ] entries = getNewFeedEntries(feeds, feed_db, entry_db) if len(entries) > 0: emailEntries(FROM_ADDR, TO_ADDR, SUBJECT, SMTP_HOST, entries) closeDBs(feed_db, entry_db)
def main(): """ Poll subscribed feeds and email out entries. """ feed_db, entry_db = openDBs(FEED_DB_FN, ENTRY_DB_FN) feeds = [x.strip() for x in open(FEEDS_FN, "r").readlines()] entries = getNewFeedEntries(feeds, feed_db, entry_db) if len(entries) > 0: emailEntries(FROM_ADDR, TO_ADDR, SUBJECT, SMTP_HOST, entries) closeDBs(feed_db, entry_db)
def main(): """ Poll subscribed feeds and produce aggregator page. """ feed_db, entry_db = openDBs(FEED_DB_FN, ENTRY_DB_FN) feeds = [ x.strip() for x in open(FEEDS_FN, "r").readlines() ] entries = getNewFeedEntries(feeds, feed_db, entry_db) if len(entries) > 0: out_fn = HTML_FN % time.strftime("%Y%m%d-%H%M%S") writeAggregatorPage(entries, out_fn, DATE_HDR_TMPL, FEED_HDR_TMPL, ENTRY_TMPL, PAGE_TMPL) emailAggregatorPage(FROM_ADDR, TO_ADDR, SUBJECT, SMTP_HOST, out_fn) closeDBs(feed_db, entry_db)
def main(): """ Poll subscribed feeds and produce aggregator page. """ feed_db, entry_db = openDBs(FEED_DB_FN, ENTRY_DB_FN) feeds = [x.strip() for x in open(FEEDS_FN, "r").readlines()] entries = getNewFeedEntries(feeds, feed_db, entry_db) if len(entries) > 0: out_fn = HTML_FN % time.strftime("%Y%m%d-%H%M%S") writeAggregatorPage(entries, out_fn, DATE_HDR_TMPL, FEED_HDR_TMPL, ENTRY_TMPL, PAGE_TMPL) emailAggregatorPage(FROM_ADDR, TO_ADDR, SUBJECT, SMTP_HOST, out_fn) closeDBs(feed_db, entry_db)
def main(): """ Poll subscribed feeds and send off IMs """ feed_db, entry_db = openDBs(FEED_DB_FN, ENTRY_DB_FN) # Create a new IM connection. conn = IM_CLASS(IM_USER, IM_PASSWD) conn.connect() # Read in the subscriptions feeds = [ x.strip() for x in open(FEEDS_FN, "r").readlines() ] # Iterate through subscribed feeds. for feed in feeds: # Get new entries for the current feed and send them off entries = getNewFeedEntries([feed], feed_db, entry_db) if len(entries) > 0: sendEntriesViaIM(conn, IM_TO, entries, IM_CHUNK, FEED_HDR_TMPL, ENTRY_TMPL, MSG_TMPL) closeDBs(feed_db, entry_db)
def main(): """ Perform a test run of the FeedFilter using defaults. """ # Create a new Bayes guesser, attempt to load data guesser = Bayes() guesser.load(BAYES_DATA_FN) # Open up the databases, load the subscriptions, get new entries. feed_db, entry_db = openDBs(FEED_DB_FN, ENTRY_DB_FN) feeds = [x.strip() for x in open(FEEDS_FN, "r").readlines()] entries = getNewFeedEntries(feeds, feed_db, entry_db) # Build the feed filter. f = BayesFilter(guesser, entries) f.FEED_META['feed.title'] = FEED_TITLE f.FEED_META['feed.tagline'] = FEED_TAGLINE # Output the feed as both RSS and Atom. open(FEED_NAME_FN % 'rss', 'w').write(f.scrape_rss()) open(FEED_NAME_FN % 'atom', 'w').write(f.scrape_atom()) # Close the databases and save the current guesser's state to disk. closeDBs(feed_db, entry_db)
def main(): """ Perform a test run of the FeedFilter using defaults. """ # Create a new Bayes guesser, attempt to load data guesser = Bayes() guesser.load(BAYES_DATA_FN) # Open up the databases, load the subscriptions, get new entries. feed_db, entry_db = openDBs(FEED_DB_FN, ENTRY_DB_FN) feeds = [ x.strip() for x in open(FEEDS_FN, "r").readlines() ] entries = getNewFeedEntries(feeds, feed_db, entry_db) # Build the feed filter. f = BayesFilter(guesser, entries) f.FEED_META['feed.title'] = FEED_TITLE f.FEED_META['feed.tagline'] = FEED_TAGLINE # Output the feed as both RSS and Atom. open(FEED_NAME_FN % 'rss', 'w').write(f.scrape_rss()) open(FEED_NAME_FN % 'atom', 'w').write(f.scrape_atom()) # Close the databases and save the current guesser's state to disk. closeDBs(feed_db, entry_db)
def main(): """ Fire up the feed blog generator, write the static HTML to disk. """ # Try to load up entry history, start with an empty list in # case of any problems. try: entries = pickle.load(open(HISTORY_FN, 'rb')) except: entries = [] # Open up the databases, load the subscriptions, get new entries. feed_db, entry_db = openDBs(FEED_DB_FN, ENTRY_DB_FN) feeds = [x.strip() for x in open(FEEDS_FN, "r").readlines()] # Gather new entries from all feeds. subs_details = [] for feed_uri in feeds: # HACK: Grab 'custom' feed record details before agglib update. if feed_db.has_key(feed_uri): feed_rec = feed_db[feed_uri] feed_link = feed_rec.get('link', '#') feed_title = feed_rec.get('title', 'untitled') # Get new entries, if any. new_entries = getNewFeedEntries([feed_uri], feed_db, entry_db) # If there's no record of the feed in the DB, skip it. if not feed_db.has_key(feed_uri): continue # Update feed record details from fresh feed, if any entries found. if len(new_entries) > 0: feed = new_entries[0].data.feed feed_link = feed.get('link', '#') feed_title = feed.get('title', 'untitled') # HACK: Update 'custom' feed record details after agglib update. feed_rec = feed_db[feed_uri] feed_rec['link'] = feed_link feed_rec['title'] = feed_title feed_db[feed_uri] = feed_rec # Add details for this feed to the sidebar content. subs_details.append({ 'feed.link': feed_link, 'feed.title': feed_title, 'feed.url': feed_uri }) # Skip ahead if no new entries found. if len(new_entries) < 1: continue # Make sure entries have a modified date, using now by default. for e in new_entries: if not e.entry.has_key('modified_parsed'): e.entry['modified_parsed'] = time.gmtime() # Tack the list of new entries onto the head of the main list. entries = new_entries + entries # Sort the subscription details, build the sidebar content. subs_details.sort(lambda a, b: cmp(a['feed.title'], b['feed.title'])) subs_out = [SUBSCRIPTION_TMPL % x for x in subs_details] # Sort all the entries, truncate to desired length. entries.sort() entries = entries[:MAX_ENTRIES] # Write out the current run's aggregator report. out_fn = time.strftime(ARCHIVE_FN) writeAggregatorPage(entries, out_fn, DATE_HDR_TMPL, FEED_HDR_TMPL, ENTRY_TMPL, PAGE_TMPL) # Build the page template from the template template. out = SHELL_TMPL % { 'subs': '\n'.join(subs_out), 'main': open(out_fn).read() } open(BLOG_FN, 'w').write(out) # Close the databases and save the entry history back out to disk. closeDBs(feed_db, entry_db) pickle.dump(entries, open(HISTORY_FN, 'wb'))
def main(): """ Fire up the feed blog generator, write the static HTML to disk. """ # Try to load up entry history, start with an empty list in # case of any problems. try: entries = pickle.load(open(HISTORY_FN, 'rb')) except: entries = [] # Open up the databases, load the subscriptions, get new entries. feed_db, entry_db = openDBs(FEED_DB_FN, ENTRY_DB_FN) feeds = [ x.strip() for x in open(FEEDS_FN, "r").readlines() ] # Gather new entries from all feeds. subs_details = [] for feed_uri in feeds: # HACK: Grab 'custom' feed record details before agglib update. if feed_db.has_key(feed_uri): feed_rec = feed_db[feed_uri] feed_link = feed_rec.get('link', '#') feed_title = feed_rec.get('title', 'untitled') # Get new entries, if any. new_entries = getNewFeedEntries([feed_uri], feed_db, entry_db) # If there's no record of the feed in the DB, skip it. if not feed_db.has_key(feed_uri): continue # Update feed record details from fresh feed, if any entries found. if len(new_entries) > 0: feed = new_entries[0].data.feed feed_link = feed.get('link', '#') feed_title = feed.get('title', 'untitled') # HACK: Update 'custom' feed record details after agglib update. feed_rec = feed_db[feed_uri] feed_rec['link'] = feed_link feed_rec['title'] = feed_title feed_db[feed_uri] = feed_rec # Add details for this feed to the sidebar content. subs_details.append({ 'feed.link' : feed_link, 'feed.title' : feed_title, 'feed.url' : feed_uri }) # Skip ahead if no new entries found. if len(new_entries) < 1: continue # Make sure entries have a modified date, using now by default. for e in new_entries: if not e.entry.has_key('modified_parsed'): e.entry['modified_parsed'] = time.gmtime() # Tack the list of new entries onto the head of the main list. entries = new_entries + entries # Sort the subscription details, build the sidebar content. subs_details.sort(lambda a,b: cmp( a['feed.title'], b['feed.title'] )) subs_out = [ SUBSCRIPTION_TMPL % x for x in subs_details ] # Sort all the entries, truncate to desired length. entries.sort() entries = entries[:MAX_ENTRIES] # Write out the current run's aggregator report. out_fn = time.strftime(ARCHIVE_FN) writeAggregatorPage(entries, out_fn, DATE_HDR_TMPL, FEED_HDR_TMPL, ENTRY_TMPL, PAGE_TMPL) # Build the page template from the template template. out = SHELL_TMPL % { 'subs' : '\n'.join(subs_out), 'main' : open(out_fn).read() } open(BLOG_FN, 'w').write(out) # Close the databases and save the entry history back out to disk. closeDBs(feed_db, entry_db) pickle.dump(entries, open(HISTORY_FN, 'wb'))