diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000..a422d01 --- /dev/null +++ b/Dockerfile @@ -0,0 +1,17 @@ +FROM python:3.11.2-alpine3.17 + +LABEL Maintainer="serega404" + +WORKDIR /app + +COPY requirements.txt requirements.txt +RUN pip3 install -r requirements.txt + +# Setting up crontab +COPY crontab /tmp/crontab +RUN cat /tmp/crontab > /etc/crontabs/root + +COPY main.py main.py + +# run crond as main process of container +CMD ["crond", "-f", "-l", "2"] \ No newline at end of file diff --git a/crontab b/crontab new file mode 100644 index 0000000..f36485c --- /dev/null +++ b/crontab @@ -0,0 +1,2 @@ +@reboot cd /app && python3 /app/main.py +*/10 * * * * cd /app && python3 /app/main.py diff --git a/main.py b/main.py index 7d130fb..8b5ef7e 100644 --- a/main.py +++ b/main.py @@ -20,8 +20,8 @@ if TELEGRAM_CHANNEL == '': # Load database db = None -if (os.path.isfile('db.json')): - with open('db.json', 'r', encoding='utf-8') as f: +if (os.path.isfile('data/db.json')): + with open('data/db.json', 'r', encoding='utf-8') as f: db = json.load(f) else: print("Database not loaded") @@ -71,6 +71,9 @@ else: # Save database -with open('db.json', 'w', encoding='utf-8') as f: +if not os.path.exists("data"): + os.makedirs("data") + +with open('data/db.json', 'w', encoding='utf-8') as f: json.dump(elements, f, ensure_ascii=False) print("Database updated") diff --git a/requirements.txt b/requirements.txt new file mode 100644 index 0000000..a98ae43 --- /dev/null +++ b/requirements.txt @@ -0,0 +1,2 @@ +requests +beautifulsoup4 \ No newline at end of file