Compare commits

7 Commits

9 changed files with 51 additions and 17 deletions

2
.gitignore vendored
View File

@@ -55,3 +55,5 @@ htmlcov/
.cache .cache
coverage.xml coverage.xml
*.cover *.cover
credentials.json

17
Dockerfile Normal file
View File

@@ -0,0 +1,17 @@
FROM python:3.9-slim-bookworm
# 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 9,13,16 * * * cd /app && /usr/local/bin/python main.py >> /var/log/cron.log 2>&1

10
docker-compose.yml Normal file
View File

@@ -0,0 +1,10 @@
version: '3.8'
services:
gsheet-bot:
build: .
restart: unless-stopped
volumes:
- ./credentials.json:/app/credentials.json:ro
environment:
- TZ=Europe/Warsaw

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

@@ -34,7 +34,7 @@ class GSheetAPI:
except gspread.exceptions.WorksheetNotFound: except gspread.exceptions.WorksheetNotFound:
print(f" Tworzę nowy arkusz: {sheet_name}") print(f" Tworzę nowy arkusz: {sheet_name}")
ws = spreadsheet.add_worksheet(title=sheet_name, rows=100, cols=10) ws = spreadsheet.add_worksheet(title=sheet_name, rows=100, cols=10)
ws.append_row(["#", "Link", "Nr zamówienia", "Model", "Wykończenie", "Kolor Top", "Kolor Body", "Kolor Neck", "Kolor Head", "Finish"]) ws.append_row(["#", "Link", "Nr zamówienia", "Model", "Wykończenie", "Kolor Top", "Kolor Body", "Kolor Neck", "Kolor Head", "Finish K/C", "Finish S"])
return ws return ws
def batch_append_unique_rows(self, doc_name, sheet_name, rows_data): def batch_append_unique_rows(self, doc_name, sheet_name, rows_data):

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,19 +1,12 @@
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): return sheet_name
print(f"{i+1}. {name}")
sheet_name = input("\nWybierz arkusz do przetworzenia: ")
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."""