|
|
|
@ -52,12 +52,12 @@ async def random_pic(token: Union[str, None] = None) -> Tuple[str, str]:
|
|
|
|
|
pic = choice(resp.json()["results"])
|
|
|
|
|
return pic["id"], pic["filename"]
|
|
|
|
|
|
|
|
|
|
async def upload_pic(filepath: str, token: Union[str, None] = None) -> Tuple[bool, list]:
|
|
|
|
|
async def upload_pic(filepath: str, allow_duplicates: bool = False, token: Union[str, None] = None) -> Tuple[bool, list]:
|
|
|
|
|
token = await authorize() if token is None else token
|
|
|
|
|
try:
|
|
|
|
|
pic_name = path.basename(filepath)
|
|
|
|
|
files = {'file': (pic_name, open(filepath, 'rb'), 'image/jpeg')}
|
|
|
|
|
response = post(f'{configGet("address", "posting", "api")}/albums/{configGet("album", "posting", "api")}/photos', params={"caption": "queue", "compress": False}, headers={"Authorization": f"Bearer {token}"}, files=files)
|
|
|
|
|
response = post(f'{configGet("address", "posting", "api")}/albums/{configGet("album", "posting", "api")}/photos', params={"caption": "queue", "compress": False, "ignore_duplicates": allow_duplicates}, headers={"Authorization": f"Bearer {token}"}, files=files)
|
|
|
|
|
if response.status_code != 200 and response.status_code != 409:
|
|
|
|
|
logWrite(f"Could not upload '{filepath}' to API: HTTP {response.status_code} with message '{response.content}'")
|
|
|
|
|
raise SubmissionUploadError(str(filepath), response.status_code, response.content)
|
|
|
|
|