updated interface
This commit is contained in:
parent
ff9343a5ab
commit
fde88b9648
25
app.py
25
app.py
|
@ -1,14 +1,31 @@
|
|||
from flask import Flask, render_template, request
|
||||
from bs4 import BeautifulSoup
|
||||
import urllib, requests
|
||||
app = Flask(__name__)
|
||||
|
||||
@app.route('/')
|
||||
def main():
|
||||
return render_template('index.html', svg="")
|
||||
return render_template('index.html', svg="", name="")
|
||||
|
||||
@app.route('/submit_kanji', methods=['GET'])
|
||||
def submit_kanji():
|
||||
try:
|
||||
with open(f"assets/0{format(ord(request.args.get('kanji')), 'x')}.svg", encoding='utf-8') as file:
|
||||
return render_template('index.html', svg=file.read())
|
||||
character = request.args.get('kanji')
|
||||
|
||||
url = "https://jisho.org/search/{0}".format(urllib.parse.quote_plus(character + "#kanji"))
|
||||
r = requests.get(url, headers={
|
||||
"User-Agent": "little-web-project",
|
||||
"From": "http://lauchism.com"
|
||||
})
|
||||
|
||||
if r.status_code != 200:
|
||||
print(f"ERROR: Failed to access Jisho API... {r.status_code}")
|
||||
return None
|
||||
|
||||
body = BeautifulSoup(r.text, features="html.parser")
|
||||
names = body.find("div", {"class": "kanji-details__main-meanings"})
|
||||
|
||||
with open(f"assets/0{format(ord(character), 'x')}.svg", encoding='utf-8') as file:
|
||||
return render_template('index.html', svg=file.read(), name=names.string)
|
||||
except:
|
||||
return render_template('index.html', svg="no")
|
||||
return render_template('index.html', svg="no", name="no")
|
|
@ -31,6 +31,7 @@
|
|||
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.5.1/jquery.min.js"></script>
|
||||
</head>
|
||||
<body>
|
||||
<h1>search for kanji</h1>
|
||||
<form action="{{ url_for('submit_kanji') }}" method="get">
|
||||
<input type="text" name="kanji">
|
||||
<input type="submit">
|
||||
|
@ -39,6 +40,10 @@
|
|||
{{svg|safe}}
|
||||
</span>
|
||||
|
||||
<h2>
|
||||
{{name}}
|
||||
</h2>
|
||||
|
||||
<script>
|
||||
var allParts = $("svg > g > g *[kvg\\:element]");
|
||||
|
||||
|
|
Loading…
Reference in a new issue