假日的python客户端库-api.de

ferien-api的Python项目详细描述


费里安API

PyPI versionBuild StatusCoverage StatusLicense: MIT

Python client library for ferien-api.de

安装

ferien-api需要python 3.5+才能正常工作

pip install ferien-api

用法

您可以使用同步实现,它将阻塞直到来自api的响应到达 或者您可以使用异步实现,它不会阻塞您的其他异步内容。

同步

importferiendefmain():# Get all vacations for all time and statesprint("All vacations:",ferien.all_vacations())# Get all vacations for a specific state (in this case Hamburg - HH) ...print("All vacations for HH:",ferien.state_vacations('HH'))# ... and optionally for a specific yearprint("All vacations for HH in 2019:",ferien.state_vacations('HH',2019))# Fetch all valid statesprint("Valid state codes:",ferien.state_codes())# Get current vacation (None if there is no vacation)print("Current vacation in HH:",ferien.current_vacation('HH'))# Get next vacation (None if there is no next vacation)print("Next vacation in HH:",ferien.next_vacation('HH'))if__name__=='__main__':main()

异步

importasyncioimportferienasyncdefmain():# Get all vacations for all time and statesprint("All vacations:",awaitferien.all_vacations_async())# Get all vacations for a specific state (in this case Hamburg - HH) ...print("All vacations for HH:",awaitferien.state_vacations_async('HH'))# ... and optionally for a specific yearprint("All vacations for HH in 2019:",awaitferien.state_vacations_async('HH',2019))# Fetch all valid states. This one is _NOT_ asyncprint("Valid state codes:",ferien.state_codes())# Get current vacation (None if there is no vacation)print("Current vacation in HH:",ferien.current_vacation(vacs=awaitferien.state_vacations_async('HH')))# Get next vacation (None if there is no next vacation)print("Next vacation in HH:",ferien.next_vacation(vacs=awaitferien.state_vacations_async('HH')))if__name__=='__main__':loop=asyncio.get_event_loop()loop.run_until_complete(main())

all_vacationsstate_vacations的实现都将返回Vacation数据对象的列表。 有关Vacation对象的定义,请参见下文。

Vacation(start=datetime.datetime(2020,12,21,0,0),end=datetime.datetime(2021,1,5,0,0),year=2020,state_code='HH',name='weihnachtsferien',slug='weihnachtsferien-2020-HH')

请注意:所有datetime对象都在Europe/Berlin (CET/CEST)时区中

使用异步版本很容易在“并行”中发出多个请求(不是真的……你知道当你 一个异步爱好者)并且节省了很多时间:

importasyncioimportferienasyncdefprint_wrapper(state_code):print("Fetching {}".format(state_code))res=awaitferien.state_vacations_async(state_code,2019)print("Fetched {}".format(state_code))returnresif__name__=='__main__':loop=asyncio.get_event_loop()coros=[print_wrapper('HH'),print_wrapper('SH'),print_wrapper('BE'),print_wrapper('BB')]loop.run_until_complete(asyncio.gather(*coros))

更改日志

0.3.4

  • 修正了日期在欧洲/柏林的错误本地化

0.3.3

  • 将所有时间戳从naive更改为“europe/berlin”

0.3.2

  • 向代码库添加类型提示
  • 将mypy添加为短绒

0.3.1

  • 加上皮林作为一根短绒,让他高兴!

0.3.0

  • 添加current_vacationnext_vacation实现

0.2.0

  • 添加all_vacationsstate_vacations
  • 的异步实现

0.1.0

  • 初始版本

欢迎加入QQ群-->: 979659372 Python中文网_新手群

推荐PyPI第三方库


热门话题
算法根据Java中传递的参数定义数据类型   java将图像文件存储在Google云存储桶中后,显示大小为“0字节”的所有文件列表   swing Java表模型删除Bounds 1的行排列   java中表上的for循环基本迭代   带有Http请求和UTF8的java下载文件   java滞后于setImageDrawable   java如何使用println按单位打印同一列中的数字列表?   中文Windows版本的Java默认编码   java编程项目,ADT列表   无法识别java消息部分MyClass。(它是否存在于服务WSDL中?)   java从IJavaProject或IProject获取到org。阿帕奇。专家模型模型   如何使用枚举(如java类变量)实现运行时同态?   使用集合对特定于Java的练习进行排序。分类   调试如何调试已作为exe文件运行的java应用程序?   java如何将带有模块的项目导入到另一个项目中,而不丢失封装?