class Category(db.Model): __tablename__ = 'categories' id = db.Column(db.Integer, primary_key=True) name = db.Column(db.String(150), unique=True, nullable=False) def __init__(self, name): self.name = name
class User(db.Model): __tablename__ = 'users' id = db.Column(db.Integer, primary_key=True, autoincrement=True) email = db.Column(db.String(120), unique=True) password_hash = db.Column(db.String(128)) def __init__(self, email, password): self.email = email self.hash_password(password) def hash_password(self, password): self.password_hash = pwd_context.encrypt(password) def verify_password(self, password): return pwd_context.verify(password, self.password_hash) def generate_auth_token(self, app, expiration=600): s = Serializer(SECRET_KEY, expires_in=EXPIRATION) return s.dumps({'id': self.id}) @staticmethod def verify_auth_token(token): s = Serializer(SECRET_KEY) try: data = s.loads(token) except SignatureExpired: return None # valid token, but expired except BadSignature: return None # invalid token user = User.query.get(data['id']) return user
class CrawledRawData(db.Model): __tablename__ = 'crawled_raw_data' id = db.Column(db.Integer, primary_key=True) # This is a longtext text = db.Column(db.Text(4294000000)) def __init__(self, text): self.text = text def __repr__(self): return '<Crawled Data %r>' % (self.text)
class User(db.Model): __tablename__ = 'users' id = db.Column(db.Integer, primary_key=True) username = db.Column(db.String(64)) password = db.Column(db.String(64)) def __init__(self, username, password): self.username = username self.password = password def __repr__(self): return '<User %r>' % (self.username)
class BookmarksModel(db.Model): __tablename__ = 'bookmarks' id = db.Column(db.Integer, primary_key=True) user_id = db.Column(db.Integer, db.ForeignKey('users.id')) resource_id = db.Column(db.Integer, db.ForeignKey('resources2.id')) timestamp = db.Column(db.TIMESTAMP, nullable=False) def __init__(self, user_id, resource_id): self.user_id = user_id self.resource_id = resource_id self.timestamp = datetime.utcnow() def __repr__(self): return '<Bookmark %r>' % (self.resource_id)
class ResourceModel(db.Model): __tablename__ = 'resources' id = db.Column(db.Integer, primary_key=True) title = db.Column(db.String(64)) # Medium text link = db.Column(db.String(64000)) tags = db.Column(db.String(64)) timestamp = db.Column(db.TIMESTAMP, nullable=False) def __init__(self, title, link, tags): self.title = title self.link = link self.tags = tags self.timestamp = datetime.utcnow() def __repr__(self): return '<Resource %r>' % (self.link)
class Company(db.Model): __tablename__ = 'companies' symbol = db.Column(db.String(15), unique=True, primary_key=True) name = db.Column(db.String(250)) sector = db.Column(db.String(250)) employees = db.Column(db.Integer) market = db.Column(db.String(250)) def __init__(self, data): self.symbol = data['symbol'] self.name = data['name'] if 'sector' in data: self.sector = data['sector'] if 'employees' in data: self.employees = data['employees'] if 'market' in data: self.market = data['market']
class ReflectionModel(db.Model): __tablename__ = 'reflections' id = db.Column(db.Integer, primary_key=True) title = db.Column(db.String(240)) user_id = db.Column(db.Integer, db.ForeignKey('users.id')) reflection = db.Column(db.JSON) date_created = db.Column(db.TIMESTAMP, nullable=False) last_modified = db.Column(db.TIMESTAMP) def __init__(self, title, user_id, reflection, last_modified=None): self.title = title self.user_id = user_id self.reflection = reflection self.last_modified = last_modified self.date_created = datetime.utcnow() def __repr__(self): return '<Reflection %r>' % (self.reflection)
class Subgoal(db.Model): __tablename__ = 'subgoals' id = db.Column(db.Integer, primary_key=True) subgoal = db.Column(db.String(64)) goal_id = db.Column(db.Integer, db.ForeignKey('goals.id')) tags = db.Column(db.String(64)) timestamp = db.Column(db.TIMESTAMP, nullable=False) status = db.Column(db.String(20), default='incomplete') def __init__(self, subgoal, goal_id, tags, status): self.subgoal = subgoal self.tags = tags self.goal_id = goal_id self.status = status self.timestamp = datetime.utcnow() def __repr__(self): return '<Subgoal %r>' % (self.subgoal)
class Price(db.Model): __tablename__ = 'prices' symbol = db.Column(db.String(15), db.ForeignKey('companies.symbol', ondelete='CASCADE'), primary_key=True) date = db.Column(db.DateTime, primary_key=True) high = db.Column(db.Float, nullable=False) low = db.Column(db.Float, nullable=False) open = db.Column(db.Float, nullable=False) close = db.Column(db.Float, nullable=False) volume = db.Column(db.Float, nullable=False) company = db.relationship('Company', backref=db.backref('companies', lazy='dynamic')) def __init__(self, symbol, date, high, low, open, close, volume): self.symbol = symbol self.date = date self.high = high self.low = low self.open = open self.close = close self.volume = volume
class ResourceModel2(db.Model): __tablename__ = 'resources2' id = db.Column(db.Integer, primary_key=True) title = db.Column(db.String(240)) # Medium text link = db.Column(db.String(64000)) text = db.Column(db.Text(4294000000)) img = db.Column(db.String(240)) category = db.Column(db.String(60)) def __init__(self, title, link, text, img, category): self.title = title self.link = link self.text = text self.img = img self.category = category def __repr__(self): return '<Resource2 %r>' % (self.link)