Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
2
20_21-J09
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
2
Merge Requests
2
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Analytics
Analytics
CI / CD
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
20_21-J09
20_21-J09
Commits
6dad8a8b
Commit
6dad8a8b
authored
May 10, 2021
by
IT17186216_Chamath Ravindu
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
'updated_python_code'
parent
dcd61da2
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
131 additions
and
0 deletions
+131
-0
app.py
app.py
+45
-0
sentimental.ipynb
sentimental.ipynb
+86
-0
No files found.
app.py
0 → 100644
View file @
6dad8a8b
from
flask
import
Flask
,
jsonify
from
textblob
import
TextBlob
import
pandas
as
pd
import
mysql.connector
from
flask_cors
import
CORS
app
=
Flask
(
__name__
)
CORS
(
app
)
@
app
.
route
(
'/sentimental'
,
methods
=
[
'GET'
])
def
get
():
mydb
=
mysql
.
connector
.
connect
(
host
=
"localhost"
,
user
=
"root"
,
password
=
"root"
,
database
=
"inteljr"
)
mycursor
=
mydb
.
cursor
()
mycursor
.
execute
(
"SELECT * FROM conversations"
)
myresult
=
mycursor
.
fetchall
()
df
=
pd
.
DataFrame
(
myresult
)
for
index
,
row
in
df
.
iterrows
():
edu
=
TextBlob
(
row
[
4
])
x
=
edu
.
sentiment
.
polarity
if
x
<
0
:
sql
=
'''UPDATE conversations set sentimental = "
%
s" WHERE id="
%
s" '''
val
=
(
"NEGATIVE"
,
row
[
0
])
mycursor
.
execute
(
sql
,
val
)
elif
x
==
0
:
sql
=
'''UPDATE conversations set sentimental = "
%
s" WHERE id="
%
s" '''
val
=
(
"NEUTRAL"
,
row
[
0
])
mycursor
.
execute
(
sql
,
val
)
elif
x
>
0
and
x
<=
1
:
sql
=
'''UPDATE conversations set sentimental = "
%
s" WHERE id="
%
s" '''
val
=
(
"POSITIVE"
,
row
[
0
])
mycursor
.
execute
(
sql
,
val
)
mydb
.
commit
()
return
"Task is done"
if
__name__
==
"__main__"
:
app
.
run
(
debug
=
True
)
sentimental.ipynb
0 → 100644
View file @
6dad8a8b
{
"cells": [
{
"cell_type": "code",
"execution_count": 18,
"metadata": {},
"outputs": [],
"source": [
"from textblob import TextBlob\n",
"import pandas as pd\n",
"import mysql.connector\n",
"mydb = mysql.connector.connect(\n",
" host=\"localhost\",\n",
" user=\"root\",\n",
" password=\"root\",\n",
" database=\"inteljr\"\n",
")\n",
"\n",
"mycursor = mydb.cursor()\n",
"\n",
"mycursor.execute(\"SELECT * FROM conversations\")\n",
"myresult = mycursor.fetchall()\n",
"df=pd.DataFrame(myresult)\n",
"for index, row in df.iterrows():\n",
" edu=TextBlob(row[4])\n",
" x=edu.sentiment.polarity\n",
" if x<0:\n",
" sql = '''UPDATE conversations set sentimental = \"%s\" WHERE id=\"%s\" '''\n",
" val = (\"NEGETIVE\",row[0])\n",
" mycursor.execute(sql, val)\n",
" elif x==0:\n",
" sql = '''UPDATE conversations set sentimental = \"%s\" WHERE id=\"%s\" '''\n",
" val = (\"NEUTRAL\",row[0])\n",
" mycursor.execute(sql, val)\n",
" elif x>0 and x<=1:\n",
" sql = '''UPDATE conversations set sentimental = \"%s\" WHERE id=\"%s\" '''\n",
" val = (\"POSITIVE\",row[0])\n",
" mycursor.execute(sql, val)\n",
" \n",
"mydb.commit()"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": []
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": []
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": []
}
],
"metadata": {
"kernelspec": {
"display_name": "Python 3",
"language": "python",
"name": "python3"
},
"language_info": {
"codemirror_mode": {
"name": "ipython",
"version": 3
},
"file_extension": ".py",
"mimetype": "text/x-python",
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.7.6"
}
},
"nbformat": 4,
"nbformat_minor": 4
}
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment