Example #1
0
def article(request, id):
    article = Article.get(id)
    
    if not article.content:
        target = ArticleParser.ArticleParser(article.url)
        target.process()
        logging.info('Loading new article from %s' % target.url)
        logging.info('Loading new article : %s' % target.title)
        
        article.content = target.get_content()
        article.put()
    
    return render_to_response('article.html', {'article':article})
Example #2
0
def blog(request, id):
    bloger = Blog.get(id)
    if not bloger:
        return render_to_response('article_list.html', {'article_list':[]})
    
    logging.info('Loading bloger : %s' % bloger.author)
    blog = BlogParser.BlogParser(bloger.url)
    blog.process()
    
    articles = []
    url = blog.getArticleListUrl()
    while True:
        logging.info('Loading article list : %s' % url)
        articleList = ArticleListParser.ArticleListParser(url)
        articleList.process()
        articles.extend(articleList.articleList)
        
        url = articleList.nextPage()
        if not url:
            break
        else:
            if Article.all().filter('url =', articles[-1]['url']).get():
                break
    
    list = []
    for article in articles:
        item = Article.all().filter('url =', article['url']).get()
        if not item:
            item = Article(blog=bloger,url=article['url'],title=article['title'])
            item.put()
            
            # Add the task to the default queue.
            taskqueue.add(url='/article/%s' % item.key())

        list.append((item.title,item.key()))
    
    # Mark this update time
    bloger.put()
    return render_to_response('article_list.html', {'article_list':list})