43 lines
1.1 KiB
Python
43 lines
1.1 KiB
Python
#!/bin/python3
|
|
import sqlite3
|
|
from flask import Flask, session, redirect, url_for, escape, request
|
|
app = Flask(__name__)
|
|
|
|
conn = sqlite3.connect('../mailing_list')
|
|
c = conn.cursor()
|
|
|
|
@app.route('/subscribe')
|
|
def login():
|
|
return '''
|
|
<form action="/added_email" method="POST">
|
|
<p> Enter information and click submit, in order to subscribe to the mailing list </p>
|
|
<input type="text" name="email" placeholder="Enter Email Address" style="width:10%"></input>
|
|
<br>
|
|
<p> Pick study</p>
|
|
<select name="studie" style="width:10%">
|
|
<option value=""></option>
|
|
<option value="Datalogi">Datalogi</option>
|
|
</select>
|
|
<br><br>
|
|
<input type="submit" value="Submit">
|
|
</form>
|
|
'''
|
|
|
|
|
|
@app.route('/added_email', methods=['POST'])
|
|
def hello():
|
|
|
|
email = request.form['email']
|
|
studie = request.form['studie']
|
|
|
|
query = "insert into mails (email, studie) values (?, ?)"
|
|
c.execute(query, (email, studie))
|
|
conn.commit()
|
|
conn.close()
|
|
return 'I inserted: %s and %s, into the database' % (email, studie)
|
|
|
|
|
|
|
|
if __name__ == '__main__':
|
|
app.run(port=2047)
|