Created
January 31, 2023 11:59
-
-
Save nhatminhbui/818218988fd9ea00dde393b675b83c82 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from flask import Flask, render_template, request, jsonify | |
from flask_cors import CORS, cross_origin | |
import highlighter | |
from mycalendar import main as calendar_main | |
import palette | |
from urllib.request import urlopen | |
app = Flask(__name__) | |
cors = CORS(app) | |
app.config['CORS_HEADERS'] = 'Content-Type' | |
@app.route('/vn-text-highlighter') | |
def highlight(): | |
return render_template('highlighter.html') | |
@app.route('/highlighter-process',methods= ['POST']) | |
def highlighter_process(): | |
long_text = request.form['long_text'] | |
num = request.form['num'] | |
if num.isnumeric(): num = int(num) | |
else: num = 5 | |
output = highlighter.summarize(long_text, num) | |
return jsonify({'result': output}) | |
@app.route('/vn-text-highlighter/api/v1/', methods=['GET']) | |
def api_filter(): | |
query_parameters = request.args | |
num = int(query_parameters.get('num')) | |
text = query_parameters.get('text') | |
output = highlighter.summarize(text, num) | |
return jsonify({'summary': output}) | |
def just_fucking_download(file_url, save_path): | |
with urlopen(file_url) as file: content = file.read() | |
with open(save_path, 'wb') as download: download.write(content) | |
@app.route('/palette/', methods=['GET']) | |
def get_palette(): | |
query_parameters = request.args | |
img_url = query_parameters.get('img') | |
#just_fucking_download(img_url, './mysite/assets/palette/img.jpg') | |
palette_url, hex_color = palette.get_palette(img_url) | |
return """ | |
<html> | |
<img src="{}" /> | |
<br /> | |
{} | |
</html> | |
""".format(palette_url, hex_color) | |
@app.route('/calendar',methods= ['POST']) | |
@cross_origin(["https://nhatminhbui.github.io"]) | |
def get_calendar(): | |
birthdate = request.form['birthdate'] | |
img_url = calendar_main(birthdate) | |
output = '<a href={}><img id="calendar-img" src="{}" /></a>'.format(img_url, img_url) | |
return jsonify({'result': output}) | |
if __name__ == "__main__": | |
app.debug = True | |
app.run() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment