Package: ferien-api
ferien-apiPython client library for ferien-api.deInstallationferien-apineeds python 3.5+ to function properlypip install ferien-apiUsageYou could use the synchronous implementation which will block until a response arrives from the api
or you could use the async implementation which will be non-blocking your other async stuff.Synchronous: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()Asynchronous: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())Both implementations ofall_vacationsandstate_vacationswill return a list ofVacationdata objects.
See below for the definition of aVacationobject.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')Please note: All datetime objects are in theEurope/Berlin (CET/CEST)timezoneUsing the async version it is easy to make multiple requests in "parallel" (not true... you know that when you are
an asyncio enthusiast) and save a lot of time: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))Changelog0.3.7Adapts the vacation date parsing logic to the new ferien-api standard (#8)Fixes some linting errors using the latest linter / mypy (#8)0.3.6Removes unnecessary print statement in utils.py0.3.5Adds strptime fallback for Z remainder (#5)0.3.4Fixes incorrect localization to Europe/Berlin for dates0.3.3Changes all timestamps from naive to 'Europe/Berlin'0.3.2Adds type hints to codebaseAdds mypy as a linter0.3.1Adds pylint as a linter and make him happy!0.3.0Addscurrent_vacationandnext_vacationimplementations0.2.0Adds an async implementation ofall_vacationsandstate_vacations0.1.0Initial version