Skip to content

Commit

Permalink
feat: add converting repository
Browse files Browse the repository at this point in the history
  • Loading branch information
thisisfabrics committed Dec 16, 2024
1 parent 8843cd0 commit 421f19b
Show file tree
Hide file tree
Showing 5 changed files with 57 additions and 3 deletions.
8 changes: 6 additions & 2 deletions docker-compose.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ services:
restart: always
ports:
- "8000:8000"

db:
# See more: https://registry.hub.docker.com/_/mongo
image: "mongo:8.0"
Expand All @@ -26,7 +26,11 @@ services:
environment:
MONGO_INITDB_ROOT_USERNAME: ${MONGO_INITDB_ROOT_USERNAME:-mongoadmin}
MONGO_INITDB_ROOT_PASSWORD: ${MONGO_INITDB_ROOT_PASSWORD:-secret}


unoserver:
image: ghcr.io/unoconv/unoserver-docker
ports:
- 2003:2003

volumes:
mongodb:
16 changes: 15 additions & 1 deletion poetry.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ pydantic = "^2.9.2"
ruff = "^0.6.7"
uvicorn = "^0.31.0"
pycups = "^2.0.4"
unoserver = "^3.1"

[tool.poetry.group.mongo.dependencies]
beanie = "^1.26.0"
Expand Down
Empty file.
35 changes: 35 additions & 0 deletions src/modules/converting/repository.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
__all__ = ["Converting"]

import os

import unoserver.client


class Converting:
def __init__(self, server="0.0.0.0", port=2003):
self.client = unoserver.client.UnoClient(server, port)

def conversion_is_allowed(self, filename: str):
return filename[filename.rfind(".") + 1 :] in [
"doc",
"docx",
"png",
"txt",
"jpg",
"md",
"bmp",
"xlsx",
"xls",
"odt",
"ods",
]

def any2pdf(self, filename: str):
if not self.conversion_is_allowed(filename):
print("The file cannot be converted.")
return
filepath = (here := os.path.dirname(__file__))[: here.index("src")] + f"files_to_be_printed/{filename}"
self.client.convert(inpath=filepath, outpath=f"{filepath[:filepath.rfind('.')]}.pdf")


converting_repository: Converting = Converting()

0 comments on commit 421f19b

Please sign in to comment.