Answer the question
In order to leave comments, you need to log in
Running postgres server on docker?
There is a table with one column called ID, there will be located the IDs of the users who will run the ID.
And there is a trigger word kuku which shows all the id's in the table.
Code itself:
from aiogram import Bot, Dispatcher, executor
from aiogram.types import Message
import logging
import psycopg2
from aiogram.dispatcher.filters.builtin import CommandStart, Text
bot = Bot(token = 'SECRET')
dp = Dispatcher(bot)
logging .basicConfig(format=u'%(filename)s [LINE:%(lineno)d] #%(levelname)-8s [%(asctime)s] %(message)s',
level=logging.INFO)
@dp .message_handler(CommandStart())
async def welcome(message: Message):
user_id = message.chat.id
conn = psycopg2.connect(dbname = "postgres",
user = "postgres",
password = "oybek123",
host = "localhost",
port = 5432)
cursor = conn.cursor()
cursor. execute("INSERT INTO id_list(id) VALUES(%s)",(user_id,))
conn.commit()
conn.close()
@dp.message_handler(Text(equals=["kuku"]))
async def feedback_press_button (message: Message):
conn = psycopg2.connect(dbname="postgres",
user="postgres",
password="oybek123",
host="localhost",
port=5432)
cursor = conn.cursor()
cursor.execute("SELECT * FROM id_list")
grab_data = cursor.fetchall()
for val in grab_data:
await message.answer(val[0])
conn.commit()
conn.close()
await message.answer("OK")
if __name__ == '__main__':
executor.start_polling(dp, skip_updates=True)
============= =================
CODE is not perfect, I will fix it.. But I would like to learn how to do the following. Run BOTA+DATABASE on docker.
Just like an experiment. I want to learn something new.
Here is the dockerfile:
FROM python:3.9
RUN mkdir /src
WORKDIR /src
COPY . /src
RUN pip install -r requirements.txt
docker-compose:
version: '3.1'
services:
tgbot:
container_name: bot
build:
context: .
command: python main.py
restart: always
db:
image: postgres
restart: always
environment:
POSTGRES_PASSWORD: example
adminer:
image: adminer
restart: always
ports:
- 8080:8080
============== ================================================
1 ) the settings of the tgbot service, in my opinion, are correct, and the bot itself starts.
2) ADMINER:
there is an admin panel for the admin database, it starts at the address that I set here
conn = psycopg2.connect(dbname = "postgres",
user = "postgres",
password = "oybek123",
host = " localhost ",
port = 5432)
and the admin port is 8080. When I write to the address bar localhost: 8080 , the admin main page opens.
There are database types, login password name and so on.
3) Here is the problem:
I type
conn = psycopg2.connect(dbname = "postgres",
user = "postgres",
password = "oybek123",
host = " localhost ",
port = 5432)
Answer the question
In order to leave comments, you need to log in
But I would like to learn how to do the following. Run BOTA+DATABASE on docker.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question