Update app.py
Browse files
app.py
CHANGED
|
@@ -11,12 +11,16 @@ from fastapi import FastAPI, HTTPException
|
|
| 11 |
from fastapi.responses import PlainTextResponse
|
| 12 |
from httpx import AsyncClient, HTTPStatusError, RequestError
|
| 13 |
from pydantic import BaseModel, HttpUrl
|
| 14 |
-
from ytelegraph import TelegraphAPI
|
| 15 |
from aiorentry.client import Client as RentryClient
|
| 16 |
from uvicorn import run as uvicorn_run
|
| 17 |
|
| 18 |
from os import environ
|
| 19 |
-
environ['PH_TOKEN_PATH'] = '
|
|
|
|
|
|
|
|
|
|
|
|
|
| 20 |
|
| 21 |
|
| 22 |
need_logging = False
|
|
@@ -173,7 +177,6 @@ async def optimize_and_upload(images_urls: List[str] | str, convert: bool = Fals
|
|
| 173 |
images_urls = [images_urls] if isinstance(images_urls, str) else images_urls
|
| 174 |
if convert:
|
| 175 |
try:
|
| 176 |
-
ph = TelegraphAPI()
|
| 177 |
ph_link = ph.create_page_md('DAll-E v3', 'изображения скоро появятся, обнови страницу...')
|
| 178 |
except Exception as e:
|
| 179 |
print(f'не получилось создать страницу на телеграфе: {e}')
|
|
@@ -183,7 +186,7 @@ async def optimize_and_upload(images_urls: List[str] | str, convert: bool = Fals
|
|
| 183 |
page_id, code = page.url, page.edit_code
|
| 184 |
continue_task = create_task(continue_optimizing_and_uploading(images_urls, page_id, code, ph_link))
|
| 185 |
print(f'https://rentry.co/{page_id}', f'https://rentry.org/{page_id}')
|
| 186 |
-
return [ph_link, f'https://rentry.co/{page_id}', f'https://rentry.org/{page_id}']
|
| 187 |
else:
|
| 188 |
return await continue_optimizing_and_uploading(images_urls)
|
| 189 |
|
|
@@ -213,7 +216,6 @@ async def continue_optimizing_and_uploading(images_urls: list[str], page_id: str
|
|
| 213 |
content = '\n\n'.join([f'' for url in new_images_urls])
|
| 214 |
if ph_link:
|
| 215 |
try:
|
| 216 |
-
ph = TelegraphAPI()
|
| 217 |
ph.edit_page_md(ph_link, content)
|
| 218 |
except Exception as e:
|
| 219 |
print(f'не удалось создать страницу на телеграфе: {e}')
|
|
|
|
| 11 |
from fastapi.responses import PlainTextResponse
|
| 12 |
from httpx import AsyncClient, HTTPStatusError, RequestError
|
| 13 |
from pydantic import BaseModel, HttpUrl
|
| 14 |
+
from ytelegraph import TelegraphAPI, TelegraphAccount
|
| 15 |
from aiorentry.client import Client as RentryClient
|
| 16 |
from uvicorn import run as uvicorn_run
|
| 17 |
|
| 18 |
from os import environ
|
| 19 |
+
environ['PH_TOKEN_PATH'] = (Path(__file__).parent / 'ph.txt').as_posix()
|
| 20 |
+
ph = TelegraphAPI()
|
| 21 |
+
ta = TelegraphAccount()
|
| 22 |
+
ph.base_url = 'https://telegraphprxver.vercel.app/'
|
| 23 |
+
ta.base_url = ph.base_url
|
| 24 |
|
| 25 |
|
| 26 |
need_logging = False
|
|
|
|
| 177 |
images_urls = [images_urls] if isinstance(images_urls, str) else images_urls
|
| 178 |
if convert:
|
| 179 |
try:
|
|
|
|
| 180 |
ph_link = ph.create_page_md('DAll-E v3', 'изображения скоро появятся, обнови страницу...')
|
| 181 |
except Exception as e:
|
| 182 |
print(f'не получилось создать страницу на телеграфе: {e}')
|
|
|
|
| 186 |
page_id, code = page.url, page.edit_code
|
| 187 |
continue_task = create_task(continue_optimizing_and_uploading(images_urls, page_id, code, ph_link))
|
| 188 |
print(f'https://rentry.co/{page_id}', f'https://rentry.org/{page_id}')
|
| 189 |
+
return [ph_link, f'https://rentry.co/{page_id}', f'https://rentry.org/{page_id}'] if ph_link else [f'https://rentry.co/{page_id}', f'https://rentry.org/{page_id}']
|
| 190 |
else:
|
| 191 |
return await continue_optimizing_and_uploading(images_urls)
|
| 192 |
|
|
|
|
| 216 |
content = '\n\n'.join([f'' for url in new_images_urls])
|
| 217 |
if ph_link:
|
| 218 |
try:
|
|
|
|
| 219 |
ph.edit_page_md(ph_link, content)
|
| 220 |
except Exception as e:
|
| 221 |
print(f'не удалось создать страницу на телеграфе: {e}')
|