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


Python Article.get_by_id方法代码示例

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


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

示例1: articles

# 需要导入模块: from models import Article [as 别名]
# 或者: from models.Article import get_by_id [as 别名]
def articles():
    article_keys = memcache.get("article_keys")
    # logging.debug("dupe() article keys: %s", article_keys[:3])
    duplicate_check = memcache.get("duplicate_check") 

# dupe check skal inneholde:
#   i verste fall:
#     alle fra db - hente derfra hvis ingen dupe check
#   i beste fall:
#     de som ble skrapet forrige gang = article keys nå + dupe checks skal lagres som neste dupe check

    delete_ctr = 0
    if article_keys: # lagret av forrige scrape
        # logging.debug("article keys exist in dupes")
        if duplicate_check: # lagret av forrige duplicates
            for article_key in article_keys:
                article = Article.get_by_id(article_key.id())
                if article:
                    if article.title in duplicate_check:
                        db.delete(article)
                        article_keys.remove(article_key)
                        delete_ctr += 1
                    else:
                        duplicate_check.append(article.title)
            memcache.set("duplicate_check", duplicate_check)
            memcache.set("article_keys", article_keys, 7200)
        else:
            q = Article.all(keys_only=True)
            # q.order("datetime") no datetime on keys
            keys = q.fetch(500)
            duplicate_check = []
            for key in keys:
                article = Article.get_by_id(key.id())
                duplicate_check.append(article.title)

            for article_key in article_keys:

                article = Article.get_by_id(key.id())
                if article:
                    if article.title in duplicate_check: 
                        db.delete(article)
                        article_keys.remove(article_key)
                        delete_ctr += 1
                    else:
                        duplicate_check.append(article.title)
            memcache.set("duplicate_check", article_keys, 7200)
            memcache.set("article_keys", article_keys, 7200)
    elif duplicate_check:
        # logging.debug("article keys do NOT exist in dupes")
        memcache.set("duplicate_check", duplicate_check, 7200)

    logging.debug("deleted %s duplicate articles", delete_ctr)
开发者ID:memius,项目名称:market-analyzer,代码行数:54,代码来源:duplicates.py

示例2: get

# 需要导入模块: from models import Article [as 别名]
# 或者: from models.Article import get_by_id [as 别名]
    def get(self):
        if self.request.get("id"):

            article = Article.get_by_id(int(self.request.get("id")))

            if article:
                pic = article.img
                if self.request.get('thumb'):

                    img = images.Image(article.img)

                    width = int(self.request.get('width', 200))
                    height = int(self.request.get('height', img.height * width / img.width))

                    img.resize(height=height, width=width,
                               allow_stretch=False, crop_to_fit=True)
                    img.im_feeling_lucky()
                    pic = img.execute_transforms(output_encoding=images.JPEG)

                self.response.headers['Content-Type'] = 'image/jpeg'
                self.response.out.write(pic)
                return

        # Either "id" wasn't provided, or there was no image with that ID in the datastore.
        self.error(404)
开发者ID:stachern,项目名称:bseu_news,代码行数:27,代码来源:img.py

示例3: delete_article

# 需要导入模块: from models import Article [as 别名]
# 或者: from models.Article import get_by_id [as 别名]
def delete_article(request, article_id):

    article = Article.get_by_id(int(article_id))
    article.delete()
    messages.success(request, 'Article deleted successfully')

    return redirect('create_article')
开发者ID:paktek123,项目名称:article-blog,代码行数:9,代码来源:views.py

示例4: post

# 需要导入模块: from models import Article [as 别名]
# 或者: from models.Article import get_by_id [as 别名]
  def post(self, article_id, vote_type): 
    article = Article.get_by_id(int(article_id))
    
    if vote_type == 'down':
      vote = Upvote(article=article.key)
      article.rating = article.rating - 1.0
    else:
      vote = Downvote(article=article.key)
      article.rating = article.rating + 1.0
    
    ndb.put_multi([article, vote])

    return self.redirect('/', body="Thanks for your vote!")
