-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathapp.py
More file actions
67 lines (45 loc) · 1.42 KB
/
app.py
File metadata and controls
67 lines (45 loc) · 1.42 KB
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
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
from flask import Flask, render_template, request, redirect
import csv
from hn_scarape import *
def write_to_csv(data):
with open('db.csv', newline='', mode='a') as db2:
email = data['email']
subject = data['subject']
message = data['text']
csv_writer = csv.writer(db2, delimiter=',', quotechar='"', quoting=csv.QUOTE_MINIMAL)
csv_writer.writerow([email, subject, message])
app = Flask(__name__)
@app.route('/')
def home():
return render_template('index.html')
@app.route('/index.html')
def home2():
return render_template('index.html')
@app.route('/works.html')
def works():
return render_template('works.html')
@app.route('/hacker_news_scraper.html')
def scrape():
return render_template('hacker_news_scraper.html', data=scraper())
@app.route('/about.html')
def about():
return render_template('about.html')
@app.route('/contact.html')
def contact():
return render_template('contact.html')
@app.route('/thx.html')
def thx():
return render_template('thx.html')
@app.route('/submit_form', methods=['POST', 'GET'])
def submit_form():
if request.method == 'POST':
try:
data = request.form.to_dict()
write_to_csv(data)
return redirect('thx.html')
except:
return 'Did not saved to DB'
else:
return 'Something went wrong. Try again'
if __name__ == "__main__":
app.run(host='0.0.0.0')