rallf.com软件开发工具包(sdk)
rallf的Python项目详细描述
ralf python sdk
rallf sdk提供了使用python3为rallf机器人(rallf.com)创建任务的工具。
免责声明!此软件包处于开发阶段(不稳定),可能有潜在的错误
安装
使用python包索引(pypi)
pip3 install rallf
来源
git clone https://github.com/RobotUnion/rallf-python-sdk
cd rallf-python-sdk
pip3 install -r requirements.txt
python3 setup.py install
开始(你好机器人任务)
为了开始robot任务开发,只需运行rallf-py create-project "hello"
,它将创建一个基本项目,其中包含下面解释的文件。
hello.py
# File: src/hello.pyfromrallf.sdkimportTask''' Hello task opens github and returns the title of the page upon it is loaded. To learn more about python selenium api, see https://selenium-python.readthedocs.io/'''classHello(Task):# implementing self.run is required for tasks, not for skillsdefrun(self,input):# Log stuff via the available loggerself.logger.debug('Hello Bot')# get a firefox instancebrowser=self.robot.devices['firefox']browser.get('https://github.com')returnbrowser.getTitle()
试试看(rallf cli)
要使用cli
,可以使用包中包含的二进制文件
rallf-py <args>
或者直接从python执行
python3 -m rallf.cli <args>
使用CLI
运行run
方法
rallf-py run . -f run
使用jsonrpc
api运行run
方法
echo'{"jsonrpc": "2.0", "id": 1, "method": "delegate", "params": {"routine": "run", "args": {}}}'| rallf-py run .
获取帮助
rallf-py -h
扩展使用
任务清单
rallf-py -h
扩展使用
任务清单
对于rallf.com任务,任务清单是必需的,但对于开发来说不是必需的,请访问manifest reference以深入了解任务清单。
/* File config/manifest.json */{"title":"Hello Task","description":"This tasks logs hello and returns the <title> of github.com","long-description":"@README.md","fqtn":"com.example.hello","type":"task",/* choices: task, skill */"main":"src.hello.Hello","exports":["run"],/* default: ["run"] */"permissions":{"uris":["https://github.com","https://google.com"],"devices":["firefox","chrome"],"skills":{"com.example.facebook":["likePage","likePost"],"com.example.gmail":["search","likePost"]},}}
注入对象
self.robot
此对象被注入到任务创建中input
此参数传递给run(self, input)
函数
任务间通信(ITC)
- 从市场上调用其他任务(rallf.com)
- 使用机器人技能
任务生命周期回调
warmup(self)
这个可选的方法在任务开始加速其余调用之前执行。run(self, input)
此必需的方法处理任务的工作,并在任务开始时触发。cooldown(self)
这个可选的方法是在任务需要一段时间而不使用时调用的。
任务vs技能
一个常见的问题是rallf生态系统中任务和技能的区别,主要区别在于
任务只有一个名为run
的方法,而且技能可以有很多,所以从技术上讲,任务是技能的一个子类型,
此外,一项技能还可以实现run
方法,也可以用作任务。