开发者ID:aeakett,项目名称:AppEngine-Example,代码行数:15,代码来源:vote.py

示例5: get

# 需要导入模块: from models import Article [as 别名]
# 或者: from models.Article import get_by_id [as 别名]
  def get(self, article_id):
    """Generate a page for a specific article"""
    article = Article.get_by_id(int(article_id))
    template_values = {
      'title': article.title,
      'content': article.content,
      'date': article.submitted,
      'rating': article.rating,
      'id': article_id,
    }

    template = jinja_environment.get_template('article.html')
    self.response.out.write(template.render(template_values))
开发者ID:aeakett,项目名称:AppEngine-Example,代码行数:15,代码来源:index.py

示例6: update_article

# 需要导入模块: from models import Article [as 别名]
# 或者: from models.Article import get_by_id [as 别名]
def update_article(request, article_id):

    article = Article.get_by_id(int(article_id))
    articles = Article.all()

    if request.method == "POST":
        form = ArticleForm(request.POST)

        if form.is_valid():
            article.title = form.cleaned_data['title']
            article.body = form.cleaned_data['body']
            article.put()
            messages.success(request, 'Article updated successfully')
            return redirect('create_article')

    return render_to_response('create_article.html', dict(articles=articles, article=article, form_action="edit"))
开发者ID:paktek123,项目名称:article-blog,代码行数:18,代码来源:views.py

示例7: postComment

# 需要导入模块: from models import Article [as 别名]
# 或者: from models.Article import get_by_id [as 别名]
def postComment(article_id):
    article = Article.get_by_id(article_id)
    if not article:
        return "", 404, {"Content-Type": "application/json"}
    data = request.get_json()
    if not data:
        return "Missing data", 400
    comment = Comment()
    comment.article = article.key
    comment.author_name = escape(data.get("author_name"))
    comment.author_email = escape(data.get("author_email"))
    comment.content = escape(data.get("content"))
    comment.put()
    comments = Comment.query().order(Comment.date).fetch(keys_only=True)
    if len(comments) >= 10:
        comments[0].delete()
    return serialize(comment)
开发者ID:blogmv,项目名称:backend-python-flask,代码行数:19,代码来源:blogmv.py

示例8: recent_word_pairs

# 需要导入模块: from models import Article [as 别名]
# 或者: from models.Article import get_by_id [as 别名]
def recent_word_pairs():
    article_keys = memcache.get("article_keys")
    # logging.debug("recent word pairs() article keys: %s", article_keys[:3])
    kwp = []
    if article_keys:
        #logging.debug("article keys exist in classify")
        for key in article_keys: 
            article = Article.get_by_id(key.id())
            if article:
                if article.clean:
                    text = article.text # later, you'll want to do this with titles as well, and see if equally good.
                    if text:
                        kwp.append([key, word_pairs(text)])
        memcache.set("article_keys",article_keys, 7200)

    # else:
    #     logging.debug("article keys do NOT exist in classify")

    # logging.debug("kwp[:3]: %s", kwp[:3])
    return kwp
开发者ID:memius,项目名称:market-analyzer,代码行数:22,代码来源:classify.py

示例9: classify

# 需要导入模块: from models import Article [as 别名]
# 或者: from models.Article import get_by_id [as 别名]
def classify(keys_word_pairs):
    classify_ctr = 0

