Profitroll
5adb004a2a
* `/report` command added * Updated to libbot 1.5 * Moved to [PhotosAPI_Client](https://git.end-play.xyz/profitroll/PhotosAPI_Client) v0.5.0 from using self-made API client * Video support (almost stable) * Bug fixes and improvements Co-authored-by: profitroll <vozhd.kk@gmail.com> Reviewed-on: #27
34 lines
930 B
Python
34 lines
930 B
Python
import logging
|
|
from os import makedirs, path
|
|
from pathlib import Path
|
|
from typing import List, Union
|
|
from zipfile import ZipFile
|
|
|
|
import aiofiles
|
|
|
|
logger = logging.getLogger(__name__)
|
|
|
|
USERS_WITH_CONTEXT: List[int] = []
|
|
|
|
|
|
async def extract_and_save(handle: ZipFile, filename: str, destpath: Union[str, Path]):
|
|
"""Extract and save file from archive
|
|
|
|
### Args:
|
|
* handle (`ZipFile`): ZipFile handler
|
|
* filename (`str`): File base name
|
|
* path (`Union[str, Path]`): Path where to store
|
|
"""
|
|
data = handle.read(filename)
|
|
filepath = path.join(str(destpath), filename)
|
|
try:
|
|
makedirs(path.dirname(filepath), exist_ok=True)
|
|
async with aiofiles.open(filepath, "wb") as fd:
|
|
await fd.write(data)
|
|
logger.debug("Unzipped %s", filename)
|
|
except IsADirectoryError:
|
|
makedirs(filepath, exist_ok=True)
|
|
except FileNotFoundError:
|
|
pass
|
|
return
|