-
Notifications
You must be signed in to change notification settings - Fork 0
/
dbConn.py
74 lines (61 loc) · 2.28 KB
/
dbConn.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
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
import mysql.connector
import numpy as np
import sqlite3
import sys
conn= mysql.connector.connect(user="root",password="",host="localhost",database="videojs")
conn_two= sqlite3.connect('videojs')
c=conn_two.cursor()
def read_from_db():
#sess_id=sys.argv[1]
sess_id = 1;
print(sess_id)
cursor_one = conn.cursor(buffered=True)
cursor_one.execute("select time_arr from info where sess_id= '%s'" % (sess_id))
data=cursor_one.fetchone()
cursor_two = conn.cursor()
cursor_two.execute("select type from questions")
data_two=cursor_two.fetchall()
str_data_two = ''.join(map(str, data_two))
split_data_two=str_data_two.replace(")('","").replace("'","").split(',')
the_new_list = [x.split(',') for x in data]
str_data = ''.join(map(str, the_new_list))
split_data=str_data.replace(" ", "").strip('[]').split(',')
i = 0
while i < len(split_data):
i += 1
fobj = open("one.srt")
text = fobj.read().strip().split()
quo_text= (', '.join("'" + item + "'" for item in text))
add_list=[]
i = 0
while i < len(split_data):
print(split_data[i])
if split_data[i] in quo_text: #string in present in the text file
ind_text=text.index(split_data[i].replace("'",""))
fix_max=ind_text+5
fix_min=ind_text-5
while ind_text < fix_max:
add_list.append(text[ind_text])
ind_text += 1
while ind_text > fix_min:
add_list.append(text[ind_text])
ind_text -= 1
else:
print("not matched" )
i += 1
database_list=[]
i = 0
while i < len(split_data_two):
if split_data_two[i] in add_list: #string in present in the text file
ind_text=add_list.index(split_data_two[i])
database_list.append(add_list[ind_text])
else:
print("not matched" )
i += 1
sess= sess_id
cursor_three=conn.cursor()
for elem in database_list:
cursor_three.execute("INSERT INTO data(sess_id,list) VALUES (%s,%s)",( sess,elem))
conn.commit()
fobj.close()
read_from_db()