# du får inn en trippel liste, som inneholder ordparene for mange artikler. kjor en for-loop gjennom alle artiklene, og lagre hver enkelt artikkel. akkurat nå lagrer du en artikkel som du ikke har definert en gang.

    for [key, word_pairs] in keys_word_pairs:
        probs = []
        unseen_pairs = []
        if word_pairs: #and isinstance(word_pairs[0], str):
            first_pair = word_pairs[0]
            # logging.debug("first pair: %s",first_pair)
            first_word = first_pair[0]
            # logging.debug("first word: %s",first_word)
            if isinstance(first_word, unicode):
                pairs = [' '.join(pair) for pair in word_pairs] # each pair 1 string, double list
                # pairs = [' '.join(pair) for sublist in word_pairs for pair in sublist] # each pair 1 string, triple list.
                for word_pair in pairs:
                    # logging.debug("word_pair: %s", word_pair)
                    wp = Word_pair.all().filter("words =", word_pair).get() # dict fra memcache er muligens mye bedre her.
                    # logging.debug("wp: %s", wp)

                    if wp:
                        if wp.prob > 0.55 or wp.prob < 0.45:
                            probs.append(wp.prob) 
                    else:
                        unseen_pairs.append(word_pair)                    

                prob = bayes(probs) # takes care of the 20
                article = Article.get_by_id(key.id())
                article.prob = prob
                article.put()
                classify_ctr += 1

                store_unseen_pairs(unseen_pairs, prob)


    logging.debug("classified %s articles",classify_ctr)
开发者ID:memius,项目名称:market-analyzer,代码行数:39,代码来源:classify.py

示例10: getComments

# 需要导入模块: from models import Article [as 别名]
# 或者: from models.Article import get_by_id [as 别名]
def getComments(article_id):
    if not Article.get_by_id(article_id):
        return "", 404, {"Content-Type": "application/json"}
    return serialize(list(Comment.query(Comment.article == ndb.Key(Article, article_id)).order(Comment.date).fetch(10)))
开发者ID:blogmv,项目名称:backend-python-flask,代码行数:6,代码来源:blogmv.py

示例11: getArticle

# 需要导入模块: from models import Article [as 别名]
# 或者: from models.Article import get_by_id [as 别名]
def getArticle(article_id):
    return serialize(Article.get_by_id(article_id))
开发者ID:blogmv,项目名称:backend-python-flask,代码行数:4,代码来源:blogmv.py

示例12: get

# 需要导入模块: from models import Article [as 别名]
# 或者: from models.Article import get_by_id [as 别名]
 def get(self, article_id):
     article = Article.get_by_id(int(article_id))
     data = ArticleForm(instance=article)
     self.response.out.write(render('templates/article.html', {'form': data,
                                                               'url': '/article/',
                                                               'id': article.key()}))
开发者ID:stachern,项目名称:bseu_news,代码行数:8,代码来源:article.py

示例13: read_article

# 需要导入模块: from models import Article [as 别名]
# 或者: from models.Article import get_by_id [as 别名]
def read_article(request, article_id):

    article = Article.get_by_id(int(article_id))

    return render_to_response('read_article.html', dict(article=article))
开发者ID:paktek123,项目名称:article-blog,代码行数:7,代码来源:views.py

示例14: sentiment

# 需要导入模块: from models import Article [as 别名]
# 或者: from models.Article import get_by_id [as 别名]

#.........这里部分代码省略.........
# er dette også veldig ineffektivt? jeg henter jo enorme mengder ordpar fra db...' bruk memcache - lagre ordparene i memcache, se etter dem der, og hvis de ikke er der, hent dem fra db vha. 'name', som er ord 1? nei, du må hente vha. hele ordparet. dammit.



    
   # values = memcache.get("values")
   # if values: 
   #     [text, pos_freq, neg_freq, pos_size, neg_size, \
   #          title, pos_title_freq, neg_title_freq, pos_title_size, neg_title_size] = values
   # else:



#gather stats henter aldri fra memcache, den bare lagrer til:
    q = Article.all(keys_only=True)
    # q.order("datetime") no datetime on keys
    article_keys = q.fetch(10000)

    # finding sizes and frequencies:
    positive_corpus = []
    negative_corpus = []
