无效用户蟒蛇
userful的Python项目详细描述
python用户版
the Userful REST API的非官方python客户端。
请注意,此客户端功能不完整,将根据需要添加调用。
用法
所有客户端方法都返回一个requests.Response
对象。他们都不做状态检查
由客户端的用户决定是否检查返回状态代码。
初始化
可以使用环境变量或在实例化客户端时配置客户端。
如果由于配置错误而导致身份验证失败,将引发requests.exceptions.HTTPError
。
使用环境变量
以下环境变量可用于配置客户端:
- userful_user-用于身份验证的用户名(必需)
- userful_pass-用于身份验证的密码(必需)。记住在环境中储存秘密 变量可能是危险的。因此,您可能希望在灌输期间提供密码。
- userful_host-userful api的主机名或IP地址(必需)
- userful端口-userful api的端口(可选,默认为
9000
)
导出这些变量后,可以按如下方式实例化客户端:
from userful.client import UserfulClient
client = UserfulClient()
初始化期间通过
from userful.client import UserfulClient
client = UserfulClient(user="myuser", password="s00persecret", host="myuserfulhost.com")
配方
在区域上切换源
# Change the source of the zone. This DOES NOT actually change what is on the screen.
# However, this source now becomes the default for the zone.
client.switch_source_by_zone('Zone-0', 'Userful Desktop')
# Actually make the zone start playing the new source
client.play_by_zone('Zone-0')
<更新现有的源代码># The PUT call to update a source is not idempotent, so we need to start by
# grabbing the existing source object
payload = client.get_sources(name='my_source')
# Get the ID of the source
source_id = payload['sourceId']
# Change the name of the source in the payload
payload['sourceName'] = 'my_new_source_name'
# Send the new data to the API
res = client.update_source(source_id, payload)