mirror of
https://gitlab.com/JKANetwork/powerfulcomputermanager.git
synced 2026-12-06 02:58:17 +01:00
First commit, only with CLI tools
This commit is contained in:
commit
e88675331c
22 files changed
+1690
No files matched your search
@@ -0,0 +1,45 @@
|
||||
import sqlite3
|
||||
import sysopt #File of options
|
||||
from shutil import copyfile
|
||||
from os import path
|
||||
from datetime import datetime
|
||||
|
||||
if not path.isfile('BD/database.db'):
|
||||
copyfile('BD/emptydatabase.db','BD/database.db')
|
||||
|
||||
def logit(text):
|
||||
text = str(text)
|
||||
now = datetime.now()
|
||||
print ("Log: " + text)
|
||||
with open('api.log', 'a') as file:
|
||||
file.write("Log ("+now.strftime("%x %X") + "): ")
|
||||
file.write(text)
|
||||
file.write('\n')
|
||||
|
||||
def dict_factory(cursor, row):
|
||||
d = {}
|
||||
for idx, col in enumerate(cursor.description):
|
||||
d[col[0]] = row[idx]
|
||||
return d
|
||||
|
||||
|
||||
def select(query):
|
||||
conn = sqlite3.connect('BD/database.db')
|
||||
conn.row_factory = dict_factory
|
||||
if sysopt.debugsql==True:
|
||||
logit("SQL: "+query)
|
||||
cur = conn.execute(query)
|
||||
return cur.fetchall()
|
||||
|
||||
def insert(query):
|
||||
conn = sqlite3.connect('BD/database.db')
|
||||
if sysopt.debugsql==True:
|
||||
logit(query)
|
||||
try:
|
||||
c = conn.cursor()
|
||||
c.execute("SQL: "+query)
|
||||
conn.commit()
|
||||
conn.close()
|
||||
return {'RESULT': 'OK'}
|
||||
except:
|
||||
return {'RESULT': 'SQLite3 Error'}
|
||||
Reference in new issue
Block a user