-
Notifications
You must be signed in to change notification settings - Fork 53
/
Copy pathmodel.py
37 lines (26 loc) · 1.04 KB
/
model.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
from flask_sqlalchemy import SQLAlchemy
db = SQLAlchemy()
from datetime import datetime
class Tweet(db.Model):
"""tweets taken in to db"""
__tablename__ = "tweets"
item_id = db.Column(db.Integer, autoincrement=True, primary_key=True, nullable=False)
handle = db.Column(db.String(25), nullable=True)
time_created = db.Column(db.DateTime, nullable=True, default=datetime.utcnow)
text = db.Column(db.String(300), nullable=True)
retweets = db.Column(db.Integer, nullable=True)
def __repr__(self):
"""prettify output"""
return "<Item item_id=%s handle=%s>" % (self.item_id, self.handle)
def connect_to_db(app, db_uri):
"""Connect the database to app"""
app.config['SQLALCHEMY_DATABASE_URI'] = db_uri
app.config['DEBUG_TB_INTERCEPT_REDIRECTS'] = False
app.config['SQLALCHEMY_TRACK_MODIFICATIONS'] = False
db.app = app
db.init_app(app)
if __name__ == "__main__":
from server import app, DB_URI
connect_to_db(app, DB_URI)
db.create_all()
print("Connected to DB, Woohoo!")