-
Notifications
You must be signed in to change notification settings - Fork 100
/
Copy pathtest.py
55 lines (48 loc) · 1.7 KB
/
test.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
import sqlite3
import json
from tqdm import tqdm
from text_analysis import senti_score,sentiment_analyzer
def score_view_insert(id,usr_name,tweet_txt,descr,pos_words,neu_words,neg_words,score): #Insert data into the tweets_analysis after score generation
# try:
conn = sqlite3.connect('data.sql')
cur = conn.cursor()
cmd='insert into tweet_analysis (id,usr_name,tweets,descr,Positive_words,Neutral_words,Negative_words,SID_Score) values (?,?,?,?,?,?,?,?)'
cur.execute(cmd,(id,usr_name,tweet_txt,descr,pos_words,neu_words,neg_words,score))
conn.commit()
# except:
# print('Failed Data load')
# finally:
# conn.commit()
conn.close()
def score_view():
try:
conn = sqlite3.connect('data.sql')
cur = conn.cursor()
cmd='select id,usr_name,tweet_txt,descr from tweet_data'
cur.execute(cmd)
op=cur.fetchall()
return op
except:
print('Failed Data load')
finally:
conn.close()
######################################################################################################################################################################################################################
def score_gen():
c=0
op=score_view()
for i in tqdm(op):
id=i[0]
usr_name=i[1]
if i[2] and i[3] is not None:
tweet=i[2]
descr=i[3]
score=senti_score(descr)
else:
tweet='NULL'
descr='NULL'
score=0
c+=1
pos_wrd,neu_wrd,neg_wrd=sentiment_analyzer(descr)
score_view_insert(id,usr_name,tweet,descr,pos_wrd,neu_wrd,neg_wrd,score)
print('Total Insertion: '+str(c))
score_gen()