#        negative_article_texts = []

    pos_title_corpus = []
    neg_title_corpus = []
        #neg_titles = []

    # if article_objects = []:
    #     article_objects = Article.all() 


    for key in article_keys:
        # logging.debug("key: %s", key)
        article = Article.get_by_id(key.id()) 
        # logging.debug("title: %s", article.title) 
        sentiment = article.sentiment

        # logging.debug("before positive corpus")

        wp = classify.word_pairs(article.text) 
        if sentiment == "positive":
            positive_corpus.append(wp)
        elif sentiment == "negative":
            negative_corpus.append(wp)

        # logging.debug("after positive corpus")

        title_sentiment = article.title_sentiment
        
        title_word_pairs = classify.word_pairs(article.title) 
        if title_sentiment == "positive":
            pos_title_corpus.append(title_word_pairs)
                #pos_titles.append(article.title)
        elif title_sentiment == "negative":
            neg_title_corpus.append(title_word_pairs)

        # logging.debug("before negative corpus")

    # logging.debug("after corpuses")

    pos_size = len(positive_corpus) # number of articles, which is what you want.
    neg_size = len(negative_corpus)
    
    pos_title_size = len(pos_title_corpus)
    neg_title_size = len(neg_title_corpus)
开发者ID:memius,项目名称:market-analyzer,代码行数:69,代码来源:analyze.py

示例15: count_recent_stats

# 需要导入模块: from models import Article [as 别名]
# 或者: from models.Article import get_by_id [as 别名]
def count_recent_stats():
    # if old_flag:
    #     q = Article.all(keys_only=True)
    #     article_keys = q.fetch(10000)
    # else:
    article_keys = memcache.get("article_keys")
    # logging.debug("clean() article keys: %s", article_keys[:3])
    # logging.debug("in clean")
    stats_ctr = 0
    if article_keys:
        # pos_ctr = 0
        # neg_ctr = 0

        companies = []
        logging.debug("article keys exist in stats")
        for article_key in article_keys:
            article = Article.get_by_id(article_key.id())
            if article != None and article.sentiment != "neutral":
                company = article.company # expensive, but ok for now - optimize later

                logging.debug("datetime.datetime.now(): %s", datetime.datetime.now())
                logging.debug("article.datetime: %s", article.datetime)
                if datetime.datetime.now() - article.datetime < datetime.timedelta(hours = 24):
                    if company.pos_ctr_day == None:
                        company.pos_ctr_day = 0
                    if company.neg_ctr_day == None:
                        company.neg_ctr_day = 0
                    if article.sentiment == 'positive':
                        company.pos_ctr_day += 1
                    elif article.sentiment == 'negative':
                        company.neg_ctr_day += 1

                elif True:
                    if company.pos_ctr_week == None:
                        company.pos_ctr_week = 0
                    if company.neg_ctr_week == None:
                        company.neg_ctr_week = 0
                    if article.sentiment == 'positive':
                        company.pos_ctr_week += 1
                    elif article.sentiment == 'negative':
                        company.neg_ctr_week += 1

                elif True:
                    if company.pos_ctr_month == None:
                        company.pos_ctr_month = 0
                    if company.neg_ctr_month == None:
                        company.neg_ctr_month = 0
                    if article.sentiment == 'positive':
                        company.pos_ctr_month += 1
                    elif article.sentiment == 'negative':
                        company.neg_ctr_month += 1


                company.put() # expensive to do this once for each article, but ok, because few articles each time.
                    
                # company = article.company # this is extremely expensive, but ok for now.
                # old_pos_ctr = company.pos_ctr
                # if old_pos_ctr == None:
                #     old_pos_ctr = 0
                # new_pos_ctr = old_pos_ctr + 1 # NOT pos_ctr, which counts for ALL the articles.
                # company.pos_ctr = new_pos_ctr

                # old_neg_ctr = company.neg_ctr
                # if old_neg_ctr == None:
                #     old_neg_ctr = 0
                # new_neg_ctr = old_neg_ctr + 1
                # company.neg_ctr = new_neg_ctr

                company.put()

        stats_ctr += 1
        # cleaning.remove(article) not needed, because pop removes it for us.
        memcache.set("article_keys", article_keys)
        # logging.debug("article keys set")

    logging.debug("counted stats for %s articles", stats_ctr)
开发者ID:memius,项目名称:market-analyzer,代码行数:78,代码来源:stats.py


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