-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathapp.py
67 lines (54 loc) · 2.28 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
from flask import Flask, render_template
from flask_script import Manager, Shell
from flask_sqlalchemy import SQLAlchemy
from flask_migrate import Migrate, MigrateCommand
from datetime import datetime
import os
basedir = os.path.abspath(os.path.dirname(__file__))
def make_shell_context():
return dict(app=app, db=db, Customer=Customer, Interaction=Interaction)
app = Flask(__name__)
app.config['SQLALCHEMY_DATABASE_URI'] = 'sqlite:///' + os.path.join(basedir, 'data.sqlite')
app.config['SQLALCHEMY_COMMIT_ON_TEARDOWN'] = True
app.config['SQLALCHEMY_TRACK_MODIFICATIONS'] = False
db = SQLAlchemy(app)
migrate = Migrate(app, db)
manager = Manager(app)
manager.add_command("shell", Shell(make_context=make_shell_context))
manager.add_command('db', MigrateCommand)
@app.route('/')
def index():
return '<h1>API Running!</h1>'
@app.errorhandler(404)
def page_not_found(e):
return render_template('404.html'), 404
@app.errorhandler(500)
def server_error(e):
return render_template('500.html'), 500
# Model definition
class Customer(db.Model):
__tablename__ = 'customers'
id = db.Column(db.Integer, primary_key=True, nullable=False)
first_name = db.Column(db.String(64), nullable=False)
last_name = db.Column(db.String(64), nullable=False)
phone = db.Column(db.String(64), unique=True, nullable=False)
email = db.Column(db.String(64), unique=True, nullable=False)
interactions = db.relationship('Interaction', backref='customer', lazy='dynamic')
def __repr__(self):
return '<Customer %r>' % self.first_name
class Interaction(db.Model):
__tablename__ = 'interactions'
id = db.Column(db.Integer, primary_key=True)
conference_sid = db.Column(db.String(64), nullable=True)
date_created = db.Column(db.String(64), nullable=True)
customer_name = db.Column(db.String(64) ,nullable=True)
worker_name = db.Column(db.String(64), nullable=True)
recording_url = db.Column(db.String(64), nullable=True)
cust_id = db.Column(db.Integer, db.ForeignKey('customers.id'))
chat_channel = db.Column(db.String(64), nullable=True)
interaction_type = db.Column(db.String(64), nullable=True)
duration = db.Column(db.Time, nullable=True)
def __repr__(self):
return '<User %r>' % self.customer_name
if __name__ == '__main__':
manager.run()