当前位置: 首页>>代码示例>>Python>>正文


Python Article.objects方法代码示例

本文整理汇总了Python中article.Article.objects方法的典型用法代码示例。如果您正苦于以下问题:Python Article.objects方法的具体用法?Python Article.objects怎么用?Python Article.objects使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在article.Article的用法示例。


在下文中一共展示了Article.objects方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: generate_relation_dict

# 需要导入模块: from article import Article [as 别名]
# 或者: from article.Article import objects [as 别名]
    def generate_relation_dict(self, news_sources, news_targets):
        '''
        generates a dictionary of string/list(int) in the format
        {source : target_count}
        ie. {s1 : [tc1, tc2, ... tcn],
        s2 : [tc1, tc2, ... tcn], ...
        sn : [tc1, tc2, ... tcn]}
        where sn is the source, tcn is the citation count of each target
        '''
        # initialize the relation dictionary.
        relation_dict = {}

        for source_name, source_url in news_sources.iteritems():
            # create an empty list with a specific size which describe the number
            # of target referenced by each source
            target_count = [0] * len(news_targets)
            # Find the articles which have a specific source website url
            articles = Article.objects(
                Q(website=Website.objects(homepage_url=source_url).only('homepage_url').first()) &
                Q(citations__exists=True)).only('citations')
            for article in articles:
                # Count the times that each target in the news_targets is in the
                # citation list for each article and put it in the target_count
                for citation in article.citations:
                    if not isinstance( citation, int ):
                        i = 0
                        while i < len(news_targets):
                            if citation.target_name.lower() == news_targets.keys()[i].lower():
                                target_count[i] += 1
                            i += 1
            relation_dict[source_name] = target_count
        return relation_dict
开发者ID:lixiao37,项目名称:team12-Project,代码行数:34,代码来源:userinterface.py

示例2: get_articles

# 需要导入模块: from article import Article [as 别名]
# 或者: from article.Article import objects [as 别名]
    def get_articles(self, number=None):
        global username

        show_article_template = Template(filename='get_articles.html')
        sources = User.objects(name=username).first().news_sources
        targets = User.objects(name=username).first().news_targets
        articles = []

        for s in sources:
            articles += Article.objects(website=Website.objects(name=s).first()).only('title', 'url').all()
        for t in targets:
            articles += Article.objects(website=Website.objects(name=t).first()).only('title', 'url').all()

        if not number:
            number = len(articles)

        return show_article_template.render(articles=articles[ :int(number)])
开发者ID:lixiao37,项目名称:team12-Project,代码行数:19,代码来源:userinterface.py

示例3: generate_relation_dict_beta

# 需要导入模块: from article import Article [as 别名]
# 或者: from article.Article import objects [as 别名]
 def generate_relation_dict_beta(self, news_sources, news_targets):
     relation_dict = {}
     for source_name in news_sources:
         # create an empty list with a specific size which describe the number
         # of target referenced by each source
         target_count = [0] * len(news_targets)
         # Find the articles which have a specific source website url
         articles = Article.objects(
             Q(website=Website.objects(name=source_name).only('name').first()) &
             Q(citations__exists=True)).only('citations')
         for article in articles:
             # Count the times that each target in the news_targets is in the
             # citation list for each article and put it in the target_count
             for citation in article.citations:
                 if not isinstance( citation, int ):
                     i = 0
                     while i < len(news_targets):
                         if citation.target_name.lower() == news_targets[i].lower():
                             target_count[i] += 1
                         i += 1
         relation_dict[source_name] = target_count
     return relation_dict
开发者ID:lixiao37,项目名称:team12-Project,代码行数:24,代码来源:userinterface.py

示例4: add_article

# 需要导入模块: from article import Article [as 别名]
# 或者: from article.Article import objects [as 别名]
    def add_article(self, article_meta, website):
        '''Add the article in the database'''

        #Create an article object to check if it exists in the database
        art = Article.objects(
                    title=article_meta.get("title"),
                    url=article_meta.get('url'),
                    last_modified_date=article_meta.get('last_modified_date'),
                    website=website
                    ).first()

        if art:
            return art

        #This article object is used to add to the database
        art = Article(
                title=article_meta.get("title"),
                author=article_meta.get("author"),
                last_modified_date=article_meta.get("last_modified_date"),
                html=article_meta.get("html"),
                url=article_meta.get("url"),
                website=website
                    )
        try:
            status = art.save()
        except NotUniqueError:
            self.logger.warn('Article is not unique, url: {0}'.format(art.url))
            return None
        except ValidationError:
            self.logger.warn('Article Save/Validation Failed, url: {0}' \
                                               .format(article_meta.get("url")))
            return None

        if status:
            return art
        else:
            return None
开发者ID:lixiao37,项目名称:team12-Project,代码行数:39,代码来源:database.py

示例5: show_article

# 需要导入模块: from article import Article [as 别名]
# 或者: from article.Article import objects [as 别名]
 def show_article(self, url=None):
     if not url:
         return ""
     art = Article.objects(url=url).first()
     html = art.html
     return html
开发者ID:lixiao37,项目名称:team12-Project,代码行数:8,代码来源:userinterface.py


注:本文中的article.Article.objects方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。