A
A
Alexander Zakharov2021-08-31 07:05:47
Python
Alexander Zakharov, 2021-08-31 07:05:47

Why does one variable work for all participants in a conversation?

Good afternoon!

faced the following problem:

There is a bot on VK. Written in vk_api, botlongpoll, python, sqlite3.

the bot is in some sense "gaming", and there is uns currency. this currency is stored in the database, but it is common for all users! how to fix it?

! I'm not asking you to write a fix for me, I will be glad for any help, even a little hint in which direction I should look! Thanks!!!

code on github: https://github.com/CleRIeQ/CleRIeQ/blob/Python-Pro... (sorry, it's not small :c)

my "DB" (functions that can be somehow related) :

import sqlite3 as sql

con = sql.connect("dott.db")  # это не функция. я сделал эту фигню напрямую, так как не знал как достать переменную из 
                                           #функции.
cur = con.cursor()

cur.execute("SELECT * FROM users")
records = cur.fetchall()
for row in records:
    money = int(row[3]) # та самая money (uns = money)
    print(money)

con.commit()
con.close()


#Query the DB and Return all records
def show_all():
    con = sql.connect("dott.db")
    cur = con.cursor()

    cur.execute("SELECT rowid, * FROM users")
    items = cur.fetchall()

    for item in items:
        print(item)

    con.commit()
    con.close()


def job_upd_balance(vkID, Balance):
    con = sql.connect("dott.db")
    cur = con.cursor()

    cur.execute("""UPDATE users SET balance = ?
          WHERE vkID = ? """, (Balance, vkID))

    con.commit()
    con.close()




def create_table(table):
    con = sql.connect("dott.db")
    cur = con.cursor()

    cur.execute("""CREATE TABLE IF NOT EXISTS users (
        vkID TEXT,
        fname TEXT,
        lname TEXT,          # моя таблица ( которая в боте )
        balance INT
    )""")

    con.commit()
    con.close()

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
Alan Gibizov, 2021-08-31
@phaggi

Maybe because someone else wrote this bot for their own purposes? Maybe ask the author of the bot?

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question