-
Notifications
You must be signed in to change notification settings - Fork 13
/
track_utils.py
47 lines (39 loc) · 1.8 KB
/
track_utils.py
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
34
35
36
37
38
39
40
41
42
43
44
45
46
47
import sqlite3
import pytz
from datetime import datetime
# Load Database Packages
conn = sqlite3.connect('./data/data.db', check_same_thread=False)
c = conn.cursor()
IST = pytz.timezone('Asia/Kolkata') # Indian Standard Time
# Function to create page visited table
def create_page_visited_table():
c.execute('CREATE TABLE IF NOT EXISTS pageTrackTable(pagename TEXT, timeOfvisit TIMESTAMP)')
# Function to add page visited details
def add_page_visited_details(pagename, timeOfvisit=None):
if timeOfvisit is None:
timeOfvisit = datetime.now(IST).strftime("%Y-%m-%d %H:%M:%S")
else:
timeOfvisit = timeOfvisit.astimezone(IST).strftime("%Y-%m-%d %H:%M:%S")
c.execute('INSERT INTO pageTrackTable(pagename, timeOfvisit) VALUES (?, ?)', (pagename, timeOfvisit))
conn.commit()
# Function to view all page visited details
def view_all_page_visited_details():
c.execute('SELECT * FROM pageTrackTable')
data = c.fetchall()
return data
# Function to create emotion classifier table
def create_emotionclf_table():
c.execute('CREATE TABLE IF NOT EXISTS emotionclfTable(rawtext TEXT, prediction TEXT, probability NUMBER, timeOfvisit TIMESTAMP)')
# Function to add prediction details
def add_prediction_details(rawtext, prediction, probability, timeOfvisit=None):
if timeOfvisit is None:
timeOfvisit = datetime.now(IST).strftime("%Y-%m-%d %H:%M:%S")
else:
timeOfvisit = timeOfvisit.astimezone(IST).strftime("%Y-%m-%d %H:%M:%S")
c.execute('INSERT INTO emotionclfTable(rawtext, prediction, probability, timeOfvisit) VALUES (?, ?, ?, ?)', (rawtext, prediction, probability, timeOfvisit))
conn.commit()
# Function to view all prediction details
def view_all_prediction_details():
c.execute('SELECT * FROM emotionclfTable')
data = c.fetchall()
return data