-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.py
40 lines (29 loc) · 1.06 KB
/
main.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
from flask import request, flash, url_for, redirect, render_template
import app.web as web
from app import create_app, db
from app.models import ScrapeModel
app = create_app()
app.app_context().push()
@app.route('/')
def show_all():
return render_template('show_all.html', records=ScrapeModel.query.all())
@app.route('/new', methods=['GET', 'POST'])
def new():
if request.method == 'POST':
if not request.form['url'] or not request.form['keyword']:
flash('Please enter all the fields', 'error')
else:
try:
s = ScrapeModel(*web.Web().scrape(request.form['url'], request.form['keyword']))
db.session.add(s)
db.session.commit()
flash('Record was successfully added')
except:
flash('Unexpected error occurred', 'error')
finally:
db.session.close()
return redirect(url_for('show_all'))
return render_template('new.html')
if __name__ == '__main__':
db.create_all()
app.run(debug=True)