'updated_python_code'

parent dcd61da2
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)
{
"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
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment