diff options
author | Christian Hodgden <chrhodgden@gmail.com> | 2024-02-03 18:23:56 +0000 |
---|---|---|
committer | Christian Hodgden <chrhodgden@gmail.com> | 2024-02-03 18:23:56 +0000 |
commit | cc1cda41d5008327a228ea1facb4db13484904ab (patch) | |
tree | bb5ee2fc3f7195ec33db93d2173f365cd0378f0b /hw.py | |
parent | f841f66799eeafb407f8b10c630dae2d1987c345 (diff) |
added username field
Diffstat (limited to 'hw.py')
-rw-r--r-- | hw.py | 15 |
1 files changed, 12 insertions, 3 deletions
@@ -1,6 +1,7 @@ import os from random import * from sqlite3 import * +import getpass if not os.path.isfile(os.path.join(os.getcwd(), 'sexy.db')): @@ -12,13 +13,21 @@ con = connect('sexy.db') cur = con.cursor() if chk_1: - cur.execute("CREATE TABLE sexy_tbl (chk INTEGER);") + cur.execute("CREATE TABLE sexy_tbl (username TEXT, chk INTEGER);") chk_2 = randint(0,1) -cur.execute("INSERT INTO sexy_tbl (chk) VALUES(:chk);", {"chk" : chk_2}) +username = getpass.getuser() +param = {"username" : username, "chk" : chk_2} + +cur.execute("INSERT INTO sexy_tbl (username, chk) VALUES(:username, :chk);", param) k = [] -res = cur.execute("SELECT sum(chk) as sum_chk, count(chk) as count_chk FROM sexy_tbl;") +res = cur.execute(''' + SELECT sum(chk) as sum_chk, count(chk) as count_chk + FROM sexy_tbl + WHERE username = :username;''', + param) + for desc in cur.description: k.append(desc[0]) row = res.fetchone() rcd = dict(zip(k,row)) |