Archived
some updates
This commit is contained in:
+10
@@ -0,0 +1,10 @@
|
|||||||
|
FROM python:3.9-slim
|
||||||
|
|
||||||
|
WORKDIR /app
|
||||||
|
|
||||||
|
COPY requirements.txt requirements.txt
|
||||||
|
RUN pip install -r requirements.txt
|
||||||
|
|
||||||
|
COPY ./app .
|
||||||
|
|
||||||
|
CMD ["./install.sh"]
|
||||||
@@ -12,3 +12,8 @@ for var in "${env_vars[@]}"; do
|
|||||||
fi
|
fi
|
||||||
done
|
done
|
||||||
|
|
||||||
|
# Add cron jobs to crontab
|
||||||
|
(crontab -l 2>/dev/null; echo "0 * * * * python3 /app/upload_sql.py") | crontab -
|
||||||
|
|
||||||
|
# Start the schedules.py script
|
||||||
|
python3 -u /app/schedules.py &
|
||||||
|
|||||||
@@ -0,0 +1,103 @@
|
|||||||
|
#!/usr/bin/python3.3
|
||||||
|
from datetime import datetime
|
||||||
|
import os
|
||||||
|
from dotenv import load_dotenv
|
||||||
|
from sshtunnel import SSHTunnelForwarder
|
||||||
|
from psycopg2 import pool
|
||||||
|
import json
|
||||||
|
|
||||||
|
|
||||||
|
allow_update = True
|
||||||
|
|
||||||
|
load_dotenv()
|
||||||
|
|
||||||
|
"""
|
||||||
|
{
|
||||||
|
"1025872648": {
|
||||||
|
"username": "ahunuin",
|
||||||
|
"first_name": "Arseniy",
|
||||||
|
"last_name": "",
|
||||||
|
"group": "205",
|
||||||
|
"timeout": "10",
|
||||||
|
"allow_message": "yes",
|
||||||
|
"thread": "General"
|
||||||
|
},
|
||||||
|
"856850518": {
|
||||||
|
"username": "kr0sh_512",
|
||||||
|
"first_name": "Дмитрий",
|
||||||
|
"last_name": "",
|
||||||
|
"group": "202",
|
||||||
|
"timeout": "10",
|
||||||
|
"allow_message": "no",
|
||||||
|
"thread": "General"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
"""
|
||||||
|
|
||||||
|
"""
|
||||||
|
CREATE TABLE IF NOT EXISTS users (
|
||||||
|
id BIGINT PRIMARY KEY,
|
||||||
|
username VARCHAR(255),
|
||||||
|
first_name VARCHAR(255),
|
||||||
|
last_name VARCHAR(255),
|
||||||
|
"group" VARCHAR(255) DEFAULT 'other',
|
||||||
|
timeout INT DEFAULT 10,
|
||||||
|
allow_message BOOLEAN DEFAULT TRUE,
|
||||||
|
thread VARCHAR(255) DEFAULT 'General',
|
||||||
|
created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP
|
||||||
|
);
|
||||||
|
"""
|
||||||
|
|
||||||
|
if os.environ.get("ENV") == "dev":
|
||||||
|
print("DEV: Connecting to local database")
|
||||||
|
server = SSHTunnelForwarder(
|
||||||
|
(os.environ.get("SSH_HOST"), 22),
|
||||||
|
ssh_private_key=os.environ.get("SSH_KEY"),
|
||||||
|
ssh_username=os.environ.get("SSH_USER"),
|
||||||
|
ssh_password=(
|
||||||
|
os.environ.get("SSH_PASSWORD") if os.environ.get("SSH_PASSWORD") else None
|
||||||
|
),
|
||||||
|
remote_bind_address=("localhost", int(os.environ.get("DB_PORT"))),
|
||||||
|
)
|
||||||
|
server.start()
|
||||||
|
|
||||||
|
db = pool.SimpleConnectionPool(
|
||||||
|
1,
|
||||||
|
20,
|
||||||
|
user=os.environ.get("DB_USER"),
|
||||||
|
password=os.environ.get("DB_PASSWORD"),
|
||||||
|
host="localhost" if os.environ.get("ENV") == "dev" else os.environ.get("DB_HOST"),
|
||||||
|
port=(
|
||||||
|
server.local_bind_port
|
||||||
|
if os.environ.get("ENV") == "dev"
|
||||||
|
else os.environ.get("DB_PORT")
|
||||||
|
),
|
||||||
|
database=os.environ.get("DB_NAME"),
|
||||||
|
)
|
||||||
|
|
||||||
|
# Load users from JSON file
|
||||||
|
with open("users.json", "r", encoding="utf-8") as file:
|
||||||
|
users = json.load(file)
|
||||||
|
|
||||||
|
# Insert users into the database
|
||||||
|
with db.getconn() as conn:
|
||||||
|
with conn.cursor() as cursor:
|
||||||
|
for user_id, user_data in users.items():
|
||||||
|
cursor.execute(
|
||||||
|
"""
|
||||||
|
INSERT INTO users (id, username, first_name, last_name, "group", timeout, allow_message, thread)
|
||||||
|
VALUES (%s, %s, %s, %s, %s, %s, %s, %s)
|
||||||
|
ON CONFLICT (id) DO NOTHING
|
||||||
|
""",
|
||||||
|
(
|
||||||
|
user_id,
|
||||||
|
user_data.get("username"),
|
||||||
|
user_data.get("first_name"),
|
||||||
|
user_data.get("last_name"),
|
||||||
|
user_data.get("group", "other"),
|
||||||
|
user_data.get("timeout", 10),
|
||||||
|
user_data.get("allow_message", "yes") == "yes",
|
||||||
|
user_data.get("thread", "General"),
|
||||||
|
),
|
||||||
|
)
|
||||||
|
conn.commit()
|
||||||
@@ -0,0 +1,20 @@
|
|||||||
|
services:
|
||||||
|
schedule_bot:
|
||||||
|
build:
|
||||||
|
context: .
|
||||||
|
dockerfile: Dockerfile
|
||||||
|
container_name: schedule_bot
|
||||||
|
environment:
|
||||||
|
- ENV=production
|
||||||
|
restart: unless-stopped
|
||||||
|
networks:
|
||||||
|
- postgres_postgres
|
||||||
|
deploy:
|
||||||
|
resources:
|
||||||
|
limits:
|
||||||
|
cpus: '0.3'
|
||||||
|
memory: 200M
|
||||||
|
|
||||||
|
networks:
|
||||||
|
postgres_postgres:
|
||||||
|
external: true
|
||||||
Reference in New Issue
Block a user