emoji-flask-app/app.py
2022-06-20 16:10:22 -04:00

48 lines
1.4 KiB
Python

from flask import Flask, render_template, request
import advertools as ad
import pandas as pd
import json
import sys
app = Flask(__name__)
@app.route('/<string:page_name>/')
def render_static(page_name):
return render_template('%s.html' % page_name)
@app.route('/linkedin', methods=['GET', 'POST'])
def upload_file():
return render_template('linkedin.html')
@app.route('/linkedin_upload', methods=['POST'])
def linkedin_upload():
if request.method == 'POST':
print("Files:\n", file=sys.stderr)
print(dict(request.files.items()), file=sys.stderr)
print("Forms:\n", file=sys.stderr)
print(dict(request.form.items()), file=sys.stderr)
f = request.files['linkedin_csv']
type_linkedin = dict(request.form.items())['type_linkedin']
file_csv = pd.read_csv(f)
if type_linkedin == "Comments":
corpus = [str(x) for x in file_csv['Message'].tolist()]
elif type_linkedin == "Shares":
corpus = [str(x) for x in
file_csv['ShareCommentary'].tolist()]
else:
corpus = []
emoji_summary_messages = {"emoji_counts": ad.extract_emoji(corpus).get(
'top_emoji')}
print(emoji_summary_messages, file=sys.stderr)
return render_template("result.html", emoji_summary_messages=emoji_summary_messages)
if __name__ == '__main__':
app.run(debug=True)