-
Notifications
You must be signed in to change notification settings - Fork 0
/
server.py
50 lines (39 loc) · 1.29 KB
/
server.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
41
42
43
44
45
46
47
48
49
50
from flask import Flask, render_template, url_for, request, redirect
import os
import csv
app = Flask(__name__)
@app.route('/')
def my_home():
return render_template('index.html')
@app.route('/<string:page_name>')
def html_page(page_name):
try:
return render_template(page_name)
except Exception:
return render_template('/404.html')
def db(data):
if os.path.isfile('database.txt'):
with open('database.txt', 'a') as db:
email = data['email']
subject = data['subject']
msg = data['message']
db.write(f'\n{email}\t\t\t{subject}\t\t\t{msg}\t\t\t')
def db_csv(data):
if os.path.isfile('database.csv'):
with open('database.csv', 'a') as db:
email = data['email']
subject = data['subject']
msg = data['message']
csv_writer = csv.writer(db, delimiter=',', quotechar='"', quoting=csv.QUOTE_MINIMAL)
csv_writer.writerow([email, subject, msg])
@app.route('/submit', methods=['POST', 'GET'])
def submit():
if request.method == 'POST':
data = request.form.to_dict()
# db(data)
db_csv(data)
return redirect("/thankyou.html")
else:
return redirect("/error.html")
if __name__ == "__main__":
app.run(debug=True)