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


Python User.load方法代码示例

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


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

示例1: fivee

# 需要导入模块: from user import User [as 别名]
# 或者: from user.User import load [as 别名]
def fivee():
    if request.method == 'POST':
        user = User.get_user_from_token(request.form['token'])
        if not user:
            abort(404)
        user.load()
        if user['status'] == "waiting":
            return jsonify({})
        user['lat'] = request.form['lat']
        user['lng'] = request.form['lng']
        if not user['lat'] or not user['lng']:
            abort(400)
        user.save()
        log.info("User %s want to be a fivee", user['username'])
        fiver_wait_list = User.get_wait_list('fiver')
        fiver_match = None
        fiver_distance = None
        for str_fiver in fiver_wait_list:
            fiver = json.loads(str_fiver)
            distance = user.distance(fiver['lat'], fiver['lng'])
            if fiver_distance is None or distance < fiver_distance:
                fiver_distance = distance
                fiver_match = str_fiver

        if fiver_distance is None or fiver_distance > MAX_FYVE_DISTANCE:
            # No matches
            user['match'] = "..."
            user['status'] = "waiting"
            user.save()
            User.insert_into_wait_list('fivee', json.dumps(user.wait_list_format))
            return jsonify({})

        # We found a match!
        User.remove_from_wait_list('fiver', fiver_match)
        fiver_match = User(json.loads(fiver_match)['username'])
        fiver_match.load()
        fiver_match['match'] = user['username']
        fiver_match['status'] = "matched"
        fiver_match.save()
        user['match'] = fiver_match['username']
        user['status'] = "matched"
        user.save()

        return jsonify(fiver_match.match_format)

    else:
        user = User.get_user_from_token(request.args['token'])
        if not user:
            abort(404)
        user.load()
        # Checking in for a match
        if user['match'] == "...":
            # Still waiting
            assert user['status'] == "waiting"
            return jsonify({})
        # We have a match!
        match_user = User(user['match'])
        match_user.load()
        return jsonify(match_user.match_format)
开发者ID:Spearl,项目名称:highfyve-api,代码行数:61,代码来源:fyve.py

示例2: success

# 需要导入模块: from user import User [as 别名]
# 或者: from user.User import load [as 别名]
def success():
    user = User.get_user_from_token(request.form['token'])
    if not user:
        abort(404)
    log.info("User %s is reporting a successful high five!", user['username'])
    user.load()
    user_fyved = User(user['match'])
    user_fyved.load()

    # Fuck yeah!
    user['status'] = "fyved"
    user.save()
    user_fyved['status'] = "fyved"
    user_fyved.save()

    return jsonify({})
开发者ID:Spearl,项目名称:highfyve-api,代码行数:18,代码来源:fyve.py

示例3: bail

# 需要导入模块: from user import User [as 别名]
# 或者: from user.User import load [as 别名]
def bail():
    user = User.get_user_from_token(request.form['token'])
    if not user:
        abort(404)
    log.info("User %s is bailing", user['username'])
    user.load()

    user_left_hanging = User(user['match'])
    user_left_hanging.load()
    user_left_hanging['status'] = "cancelled"
    user_left_hanging.save()

    user['status'] = "cancelled"
    user.save()

    return jsonify({})
开发者ID:Spearl,项目名称:highfyve-api,代码行数:18,代码来源:fyve.py

示例4: get

# 需要导入模块: from user import User [as 别名]
# 或者: from user.User import load [as 别名]
    def get(self, id):
        user = User.load(id)
        if user is None:
            self.set_status(404)
            return

        self.write(user.to_json())
开发者ID:fariszacina,项目名称:fibrous,代码行数:9,代码来源:tornado_server.py

示例5: login

# 需要导入模块: from user import User [as 别名]
# 或者: from user.User import load [as 别名]
def login():
    username = request.form['username']
    password = request.form['password']
    user = User(username)
    if not user.exists:
        if not request.form['photo']:
            abort(401)
        user['token'] = str(uuid.uuid4()).replace('-','')
        user['password'] = password
        user['photo'] = request.form['photo']
        user.save()
        user.save_token()
    else:
        user.load()
        if password != user['password']:
            abort(401)
    log.info("User %s logged in", username)
    return jsonify({'token': user['token']})
开发者ID:Spearl,项目名称:highfyve-api,代码行数:20,代码来源:fyve.py

示例6: render_GET

# 需要导入模块: from user import User [as 别名]
# 或者: from user.User import load [as 别名]
    def render_GET(self, request):
        user_id = self.user_id(request.path)
        if user_id is None:
            request.setResponseCode(400)
            return ""

        user = User.load(user_id)
        if user is None:
            request.setResponseCode(404)
            return ""

        return user.to_json()
开发者ID:fariszacina,项目名称:fibrous,代码行数:14,代码来源:twisted_server.py

示例7: get_message_reply

