import pymysql
try:
connection = pymysql.connect(
host=host,
user=user,
password=password,
database=db_name,
)
print('Connection to database is successfully...')
except Exception as ex:
print('Connection to database is refused...')
print(ex)
def main():
with connection.cursor() as cursor:
cursor.execute("SHOW DATABASES")
print(cursor.fetchone()[0])
main()
@bot.on.raw_event(GroupEventType.WALL_POST_NEW, dataclass=GroupTypes.WallPostNew)
async def wall_post_new(event: GroupTypes.WallPostNew):
conversations = await bot.api.messages.get_conversations(peer_type='chat')['items']
for conv in conversations:
peer_id = conv['peer']['id']
try:
await bot.api.messages.send(peer_id=peer_id, message='Новый пост!', random_id=0,
attachment=f'wall-{event.group_id}_{event.object.id}')
except Exception as ex:
print(f'error: {ex}')
Class 'Coroutine' does not define '__getitem__', so the '[]' operator cannot be used on its instances
def create_main():
try:
connection = pymysql.connect(
host=host,
user=user,
password=password,
database=db_name,
)
with connection.cursor() as cursor:
cursor.execute("""CREATE TABLE IF NOT EXISTS main (
num INT AUTO_INCREMENT,
id INT,
score INT,
nickname VARCHAR(30),
lvl INT,
PRIMARY KEY (num))""")
connection.commit()
with connection.cursor() as cursor:
cursor.execute("INSERT INTO main (id, score, nickname, lvl) VALUES (123456789, 0, 'Максим', 1)")
connection.commit()
print('Connection to database is successfully...')
except Exception as ex:
print('Connection to database is refused...')
print(ex)
can_access_closed=True deactivated=None first_name='Максим' hidden=None id=308159543 is_closed=False last_name='Лиссников' friend_status=None mutual=None online=None online_app=None online_info=None online_mobile=None photo_100=None photo_50=None screen_name=None sex=None trending=None verified=None about=None access_key=None activities=None activity=None bdate=None blacklisted=None blacklisted_by_me=None books=None can_be_invited_group=None can_call=None can_call_from_group=None can_post=None can_see_all_posts=None can_see_audio=None can_see_gifts=None can_see_wishes=None can_send_friend_request=None can_subscribe_podcasts=None can_subscribe_posts=None can_upload_doc=None can_write_private_message=None career=None city=None clips_count=None common_count=None contact_id=None contact_name=None counters=None country=None crop_photo=None descriptions=None domain=None education_form=None education_status=None email=None exports=None facebook=None facebook_name=None faculty=None faculty_name=None first_name_abl=None first_name_acc=None first_name_dat=None first_name_gen=None first_name_ins=None first_name_nom=None followers_count=None games=None graduation=None has_mobile=None has_photo=None has_unseen_stories=None hash=None home_phone=None home_town=None instagram=None interests=None is_favorite=None is_friend=None is_hidden_from_feed=None is_message_request=None is_no_index=None is_service=None is_subscribed_podcasts=None is_video_live_notifications_blocked=None language=None last_name_abl=None last_name_acc=None last_name_dat=None last_name_gen=None last_name_ins=None last_name_nom=None last_seen=None lists=None livejournal=None maiden_name=None military=None mobile_phone=None movies=None music=None nickname=None occupation=None owner_state=None personal=None photo=None photo_200=None photo_200_orig=None photo_400=None photo_400_orig=None photo_big=None photo_id=None photo_max=None photo_max_orig=None photo_max_size=None photo_medium=None photo_medium_rec=None photo_rec=None quotes=None relation=None relation_partner=None relatives=None schools=None service_description=None site=None skype=None status=None status_audio=None stories_archive_count=None test=None timezone=None tv=None twitter=None type=None universities=None university=None university_group_id=None university_name=None video_live=None video_live_count=None video_live_level=None wall_comments=None wall_default=None