A fully async and easy to use API client for the Ecole Directe API. This package is mainly used by Home Assistant, to offer the Ecole Directe integration. If you want to use this package in your own project, you can look at the Home Assistant Code for more examples.
- Free software: GNU General Public License v3
- Documentation: https://ecoledirecte-api.readthedocs.io.
- TODO
$ pip install ecoledirecteimport asyncio
import json
import logging
from pathlib import Path
from ecoledirecte_api.client import EDClient
from ecoledirecte_api.exceptions import BaseEcoleDirecteException
logger = logging.getLogger(__name__)
async def save_question(qcm_json):
"""Save question to file."""
with Path("qcm.json").open(
"w",
encoding="utf-8",
) as fp:
json.dump(qcm_json, fp, indent=4, ensure_ascii=False)
logger.info("Saved question to file", qcm_json)
async def main():
logging.basicConfig(filename="myapp.log", level=logging.DEBUG)
logger.info("Started")
try:
qcm_json = {}
with Path("qcm.json").open(
"r",
encoding="utf-8",
) as fp:
qcm_json = json.load(fp)
async with EDClient(
"user", "password", qcm_json
) as client:
client.on_new_question(save_question)
l = await client.login()
logger.info(f"l= {l}")
logger.info(f"Logged in as {client.username}")
logger.info("Finished")
await client.close()
except BaseEcoleDirecteException as e:
logger.exception(e.message)
return
except Exception as e:
logger.exception(e)
return
if __name__ == "__main__":
loop = asyncio.get_event_loop()
loop.run_until_complete(main())If you use Visual Studio Code with Docker or GitHub CodeSpaces, you can leverage the available devcontainer. This will install all required dependencies and tools and has the right Python version available. Easy!
This package was created with Cookiecutter and the audreyr/cookiecutter-pypackage project template.