/cancel, /identify, sponsorships improvements and fixes #3
@ -193,6 +193,15 @@ def find_location(query: str) -> dict:
|
||||
raise PlaceNotFoundError(query)
|
||||
|
||||
def create_tmp(bytedata: Union[bytes, bytearray], kind: Union[Literal["image", "video"], None]) -> str:
|
||||
"""Create temporary file to help uploading it
|
||||
|
||||
### Args:
|
||||
* bytedata (`Union[bytes, bytearray]`): Some bytes to be written
|
||||
* kind (`Union[Literal["image", "video"], None]`): Kind of upload. Will add `.jpg` or `.mp4` if needed
|
||||
|
||||
### Returns:
|
||||
* `str`: Path to temporary file
|
||||
"""
|
||||
filename = str(uuid1())
|
||||
if kind == "image":
|
||||
filename += ".jpg"
|
||||
@ -204,6 +213,15 @@ def create_tmp(bytedata: Union[bytes, bytearray], kind: Union[Literal["image", "
|
||||
return path.join("tmp", filename)
|
||||
|
||||
async def download_tmp(app: Client, file_id: str) -> bytes:
|
||||
"""Download file by its ID and return its bytes
|
||||
|
||||
### Args:
|
||||
* app (`Client`): App that will download the file
|
||||
* file_id (`str`): File's unique id
|
||||
|
||||
### Returns:
|
||||
* `bytes`: Bytes of downloaded file
|
||||
"""
|
||||
filename = str(uuid1())
|
||||
makedirs("tmp", exist_ok=True)
|
||||
await app.download_media(file_id, path.join("tmp", filename))
|
||||
|
Reference in New Issue
Block a user