面向BBFC的API服务、库和解析器
bbfcapi的Python项目详细描述
BBFC API
BBFC的Web API和Python库。在
公共REST API
- 托管@https://bbfcapi.fustra.co.uk
- 文档@https://bbfcapi.fustra.co.uk/redoc
- 替代文档@https://bbfcapi.fustra.co.uk/docs
现在就试试:
$ curl "https://bbfcapi.fustra.co.uk?title=interstellar"{"title":"Interstellar","ageRating":"12"}
使用Python客户端:
^{pr2}$>>>frombbfcapi.api_syncimportbest_match>>>best_match("interstellar",2014)Film(title='INTERSTELLAR',age_rating=<AgeRating.AGE_12:'12'>)
工程概况
项目分为:
- “我想自己托管上面演示的restapi”
- BBFCAPI-Python REST Web API
pip install bbfcapi[app]
- “我想要一个Python库来与上面演示的restapi对话”
- 用于BBFCAPI的Python客户端
pip install bbfcapi[api_async]
(异步变量)pip install bbfcapi[api_sync]
(同步变量)
- “我想要一个Python库与BBFC网站对话”
- BBFC网站的Python库
pip install bbfcapi[lib_async]
(异步变体)pip install bbfcapi[lib_sync]
(同步变量)
- “我想从BBFC下载原始HTML网页”
- 用于BBFC网站的Python网络客户端
pip install bbfcapi[client_async]
(异步变量)pip install bbfcapi[client_sync]
(同步变量)
- “我想解析从BBFC下载的网页”
- 用于BBFC网页的Python HMTL解析器
pip install bbfcapi
同步版本使用requests
库,而异步变体使用aiohttp
。在
高级REST Web API
安装pip install bbfcapi[app]
。在
要使用REST API查询BBFC,请首先运行web服务器:
$ uvicorn bbfcapi.app:app
然后,要使用Python库同步查询API:
frombbfcapi.api_syncimportbest_matchbest_match("interstellar",base_url="http://127.0.0.1:8000")
或者,要使用Python库异步查询API:
frombbfcapi.api_asyncimportbest_matchprint(awaitbest_match("interstellar",base_url="http://127.0.0.1:8000"))
importasynciofrombbfcapi.api_asyncimportbest_matchprint(asyncio.run(best_match("interstellar",base_url="http://127.0.0.1:8000")))
或者,要使用curl
查询API:
$ curl "127.0.0.1:8000?title=interstellar"{"title":"Interstellar",age_rating":"12"}
或者,要从其他网页查询API:
asyncfunctioncall(){constresponse=awaitfetch('http://127.0.0.1:8000/?title=interstellar');constresponseJson=awaitresponse.json();console.log(JSON.stringify(responseJson));}call();
附加说明:
- 当没有找到胶片时,返回HTTP 404 Not Found。在
- 浏览文档@http://127.0.0.1:8000/redoc。在
- 或者,浏览文档@http://127.0.0.1:8000/docs。在
- 有关托管此web应用程序的示例可在存储库的/docs文件夹中找到。在
高级Python库
要使用库从BBFC同步获取结果,请执行以下操作:
frombbfcapi.lib_asyncimportbest_matchprint(best_match(title="interstellar"))
要使用库从BBFC异步获取结果,请执行以下操作:
frombbfcapi.lib_asyncimportbest_matchprint(awaitbest_match(title="interstellar"))
importasynciofrombbfcapi.lib_asyncimportbest_matchprint(asyncio.run(best_match(title="interstellar")))
低级BBFC网络客户端和解析器
要使用库从BBFC同步获取原始HTML页面:
$ pip install bbfcapi[client_sync]`
frombbfcapi.client_syncimportsearchprint(search(title="interstellar"))
要使用库从BBFC异步获取原始HTML页面,请执行以下操作:
$ pip install bbfcapi[client_async]`
frombbfcapi.client_asyncimportsearchprint(awaitsearch(title="interstellar"))
importasynciofrombbfcapi.client_asyncimportsearchprint(asyncio.run(search(title="interstellar")))
要使用库解析来自BBFC的GraphQL API的结果,请执行以下操作:
$ pip install bbfcapi[parser]`
frombbfcapiimportparserprint(parser.best_autocomplete_match({"BBFC":"...graphql json..."}))
发展
poetry install -E all
设置virtualenv(一次性)poetry run uvicorn bbfcapi.apiweb:app --reload
运行web服务器make fix
、make check
和{}提交之前
还有一个make test-live
,它将对运行实时集成测试
BBFC网站。在
贡献
欢迎拉取请求:)
发布
这个应用程序发布在PyPi上。在
- 确保您已经用诗歌配置了PyPi存储库(一次性)
- 运行
make release
以执行检查列表
要发布到测试存储库:
- 确保您已经用诗歌配置了测试PyPi存储库(一次性)
poetry publish --build -r testpypi
上载到测试存储库
变更日志
未发布
。。。在
v3.0.0-2020年11月8日
- 重要提示:与BBFC新网站的兼容性有重大变化
- 更新各种依赖项
v2.0.2-2020年3月22日
- 修复另一个丢失的依赖项
v2.0.1-2020年3月22日
- 修复缺少的依赖项
v2.0.0-2020年3月22日
- 为BBFCAPI REST Web API添加Python客户端库
- 在webapi中为JSON字段使用camelCasing
- 重组整个程序包
v1.0.1-2020年1月19日
- 修正分析12A年龄等级
v1.0.0-2020年1月19日
- bbfcapi的首次发布
- 项目
标签: