-
Notifications
You must be signed in to change notification settings - Fork 0
/
app.py
69 lines (53 loc) · 1.78 KB
/
app.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
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
from flask import Flask, render_template, request
from flask.ext.sqlalchemy import SQLAlchemy
from flask.ext.mandrill import Mandrill
from getenv import env
from scr import *
import dotenv
dotenv.read_dotenv()
app = Flask(__name__)
app.config['SQLALCHEMY_DATABASE_URI'] = 'postgresql:///latest-package'
db = SQLAlchemy(app)
app.config['MANDRILL_API_KEY'] = env('API_KEY')
mandrill = Mandrill(app)
class User(db.Model):
__tablename__ = "users"
id = db.Column(db.Integer, primary_key=True)
email = db.Column(db.String(120), unique=True)
def __init__(self, email):
self.email = email
def __repr__(self):
return '<E-mail %r>' % self.email
# Set "homepage" to index.html
@app.route('/')
def index():
# package_finder()
# new_package_list = difference()
# list_finder()
# new_to_old()
return render_template('index.html')
# Save e-mail to database and send to success page
@app.route('/subscribe', methods=['POST'])
def subscribe():
email = None
if request.method == 'POST':
email = request.form['email']
# Check that email does not already exist (not a great query, but works)
if not db.session.query(User).filter(User.email == email).count():
reg = User(email)
db.session.add(reg)
db.session.commit()
print reg.email
mcl = call_other_functions()
print mcl
mandrill.send_email(
from_email=env('FROM_MAIL'),
to=[{'email': 'svnitvikas@gmail.com'}],
# text="hello world"
html=render_template("mail.html", mcl=mcl)
)
return render_template('success.html')
return render_template('index.html')
if __name__ == '__main__':
app.debug = True
app.run()