# 需要导入模块: from user import User [as 别名]
# 或者: from user.User import load [as 别名]
def get_message_reply(message):	
	user = User(message.sender.id)
	if message.text == "/start" or message.text == "🔄 Начать заново":
		user.progressLabel, user.progressKey, user.active, user.variables = "start", -1, 1, {}
		user.save() 	
		return ("Вы начали игру заново", ReplyKeyboardMarkup.create([['⏸ Приостановить игру']],resize_keyboard=True))
	elif message.text == "/pause" or message.text == "⏸ Приостановить игру":
		user.active = 0
		user.save()
		return ("Игра приостановлена", ReplyKeyboardMarkup.create([['🔄 Начать заново'],['▶️ Продолжить игру']],resize_keyboard=True))
	elif message.text == "/continue" or message.text == "▶️ Продолжить игру":
		user.active = 1
		user.save()
		return ("Игра возобновлена", ReplyKeyboardMarkup.create([['⏸ Приостановить игру']],resize_keyboard=True))
	else:
		scenario.load(user)
		if scenario.get_current().__class__.__name__ == "NodeMenu":
			menu_item_finded = False
			for line,label in scenario.get_current().menu:
				if (line == message.text):
					menu_item_finded = True
					scenario.goto(label,-1)
					break
			if (menu_item_finded):
				reply, menu = scenario.next()
				user.load(scenario)
				user.lastMessage = round(time.time())
				user.save()
				if (menu):
					return (reply, ReplyKeyboardMarkup.create([[line] for line,label in menu],resize_keyboard=True))
				else:
					return (reply, ReplyKeyboardMarkup.create([['⏸ Приостановить игру']],resize_keyboard=True))
			else:
				return ("???", ReplyKeyboardMarkup.create([[line] for line,label in scenario.get_current().menu] + [['🔄 Начать заново']],resize_keyboard=True))
		else:
			if (user.active):
				return ("Чтобы начать заново введите /start, чтобы приостановить игру введите /pause", ReplyKeyboardMarkup.create([['🔄 Начать заново'],['⏸ Приостановить игру']],resize_keyboard=True))
			else:
				return ("Чтобы начать заново введите /start, чтобы продолжить игру введите /continue", ReplyKeyboardMarkup.create([['🔄 Начать заново'],['▶️ Продолжить игру']],resize_keyboard=True))
开发者ID:Tairesh,项目名称:telegram-quest,代码行数:41,代码来源:bot.py

示例8: stop

# 需要导入模块: from user import User [as 别名]
# 或者: from user.User import load [as 别名]
    def stop(cls, request):
        userid = unquote(request.form['name']).lower()
        user = User.load(userid)
    
        user.check_password(request)

        # get existing trip
        trip = Trip.load(userid)

        pipe = rd.pipeline()

        # remove user from map
        if trip:
            prevloc = Point(trip['loc'])
            pipe.srem('userloc:'+prevloc.hashUser(), userid)

        Camera.deactivate(pipe, user)
        pipe.delete('t:' + userid)
        pipe.execute()

        return 'OK'
开发者ID:tomasvdw,项目名称:thas,代码行数:23,代码来源:trip.py

示例9: get_user

# 需要导入模块: from user import User [as 别名]
# 或者: from user.User import load [as 别名]
def get_user():
    user_id = request.cookies.get('u')
    user = User.load(user_id)
    if not user:
        user = User.create()
    return user
开发者ID:boivie,项目名称:uplinq-geosnap,代码行数:8,代码来源:run.py

示例10: create_point

# 需要导入模块: from user import User [as 别名]
# 或者: from user.User import load [as 别名]
    def create_point(cls,request):
    
        # load and check user
        userid = unquote(request.form['name']).lower()
        user = User.load(userid=userid)
        user.check_password(request)
    
    
        # check if locked
        if user.locked_for() > 0:
            return 'LOCKED: ' + str(user.locked_for())

        # get existing trip
        trip = Trip.load(userid)

        # see where we moving from and to
        loc = Point(unquote(request.form['loc']))
        prevloc = Point(trip['loc']) if trip else loc

        pipe = rd.pipeline()

        # remove user from map
        if trip:
            pipe.srem('userloc:'+prevloc.hashUser(), userid)

        # count users
        evilness = rd.scard('userloc:' + loc.hashUser())

        if Camera.check_line(prevloc, loc, userid):
            Camera.deactivate(pipe, user)
            pipe.delete('t:' + userid)

            # add feed "Spotted"
            #  
            # 
            pipe.execute()
            return 'LOCKED: ' + str(user.locked_for())

        # now we now we're good
        # see if we have a camera to place
        if ('cam-num' in request.form):
           direction = request.form['cam-direction']
           num = request.form['cam-num']
           cam = Camera.create_new(userid, num, str(loc), direction)
           cam.place(user, pipe)


        # add user to map
        pipe.sadd('userloc:'+loc.hashUser(), userid)

        # update users centre-spot
        user.update_centre(pipe, loc)
        
        if not trip:
            # create a new trip
            trip = Trip.create_new(userid, loc)
            trip.save(pipe)
            Camera.activate(pipe, user)

        else:
            # extend trip
            trip.extend(loc, evilness)

            if (trip.progress() >= 1):
                # we're done
                trip.save(pipe)
                user.add_trip_points(pipe, float(trip['points']) / float(trip['point_count']))
                trip = Trip.create_new(userid, loc)
                # feed.create()
                pipe.execute()
                return 'DON'
            else:
                # save
                trip.save(pipe)

        pipe.execute()
        return 'ACT: ' + str(trip.progress()) + ':' + str(evilness)
开发者ID:tomasvdw,项目名称:thas,代码行数:79,代码来源:trip.py


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