web_server.py 文件源码

python
阅读 37 收藏 0 点赞 0 评论 0

项目:house-of-spirits 作者: OnlyInAmerica 项目源码 文件源码
def lights():
    """
    example_lights_json = {
        'rooms': [
            {'name': 'Living Room', 'on': True},
        ]
    }
    """
    if is_local_request(flask.request):
        json = flask.request.get_json()
        rooms = json.get('rooms', [])
        logger.info('Switching rooms %s', rooms)
        for json_room in rooms:
            room_name = json_room['name']
            on_state = json_room['on']

            for room in ROOMS:
                # Strip whitespace
                if room.name == room_name:
                    logger.info('Switching room %s', room.name)
                    room.switch(on_state)
        return "Light commands sent."
    else:
        logger.info('Lights accessed by remote address %s', flask.request.environ['REMOTE_ADDR'])
        flask.abort(404)
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号