def add_randcode(self, code):
with self.connection:
code = self.cursor.execute("SELECT * FROM `subscriptions` WHERE `code` = ?", (code, )).fetchone()
if code == None:
code = random.randint(1000,9999)
self.cursor.execute("""INSERT INTO subscriptions(code)
VALUES (?)""", (code, ))
return code
else:
return code
self.connection.commit()