I've got my web app up and running.
However, I need to post the output of the website using render_template
To get the output to show in the text output, I have to pass it all at once. I do this using a list, but the list isn't formatted properly in the output.
My web app: http://tomshoe02.pythonanywhere.com/scraper
Sample input: https://dtmwra1jsgyb0.cloudfront.net/groups/5e223506edae743046ecdaa2/matches
An example output (screenshot): https://i.imgur.com/J2yOc3K.png
An example output: ['{{MatchSchedule|team1=UAlbany eSports|team2=Thomas Esports|team1score=2|team2score=0|winner=1|date=2020-02-07|time=13:00|timezone=PST|dst=yes|vod1=|stream=}}\n', '{{MatchSchedule|team1=King Tornado|team2=|team1score=|team2score=|winner=|date=2020-02-08|time=12:00|timezone=PST|dst=yes|vod1=|stream=}}\n', '{{Ma...
Desired output:
{{MatchSchedule|team1=UAlbany eSports|team2=Thomas Esports|team1score=2|team2score=0|winner=1|date=2020-02-07|time=13:00|timezone=PST|dst=yes|vod1=|stream=}}
{{MatchSchedule|team1=King Tornado|team2=|team1score=|team2score=|winner=|date=2020-02-08|time=12:00|timezone=PST|dst=yes|vod1=|stream=}}
app.py
from flask import Flask, render_template
from flask_wtf import FlaskForm
from wtforms import StringField, PasswordField
import os, sys, subprocess, importlib
from stuff import jloader
directory = os.path.dirname(os.path.abspath(__file__))
app = Flask(__name__)
app.config['TEMPLATES_AUTO_RELOAD'] = True
app.config['SECRET_KEY'] = 'tomisgoated'
class BattlefyForm(FlaskForm):
matchhistory = StringField('Match History Link')
@app.route("/test")
def home():
return render_template("base.html")
@app.route("/", methods=["GET", "POST"])
@app.route("/lol", methods=["GET", "POST"])
@app.route("/scraper", methods=["GET", "POST"])
def scraper():
form = BattlefyForm()
if form.validate_on_submit():
url = form.matchhistory.data
result = jloader(url)
'''
#result = url
result = subprocess.check_output([sys.executable,
"{}/stuff.py".format(directory), url]).decode('iso-8859-1')
'''
return render_template("scraper.html", form=form, result=result)
return render_template("scraper.html", form=form)
@app.route('/base', methods=["GET"])
def base():
return render_template("base.html")
@app.template_filter('nl2br')
def nl2br(s):
return s.replace("\n", "<br />")
if __name__ == "__main__":
app.run(debug = True)
stuff.py: https://www.codepile.net/pile/Ore8pj5e
list1 = ['a','b','c']
print("\n".join(list1))
Additional discussion around this here: https://stackoverflow.com/a/3971100/12939068
<div>
{% for item in list %}
<div>{{ item }}</div>
{% endfor %}
</div>
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.