Ejemplo n.º 1
0
def serve_feeds_with_template():
    current_time = time.gmtime()
    current_local_time = time.localtime()
    try:
        crss = CouchRSS(os.environ['COUCH'], os.environ['READABILITY'], \
            os.environ['VIEW1'], os.environ['VIEW2'], os.environ['VIEW3'])
        print 'environment vars startup successful'
    except KeyError:
        print 'environment vars startup failed'
    feed_list = crss.get_feeds()
    all_articles = []
    for i in range(0, len(feed_list)):
        feed_start_time = time.gmtime()
        d = feedparser.parse(feed_list[i])
        this_feed = []
        for j in range(0, 5):
            try:
                arty_date = humanize.naturaltime(time.mktime(current_time) - \
                    time.mktime(d.entries[j].published_parsed))
                arty_link = d.entries[j].link
            except:
                arty_date = "?"
                arty_link = 'https://2names1scott.com/'
            this_feed.append([d.entries[j].title, arty_date, arty_link])
        all_articles.append([d.feed.title, fix_array_of_urls(this_feed)])
        print "Finished processing feed {} in {}".format( \
            feed_list[i], time.mktime(time.gmtime()) - time.mktime(feed_start_time))
    return template('feeds', current_local_time=current_local_time, \
        all_articles=all_articles)
Ejemplo n.º 2
0
def new_article():
    try:
        crss = CouchRSS(os.environ['COUCH'], os.environ['READABILITY'], \
            os.environ['VIEW1'], os.environ['VIEW2'], os.environ['VIEW3'])
        print 'environment vars startup successful'
    except KeyError:
        print 'environment vars startup failed'
    article_url = request.query.url
    if re.compile(r'www\.nytimes\.com').search(article_url):
        article_url = 'http://127.0.0.1:16800/nyt?url=' + article_url
    article = crss.view_article(article_url)
    if article:
        return article
    else:
        abort(503, "Readability error")