Написал бота телеграм, фиксил ошибку за ошибкой, но не справился с последней
import telebot
import matplotlib.pyplot as plt
import numpy as np
import io
import aiogram
from datetime import datetime
bot = telebot.TeleBot('7061942175:AAE5pDV1NwM8VMngkVT4EbaSJIlYWyHKh1E')
# Initialize a dictionary to store the переписи data
census_data = {}
# Define the list of valid nationalities
valid_nationalities = ['Ѕerbšćin', 'Čech', 'Slovák', 'Polak', 'Ślůnzok', 'Kaszëbа', 'Беларус', 'Українець', 'Карпаторуснак', 'Русский', 'Българин', 'Македонец', 'Србин', 'Козак', 'Bosanac', 'Hrvat', 'Slovenec']
# Define the list of valid languages
valid_languages = ['Ѕerbšćina', 'Čeština', 'Ѕlovenský', 'Polszczyzna', 'Ślůnski', 'Kaszëbizna', 'Беларуская', 'Українська', 'Карпаторуськый', 'Русский', 'Български', 'Македонски', 'Српски', 'Вosanski', 'Hrvatski', 'Slovenščina']
participated_users = { }
# Handle the '/prepis' command
@bot.message_handler(commands=['prepis'])
def prepis(message):
# Extract the nationality and language from the command arguments
if message.chat.id in participated_users:
bot.send_message(message.chat.id, 'Vy uže jesti učestvovali.')
return
args = message.text.split(' ')
nationality = args[1]
language = args[2]
# Check if the nationality and language are valid
if nationality not in valid_nationalities or language not in valid_languages:
bot.send_message(message.chat.id, 'Povišy vami narodnost abo jezyk vpisany ne věrno.')
return
participated_users[message.chat.id] = True
# Increment the count for the given nationality and language in the census data
if nationality not in census_data:
census_data[nationality] = {}
if language not in census_data[nationality]:
census_data [nationality] [language] = 0
census_data [nationality] [language] += 1
# Send a confirmation message to the user
bot.send_message(message.chat.id, 'Dekuju za učestničstvo!')
# Generate a diagram from the census data every 24 hours
@bot.message_handler(func=lambda message: True)
def generate_diagram(message):
# Check if 24 hours have passed since the last diagram generation
if (datetime.datetime.now() - last_diagram_generation_time).total_seconds() > 86400:
# Create a bar chart of the census data
plt.figure(figsize=(10,5))
plt.bar(list(census_data.keys()), [sum(v.values()) for v in census_data.values()])
plt.title('Rezultat prěpisi')
plt.xlabel('Narodnost')
plt.ylabel('Jezyk')
# Convert the plot to a PNG image
buf = io.BytesIO()
plt.savefig(buf, format='png')
buf.seek(0)
# Send the image to the chat
bot.send_photo(message.chat.id, buf)
# Reset the last diagram generation time
last_diagram_generation_time = datetime.datetime.now()
# Start the bot
bot.polling()
Возвращает ошибку
Цитата Traceback (most recent call last): File "/data/user/0/ru.iiec.pydroid3/files/temp_iiec_codefile.py", line 42, in participated_users[message.chat.id] = True ^^^^^^^ NameError: name 'message' is not defined