Remove convertDocumentOneShot
This commit is contained in:
parent
0135bfb1ab
commit
2d13526926
|
@ -1,7 +1,6 @@
|
|||
# TG2PDF
|
||||
This telegram bot converts any libreoffice-supported document into a pdf file.
|
||||
It uses [pyrogram](https://docs.pyrogram.org/), [libreoffice](https://libreoffice.org) and optionally [unoserver](https://github.com/unoconv/unoserver).
|
||||
The unoserver dependency is entirely optional - however it improves theoretical processing speed, so its included into Dockerfile by default.
|
||||
It uses [pyrogram](https://docs.pyrogram.org/), [libreoffice](https://libreoffice.org) and [unoserver](https://github.com/unoconv/unoserver).
|
||||
|
||||
# Quickstart
|
||||
```console
|
||||
|
|
14
main.py
14
main.py
|
@ -66,15 +66,6 @@ async def unoConvertDocument(sourceDocumentPath, sourceDocumentName):
|
|||
subprocess.run(args=[unoconvertPath, "--convert-to", "pdf", sourceDocumentPath, outputDocumentPath])
|
||||
subprocess.run(args=["rm", sourceDocumentPath], check=True)
|
||||
return outputDocumentPath
|
||||
|
||||
async def convertDocumentOneShot(sourceDocumentPath, sourceDocumentName):
|
||||
libreofficePath = shutil.which("libreoffice") # Find full path to the libreoffice binary
|
||||
outputDir = "output"
|
||||
Path(outputDir).mkdir(parents=True, exist_ok=True) # Ensure directory exists
|
||||
subprocess.run(args=[libreofficePath, "--headless", "--convert-to", "pdf", "--outdir", outputDir, sourceDocumentPath], check=True)
|
||||
outputDocumentPath = Path(outputDir) / Path(f"{sourceDocumentName}").with_suffix('.pdf')
|
||||
subprocess.run(args=["rm", sourceDocumentPath], check=True)
|
||||
return outputDocumentPath
|
||||
|
||||
async def uploadDocument(outputDocumentPath, chat, message):
|
||||
await app.send_document(document=outputDocumentPath, chat_id=chat, reply_to_message_id=message)
|
||||
|
@ -84,9 +75,8 @@ async def uploadDocument(outputDocumentPath, chat, message):
|
|||
async def documentFetcher(client, message):
|
||||
mime_type = message.document.mime_type
|
||||
if validDocument(mime_type=mime_type) == True:
|
||||
sourceDocumentPath = await downloadDocument(message.document.file_id, message.document.file_name)
|
||||
if unoserverPath:
|
||||
outputDocumentPath = await unoConvertDocument(sourceDocumentPath, message.document.file_name)
|
||||
sourceDocumentPath = await downloadDocument(message.document.file_id, message.document.file_unique_id)
|
||||
outputDocumentPath = await unoConvertDocument(sourceDocumentPath, message.document.file_name)
|
||||
else:
|
||||
outputDocumentPath = await convertDocumentOneShot(sourceDocumentPath, message.document.file_name)
|
||||
await uploadDocument(outputDocumentPath, message.chat.id, message.id)
|
||||
|
|
Loading…
Reference in New Issue