-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathcommand_count_table.py
More file actions
33 lines (26 loc) · 1.1 KB
/
command_count_table.py
File metadata and controls
33 lines (26 loc) · 1.1 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
import sqlite3
# establish connection to existing SQLite3 database
conn = sqlite3.connect('counter_db.db')
cursor = conn.cursor()
# create a new table for command counters if it doesn't already exit
cursor.execute('''CREATE TABLE IF NOT EXISTS command_counters (
command string,
date_logged date,
author string,
argument string
)''')
def add_command_count(command, author, argument, date_logged):
parameterized_data = """INSERT INTO command_counters
(command, author, argument, date_logged) VALUES (?,?,?,?)"""
params = (command, author, argument, date_logged)
cursor.execute(parameterized_data, params)
conn.commit()
def return_command_total():
number = cursor.execute("""SELECT command, lower(argument),
COUNT(distinct datetime(strftime('%Y-%m-%dT%H:%M:00', date_logged)))
FROM command_counters
WHERE command='typo'
GROUP BY command, lower(argument)""")
rows = number.fetchall()
count = len(rows)
return count