F
F
Fizl2021-08-09 18:36:51
Python
Fizl, 2021-08-09 18:36:51

The function of changing data in the database does not work, why?

Hello !
I'm trying to change one column in a db but for some reason my function not only doesn't work but it doesn't throw any errors

class DATABASE:
    def __init__(self):

        self.conn2 = sqlite3.connect('db1.db')
        self.cur2 = self.conn2.cursor()
        self.cur2.execute(
            '''CREATE TABLE IF NOT EXISTS task(id INTEGER PRIMARY KEY, name TEXT, task_name TEXT, task_dict TEXT, task_time TEXT, succes BOOLEAN)''')
        self.conn2.commit() 
 
class GET_MAIL():
    def __init__(self, mail):
        
        self.mail = mail
        self.db = db
        self.email_file = codecs.open('email.txt', 'r')
        self.password_file = codecs.open('password.txt', 'r')

        self.read_email_file = str(self.email_file.read())
        self.read_password_file = str(self.password_file.read())

        (self.retcode, self.capabilities) = self.mail.login(self.read_email_file, self.read_password_file)
#////////Нужная функция//////////
    def usedonedata(self, task_name_):
        self.db.cur2.execute("UPDATE task SET succes = True WHERE task_name = (?)", (task_name_,))
        self.db.conn2.commit()
      
#//////////////////////////////////////
    def get_task_func_norepeat(self):

        self.mail.list()
        self.mail.select('inbox')
        (retcode, messages) = self.mail.search(None, '(UNSEEN)')
        if retcode == 'OK':
            for num in messages[0].split():
                typ, data = self.mail.fetch(num,'(RFC822)')
                for response_part in data:
                    if isinstance(response_part, tuple):
                        original = email.message_from_bytes(response_part[1])
                        raw_email = data[0][1]
                        raw_email_string = raw_email.decode('utf-8')
                        email_message = email.message_from_string(raw_email_string)
                        typ, data = self.mail.store(num,'+FLAGS','\\Seen')

                        if "=?utf-8?b?IyMjIyo=?=" in ((email_message['Subject'])):
                            print("Задача решена")

                            if email_message.is_multipart():
                                print('1')
                                for payload in email_message.get_payload():
                                    body = payload.get_payload(decode=True).decode('utf-8')                                    
                                    self.usedonedata(body)                                                                                                       
                            else:    
                                print("2")
                                body = email_message.get_payload(decode=True).decode('utf-8')                                
                                self.usedonedata(body)                                                                      
                        else:
                            pass

I even tried creating it in the DATABASE class itself and calling it through a function in the GET_MAIL class.
It looked something like this:
#В классе DATABASE*
    def done_data(self, task_name_):
        self.cur2.execute("UPDATE task SET succes = True WHERE task_name = (?)", (task_name_,))
        self.conn2.commit()
#В классе GET_MAIL*
    def usedonedata(self,  task_name_):
        self.db.done_data(task_name_)

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question