mirror of
https://github.com/stijndcl/didier.git
synced 2026-04-07 15:48:29 +02:00
Create reminder task & command, fix Les aliases
This commit is contained in:
parent
caf595010b
commit
250c2d40c7
6 changed files with 133 additions and 4 deletions
43
functions/database/remind.py
Normal file
43
functions/database/remind.py
Normal file
|
|
@ -0,0 +1,43 @@
|
|||
from functions.database import utils
|
||||
|
||||
|
||||
def getAllRows():
|
||||
connection = utils.connect()
|
||||
cursor = connection.cursor()
|
||||
|
||||
cursor.execute("SELECT * FROM remind")
|
||||
return cursor.fetchall()
|
||||
|
||||
|
||||
def getOrAddUser(userid):
|
||||
connection = utils.connect()
|
||||
cursor = connection.cursor()
|
||||
|
||||
cursor.execute("SELECT * FROM remind WHERE userid = %s", (int(userid),))
|
||||
res = cursor.fetchall()
|
||||
|
||||
if not res:
|
||||
cursor.execute("INSERT INTO remind(userid) VALUES %s", (int(userid),))
|
||||
connection.commit()
|
||||
|
||||
return getOrAddUser(userid)
|
||||
|
||||
return res[0]
|
||||
|
||||
|
||||
def switchReminder(userid, column):
|
||||
connection = utils.connect()
|
||||
cursor = connection.cursor()
|
||||
|
||||
columns = ["id", "nightly", "les"]
|
||||
|
||||
res = getOrAddUser(userid)
|
||||
|
||||
# Switch the column value
|
||||
to = not (res[columns.index(column)])
|
||||
|
||||
cursor.execute("UPDATE remind SET %s = %s WHERE userid = %s", (column, to, int(userid),))
|
||||
connection.commit()
|
||||
|
||||
return to
|
||||
|
||||
Loading…
Add table
Add a link
Reference in a new issue