semvec/pypi-packages huggingface dataset:
bakalariFileExplorer 1.0.4
Python library to access Bakalari documents
License: MIT

# bakalariFileExplorer
Python3 library to access Bakalari documents using requests.
* [GitHub](https://github.com/vfosnar/bakalariFileExplorer/) page
* [PyPi](https://pypi.org/project/bakalariFileExplorer/) page
## Example usage
```python
from bakalariFileExplorer import BakalariFileExplorer, File

USERNAME = ""
PASSWORD = ""
BAKALARI_ENDPOINT = "https://bakalari.example.org"

bfe = BakalariFileExplorer(BAKALARI_ENDPOINT)
bfe.authWithCredentials(USERNAME, PASSWORD)

# We can list the root directory
itemList = bfe.listFolder("")

# A folder
itemList = bfe.listFolder("Folder")

# Or any subfolder
itemList = bfe.listFolder("Folder\\Subfolder\\Yet another subfolder")

# Iterate items
for item in itemList:
    # Check if it's a file or folder
    if(type(item) == File):
        print("[File]", item.name)
        # And if it's a file we can download it using it's id
        bfe.downloadFile(item.id, "folder/" + item.name)
    else:
        print("[Folder]", item.name)
```


## Item classes
| Property  | File  | Folder    | Must be defined   |
|-----------|-------|-----------|-------------------|
| path      | X     | X         | X                 |
| name      | X     | X         | X                 |
| icon      | X     | X         | X                 |
| id        | X     | X         | X                 |
| owner     | X     | X         |                   |
| size      | X     |           |                   |

## BakalariFileExplorer.authWithCredentials(username: str, password: str)
Authenticates the user with given credentials.
\
\
Raises AuthError when wrong credentials are used.
```python
bfe.authWithCredentials(USERNAME, PASSWORD)

# You can now export the cookie so you can auth later with it
BakaAuth_COOKIE = bfe.getAuthCookie()
print(BakaAuth_COOKIE)
```

## BakalariFileExplorer.authWithCookie(BakaAuth: str)
Authenticates the user using given cookie. It looks like the cookie works only for a week but I didn't do enough research to be 100% sure.
\
\
Raises AuthError when bad cookie is used.
```python
bfe.authWithCookie(BakaAuth_COOKIE)
```

## BakalariFileExplorer.listFolder(path: str) -> list
returns a list of all content of a folder. You must use the same ``path`` as in the Bakalari documents explorer. Every item in the returned ``list`` is a ``bakalariFileExplorer.File`` or ``bakalariFileExplorer.Folder`` type.
\
\
Raises ``PathError`` when bad path is given.

## BakalariFileExplorer.downloadFile(id: str, localPath: str)
will download file based on given id and saves it to the given path. Path must include file name.

## BakalariFileExplorer.readFile(id: str) -> bytes
returns file content in bytes by given id. Path must include file name.

## Every call can also raise
``RequestError`` - most of the time when bad url is given.\
``ResponseError`` - most of the time when bad parameters are given.