Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -144,11 +144,14 @@ async def tgph_create_page(token: str, title: str, markdown_text: str) -> str:
|
|
144 |
|
145 |
|
146 |
async def tgph_edit_page(token: str, page: str, title: str, markdown_text: str) -> str:
|
|
|
|
|
|
|
147 |
params = {
|
148 |
'access_token': token,
|
149 |
'path': page,
|
150 |
'title': title,
|
151 |
-
'content':
|
152 |
'return_content': False
|
153 |
}
|
154 |
async with AsyncClient(verify=False, follow_redirects=True, timeout=30.0) as client:
|
@@ -292,18 +295,18 @@ async def process_image(old_url: str, image_path: Path, convert: bool) -> tuple[
|
|
292 |
|
293 |
async def optimize_and_upload(images_urls: List[str] | str, convert: bool = False) -> List[str]:
|
294 |
images_urls = [images_urls] if isinstance(images_urls, str) else images_urls
|
|
|
295 |
if convert:
|
296 |
try:
|
297 |
ph_link = await tgph_create_page(tgph_acc.get_token(), 'DAll-E v3', '*изображения скоро появятся, обнови страницу...*')
|
298 |
except Exception as e:
|
299 |
print(f'не получилось создать страницу на телеграфе: {e}')
|
300 |
-
ph_link = None
|
301 |
async with RentryClient('https://rentry.org') as client:
|
302 |
page = await client.new_page('изображения скоро появятся, обнови страницу...')
|
303 |
page_id, code = page.url, page.edit_code
|
304 |
-
|
305 |
-
|
306 |
-
|
307 |
else:
|
308 |
return await continue_optimizing_and_uploading(images_urls)
|
309 |
|
@@ -336,6 +339,8 @@ async def continue_optimizing_and_uploading(images_urls: list[str], page_id: str
|
|
336 |
await tgph_edit_page(tgph_acc.get_token(), ph_link, 'DAll-E v3', content)
|
337 |
except Exception as e:
|
338 |
print(f'не удалось отредактировать на телеграфе: {e}')
|
|
|
|
|
339 |
if page_id and code:
|
340 |
try:
|
341 |
async with RentryClient('https://rentry.org') as client:
|
|
|
144 |
|
145 |
|
146 |
async def tgph_edit_page(token: str, page: str, title: str, markdown_text: str) -> str:
|
147 |
+
content = dumps(md_to_dom(markdown_text))
|
148 |
+
print(markdown_text)
|
149 |
+
print(content)
|
150 |
params = {
|
151 |
'access_token': token,
|
152 |
'path': page,
|
153 |
'title': title,
|
154 |
+
'content': content,
|
155 |
'return_content': False
|
156 |
}
|
157 |
async with AsyncClient(verify=False, follow_redirects=True, timeout=30.0) as client:
|
|
|
295 |
|
296 |
async def optimize_and_upload(images_urls: List[str] | str, convert: bool = False) -> List[str]:
|
297 |
images_urls = [images_urls] if isinstance(images_urls, str) else images_urls
|
298 |
+
ph_link = None
|
299 |
if convert:
|
300 |
try:
|
301 |
ph_link = await tgph_create_page(tgph_acc.get_token(), 'DAll-E v3', '*изображения скоро появятся, обнови страницу...*')
|
302 |
except Exception as e:
|
303 |
print(f'не получилось создать страницу на телеграфе: {e}')
|
|
|
304 |
async with RentryClient('https://rentry.org') as client:
|
305 |
page = await client.new_page('изображения скоро появятся, обнови страницу...')
|
306 |
page_id, code = page.url, page.edit_code
|
307 |
+
continue_task = create_task(continue_optimizing_and_uploading(images_urls, page_id, code, ph_link))
|
308 |
+
print(f'https://telegra.ph/{ph_link}', f'https://rentry.co/{page_id}', f'https://rentry.org/{page_id}')
|
309 |
+
return [f'https://telegra.ph/{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}']
|
310 |
else:
|
311 |
return await continue_optimizing_and_uploading(images_urls)
|
312 |
|
|
|
339 |
await tgph_edit_page(tgph_acc.get_token(), ph_link, 'DAll-E v3', content)
|
340 |
except Exception as e:
|
341 |
print(f'не удалось отредактировать на телеграфе: {e}')
|
342 |
+
else:
|
343 |
+
print(f'страница телеграф не предоставлена: {ph_link}')
|
344 |
if page_id and code:
|
345 |
try:
|
346 |
async with RentryClient('https://rentry.org') as client:
|