Compare commits

4 Commits

7 changed files with 44 additions and 15 deletions

17
Dockerfile Normal file
View File

@@ -0,0 +1,17 @@
FROM python:3.9-slim-buster
# Install cron
RUN apt-get update && apt-get -y install cron
WORKDIR /app
COPY requirements.txt .
RUN pip install --no-cache-dir -r requirements.txt
COPY . .
# Make entrypoint script executable
RUN chmod +x /app/entrypoint.sh
# Set the entrypoint
ENTRYPOINT ["/app/entrypoint.sh"]

1
crontab Normal file
View File

@@ -0,0 +1 @@
0 8,13,18 * * * python /app/main.py >> /var/log/cron.log 2>&1

7
docker-compose.yml Normal file
View File

@@ -0,0 +1,7 @@
version: '3.8'
services:
gsheet-bot:
build: .
restart: unless-stopped
volumes:
- ./credentials.json:/app/credentials.json:ro

11
entrypoint.sh Normal file
View File

@@ -0,0 +1,11 @@
#!/bin/bash
# Load the cron job
crontab /app/crontab
# Create the log file and set permissions
touch /var/log/cron.log
chmod 0666 /var/log/cron.log
# Start cron in the foreground
cron -f

View File

@@ -7,7 +7,7 @@ from processing import process_all_rows
def main(): def main():
gsheet_api = GSheetAPI() gsheet_api = GSheetAPI()
sheet_name = select_sheet(gsheet_api) sheet_name = select_sheet()
if not sheet_name: if not sheet_name:
return return

View File

@@ -1,20 +1,13 @@
import datetime
from config import DOC_NAME, RESULT_DOC from config import DOC_NAME, RESULT_DOC
def select_sheet(gsheet_api): def select_sheet():
"""Lists available sheets and prompts the user to select one.""" """Generates the sheet name based on the current month and year (MM.YYYY)."""
print("📄 Pobieram listę arkuszy...") now = datetime.datetime.now()
try: sheet_name = now.strftime("%m.%Y")
sheets = gsheet_api.list_sheets(DOC_NAME) print(f"📄 Automatycznie wybrano arkusz: {sheet_name}")
for i, name in enumerate(sheets):
print(f"{i+1}. {name}")
sheet_name = input("\nWybierz arkusz do przetworzenia: ")
return sheet_name return sheet_name
except Exception as e:
print(f"❌ Błąd podczas pobierania listy arkuszy: {e}")
return None
def get_sheet_data(gsheet_api, sheet_name): def get_sheet_data(gsheet_api, sheet_name):
"""Fetches all data from a given sheet.""" """Fetches all data from a given sheet."""
print(f"📋 Pobieram dane z arkusza: {sheet_name}") print(f"📋 Pobieram dane z arkusza: {sheet_name}")