Stads_Scraping/Web/WebSubscription.py

43 lines
1.1 KiB
Python
Raw Normal View History

2017-04-16 19:06:02 +00:00
#!/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)