diff --git a/.gitignore b/.gitignore index 3d414cc..b091641 100644 --- a/.gitignore +++ b/.gitignore @@ -20,7 +20,3 @@ public.pem *.session parser.json test_site.py - -### Docker ### -Dockerfile -docker-compose.yml diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000..b61afe3 --- /dev/null +++ b/Dockerfile @@ -0,0 +1,25 @@ +FROM python:3.12.3-slim + + +RUN apt-get update && apt-get install -y curl + +# Installing Poetry using curl +RUN curl -sSL https://install.python-poetry.org | python3 - + +#Adding Poetry to the PATH +ENV PATH="/root/.local/bin:$PATH" + + +COPY pyproject.toml poetry.lock /app/ + +#We give full access rights to the /app directory. +RUN chmod 777 /app + +WORKDIR /app + +#we install the dependencies specified in py project.tom l, excluding dev dependencies. +RUN poetry install --no-dev + +COPY . /app + +CMD ["poetry", "run", "python", "-u", "pyrogram_parser.py"] diff --git a/docker-compose.yml b/docker-compose.yml new file mode 100644 index 0000000..35f9c95 --- /dev/null +++ b/docker-compose.yml @@ -0,0 +1,13 @@ +version: '3.7' + +services: + parser: + build: . + volumes: + - .env:/app/.env # Attach the .env file to the container + networks: + - default # Connect the service to the default network + +networks: + default: + driver: bridge diff --git a/pyrogram_parser.py b/pyrogram_parser.py index e3d3c33..73ce1f4 100644 --- a/pyrogram_parser.py +++ b/pyrogram_parser.py @@ -13,12 +13,10 @@ # File for saving data filename = "parser.json" # specify the name of the session file for userbot -app = Client(f"{os.getenv("PYROGRAM_SESSION_STRING")}") +app = Client(os.getenv("PYROGRAM_SESSION_STRING")) # The url of the server url = os.getenv("URL") -print(url) - class Chat(BaseModel): id: int @@ -54,6 +52,7 @@ async def saveJson(message_save): data = json.load(file) except json.JSONDecodeError: data = [] + print(f"save message: id = {message_save.id}") data.append(message_save.serializableDict()) file.seek(0) json.dump(data, file, ensure_ascii=False, indent=4)