WIP: API change
This commit is contained in:
@@ -1,6 +1,45 @@
|
||||
"""This is only a temporary solution. Complete Photos API client is yet to be developed."""
|
||||
|
||||
from photosapi_client import AuthenticatedClient
|
||||
import asyncio
|
||||
from photosapi_client import AuthenticatedClient, Client
|
||||
from photosapi_client.api.default.user_me_users_me_get import sync as user_me
|
||||
from photosapi_client.api.default.user_create_users_post import asyncio as user_create
|
||||
from photosapi_client.api.default.login_for_access_token_token_post import (
|
||||
sync as login,
|
||||
)
|
||||
from photosapi_client.api.default.video_find_albums_album_videos_get import (
|
||||
asyncio as video_find,
|
||||
)
|
||||
from photosapi_client.api.default.album_find_albums_get import asyncio as album_find
|
||||
from photosapi_client.api.default.album_create_albums_post import (
|
||||
asyncio as album_create,
|
||||
)
|
||||
from photosapi_client.api.default.album_delete_album_id_delete import (
|
||||
asyncio as album_delete,
|
||||
)
|
||||
from photosapi_client.api.default.photo_find_albums_album_photos_get import (
|
||||
asyncio as photo_find,
|
||||
)
|
||||
from photosapi_client.api.default.photo_patch_photos_id_patch import (
|
||||
asyncio as photo_patch,
|
||||
)
|
||||
from photosapi_client.api.default.photo_delete_photos_id_delete import (
|
||||
asyncio as photo_delete,
|
||||
)
|
||||
from photosapi_client.api.default.photo_upload_albums_album_photos_post import (
|
||||
asyncio_detailed as photo_upload,
|
||||
)
|
||||
from photosapi_client.api.default.photo_get_photos_id_get import asyncio as photo_get
|
||||
|
||||
from photosapi_client.models.body_photo_upload_albums_album_photos_post import (
|
||||
BodyPhotoUploadAlbumsAlbumPhotosPost,
|
||||
)
|
||||
from photosapi_client.types import File
|
||||
from photosapi_client.models.token import Token
|
||||
from photosapi_client.models.http_validation_error import HTTPValidationError
|
||||
from photosapi_client.models.body_login_for_access_token_token_post import (
|
||||
BodyLoginForAccessTokenTokenPost,
|
||||
)
|
||||
|
||||
# import asyncio
|
||||
from base64 import b64decode, b64encode
|
||||
@@ -72,8 +111,33 @@ async def authorize() -> str:
|
||||
return (await response.json())["access_token"]
|
||||
|
||||
|
||||
unauthorized_client = Client(
|
||||
base_url=configGet("address", "posting", "api"),
|
||||
timeout=5.0,
|
||||
verify_ssl=True,
|
||||
raise_on_unexpected_status=True,
|
||||
)
|
||||
|
||||
login_token = login(
|
||||
client=unauthorized_client,
|
||||
form_data=BodyLoginForAccessTokenTokenPost(
|
||||
grant_type="password",
|
||||
scope="me albums.list albums.read albums.write photos.list photos.read photos.write videos.list videos.read videos.write",
|
||||
username=configGet("username", "posting", "api"),
|
||||
password=configGet("password", "posting", "api"),
|
||||
),
|
||||
)
|
||||
|
||||
if not isinstance(login_token, Token):
|
||||
logWrite(f"Could not initialize connection due to invalid token: {login_token}")
|
||||
exit()
|
||||
|
||||
client = AuthenticatedClient(
|
||||
base_url=configGet("address", "posting", "api"), token=await authorize()
|
||||
base_url=configGet("address", "posting", "api"),
|
||||
timeout=5.0,
|
||||
verify_ssl=True,
|
||||
raise_on_unexpected_status=True,
|
||||
token=login_token.access_token,
|
||||
)
|
||||
|
||||
# async def random_pic(token: Union[str, None] = None) -> Tuple[str, str]:
|
||||
@@ -267,5 +331,5 @@ client = AuthenticatedClient(
|
||||
# return None
|
||||
|
||||
|
||||
# if __name__ == "__main__":
|
||||
# print(asyncio.run(authorize()))
|
||||
if __name__ == "__main__":
|
||||
print(asyncio.run(authorize()))
|
||||
|
Reference in New Issue
Block a user