Jan-03-2020, 09:43 AM
I get the data from the database and I want to display sentence only. But, instead..it just display id and also sentence in one column. Example table output that I got:
------------------------------
Word
------------------------------
{'id': '1', 'q': '- Happy'}
Example table output that I want to display:
------------------------------
Word
------------------------------
Happy
I want to remove id ('id': '1')and just display word, in this case(Happy)
My code in app.py:
------------------------------
Word
------------------------------
{'id': '1', 'q': '- Happy'}
Example table output that I want to display:
------------------------------
Word
------------------------------
Happy
I want to remove id ('id': '1')and just display word, in this case(Happy)
My code in app.py:
def programs(id): # Create cursor cur = mysql.connection.cursor() # Get articles result = cur.execute("SELECT id,y FROM table WHERE id = %s", [id]) data = cur.fetchall() values = [] for i in data: sid_obj = SentimentIntensityAnalyzer() sentiment_dict = sid_obj.polarity_scores(i) if sentiment_dict['compound'] >= 0.05 : sentiment = 'positive' elif sentiment_dict['compound'] <= - 0.05 : sentiment = 'negative' else : sentiment = 'neutral' values.append({"y": i, "sentiment": sentiment, "sentiment_dict": sentiment_dict}) if result > 0: return render_template('programs.html', data=values) else: msg = 'No Results Found' return render_template('programs.html', msg=msg)Code in html:
{% for j in data%} <tr> <td>{{j.y}}</td> <td>{{j.sentiment}}</td> <td>{{j.sentiment_dict}}</td> </tr> {% endfor %}