當前位置: 首頁>>代碼示例>>Python>>正文


Python History.user方法代碼示例

本文整理匯總了Python中models.History.user方法的典型用法代碼示例。如果您正苦於以下問題:Python History.user方法的具體用法?Python History.user怎麽用?Python History.user使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在models.History的用法示例。


在下文中一共展示了History.user方法的2個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。

示例1: crawl_user

# 需要導入模塊: from models import History [as 別名]
# 或者: from models.History import user [as 別名]
def crawl_user(account):
    client = weibo.APIClient(app_key=settings.WEIBO_APPKEY, app_secret=settings.WEIBO_APPSECRET)
    client.set_access_token(account.access_token, 0)
    
    if settings.DEBUG:
        COUNT = 21
    else:
        COUNT = settings.WEIBO_API_MAX_COUNT
    id_func = lambda s:s.id 
    
    ##TODO: handle exception
    if not account.latest_status:
        all_statuses = client.statuses.home_timeline.get(count = COUNT).statuses
    else:
        statuses = client.statuses.home_timeline.get(since_id = account.latest_status.id, count = COUNT).statuses
        all_statuses = statuses
        
        while len(statuses) == COUNT:
            last_minid = min(map(id_func, statuses))
            ## The API will return the largest COUNT statuses whose id is larger than since_id
            ## so here is how we iterate to retrieve the entire set
            statuses = client.statuses.home_timeline.get(max_id = last_minid - 1, since_id = account.latest_status.id, count = COUNT).statuses
            all_statuses.extend(statuses)
            
    all_statuses.sort(key=id_func)
    ids = map(id_func, all_statuses)
    assert len(ids) == len(set(ids)) ## Sanity check: no duplicates in the list
    
    saved_statuses = map(store_status, all_statuses)
    for status in saved_statuses:
        ## If we encounter duplicated status, do not create history m2m again
        if not status.weiboaccount_set.exists():
            h = History()
            h.user = account
            h.status = status
            h.save()
    ## Move on if the status is 15 minutes old
    ## This is to deal with API sometimes having missing statuses in between (not even eventually consistent?!) 
    if saved_statuses:
        for i in reversed(range(len(saved_statuses))):
            if older_than(all_statuses[i].created_at, 15): 
                account.latest_status = saved_statuses[i]
                break
    account.save()
    return map(lambda s:s.id, saved_statuses)
開發者ID:xurubin,項目名稱:WeiboObservatory,代碼行數:47,代碼來源:crawl.py

示例2: _make_move

# 需要導入模塊: from models import History [as 別名]
# 或者: from models.History import user [as 別名]
 def _make_move(self, game, user, at_position, p):
     try:
         history = History(parent=game.key)
         history.user = user.key
         history.guess = p.coordinate
         history.turn = game.turn
         if game.player1_turn:
             history.player_turn = 1
         else:
             history.player_turn = 2
         if at_position <= 0:
             message = 'Miss!'
             history.result = 'miss'
             history.put()
             game.set_fired(user, p.d)
             game.put()
         else:
             message = "Hit!"
             history.result = 'hit'
             ships_query = Ship.query(ancestor=game.key)
             filter_query = ndb.query.FilterNode('user', '=', user.key)
             ships_query1 = ships_query.filter(filter_query)
             filter_query = ndb.query.FilterNode('type', '=', at_position)
             ships_query2 = ships_query1.filter(filter_query)
             ship = ships_query2.get()
             if not ship:
                 filter_query = ndb.query.FilterNode(
                     'type', '=', str(at_position))
                 ships_query3 = ships_query1.filter(filter_query)
                 ship = ships_query3.get()
             ship.hits += 1
             game.set_fired(user, p.d)
             if(ship.is_sank()):
                 message += " Ship %s sank" % ShipType(at_position)
                 game.sink_ship(user, at_position)
             history.put()
             ship.put()
             game.put()
     except ValueError as e:
         raise endpoints.BadRequestException(e)
     return game.to_form(message)
開發者ID:seyfig,項目名稱:BattleShip,代碼行數:43,代碼來源:api.py


注:本文中的models.History.user方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。