Exemplo n.º 1
0
class News(db.Model):

    news_id = db.Column(db.Integer, primary_key=True)
    heading = db.Column(db.String(40), nullable=False)
    description = db.Column(db.String(1000), nullable=False)
    # many to one relation with User model
    user_id = db.Column(db.Integer, db.ForeignKey('user.user_id'))
class Feedback(db.Model):
    __tablename__ = 'feedback'

    id = db.Column(db.Integer, primary_key=True)
    text = db.Column(db.Text, nullable=False)
    date = db.Column(db.DateTime, default=datetime.now())

    def __repr__(self):
        return f"Feedback {self.id}, {self.text}, {self.date}"
Exemplo n.º 3
0
class User(db.Model, UserMixin):
    id = db.Column(db.Integer, primary_key=True)
    first_name = db.Column(db.String(20), nullable=False)
    last_name = db.Column(db.String(20), nullable=False)
    email = db.Column(db.String(120), unique=True, nullable=False)
    password = db.Column(db.String(60), nullable=False)

    def __repr__(self):
        return f"User('{self.id}', '{self.first_name}', '{self.last_name}', '{self.email}')"
Exemplo n.º 4
0
class Timeline(db.Model):
    __tablename__ = 'timeline'

    id = db.Column(db.Integer, primary_key=True)
    headline = db.Column(db.Text, unique=True)
    link = db.Column(db.Text)
    user_id = db.Column(db.Integer, db.ForeignKey('user.id'))

    def __repr__(self):
        return f"Timeline {self.id}, {self.headline}"
Exemplo n.º 5
0
class NewsCategory(db.Model, Serializer):
    __tablename__ = "NewsCategory"
    id = db.Column(db.Integer, primary_key=True)
    name = db.Column(db.String(1024), nullable=False)

    def serialize(self):
        exclude = []
        d = Serializer.serialize(self)
        [d.pop(attr, None) for attr in exclude]
        d['sources'] = NewsSource.serialize_list(self.sources, uw_style=1)
        return d
Exemplo n.º 6
0
class User(db.Model):
    __tablename__: 'user'

    id = db.Column(db.Integer, primary_key=True)
    username = db.Column(db.String(64), nullable=False)
    location = db.Column(db.String(64))
    timelines = db.relationship('Timeline',
                                backref='user',
                                cascade='all, delete')

    def __repr__(self):
        return f"User {self.id}, {self.username}"
Exemplo n.º 7
0
class Sentiment(db.Model):
    __tablename__ = 'sentiment'

    id = db.Column(db.Integer, primary_key=True)
    type = db.Column(db.String(32))
    timeline_headline = db.Column(db.Text, db.ForeignKey('timeline.headline'))
    timeline = db.relationship('Timeline',
                               backref='sentiment',
                               cascade='all, delete')

    def __repr__(self):
        return f"Sentiment {self.id}, {self.type}"
Exemplo n.º 8
0
class NewsSource(db.Model, Serializer):
    __tablename__ = "NewsSource"
    id = db.Column(db.Integer, primary_key=True, autoincrement=True)
    url = db.Column(db.String(1024), nullable=False)
    name = db.Column(db.String(1024), nullable=False)
    uw_style = db.Column(db.Boolean, nullable=False)
    category_id = db.Column(db.Integer, db.ForeignKey('NewsCategory.id', ondelete='CASCADE'))
    category = db.relationship('NewsCategory', backref=db.backref('sources'))

    def serialize(self):
        exclude = ['url', 'uw_style', 'category_id', 'category']
        d = Serializer.serialize(self)
        [d.pop(attr, None) for attr in exclude]
        return d
Exemplo n.º 9
0
class User(db.Model, UserMixin):

    user_id = db.Column(db.Integer, primary_key=True)
    email = db.Column(db.String(60), nullable=False, unique=True)
    password = db.Column(db.String(130), nullable=False)
    is_admin = db.Column(db.Boolean, default=False)
    news = db.relationship('News')

    # get the id of the user (need to return id as inheriting UserMixin)
    def get_id(self):
        return f'{self.user_id}'

    # store the password in hashed format
    def set_password(self, password):
        self.password = generate_password_hash(password, method='sha256')

    # check the password and stored hashed password
    def get_password(self, password):
        return check_password_hash(self.password, password)
Exemplo n.º 10
0
class User(db.Model, UserMixin):
    id = db.Column(db.Integer, primary_key=True)
    username = db.Column(db.String(20), nullable=False, unique=True)
    email = db.Column(db.String(50), nullable=False, unique=True)
    password = db.Column(db.String(100), nullable=False)

    def get_reset_token(self, expired_seconds=1800):
        s = Serializer(app.config['SECRET_KEY'], expired_seconds)
        return s.dumps({'user_id': self.id}).decode('utf-8')

    @staticmethod
    def verify_reset_token(token):
        s = Serializer(app.config['SECRET_KEY'])
        try:
            user_id = s.loads(token)['user_id']
            return User.query.get(user_id)
        except:
            return None

    def __repr__(self) -> str:
        return f'User({self.username}, {self.email})'
Exemplo n.º 11
0
class Company(db.Model):
    __tablename__ = 'company'
    id = db.Column(db.Integer, primary_key=True)
    name = db.Column(db.String(30), unique=True, nullable=False)
    base_url = db.Column(db.String(100), unique=True)
    html_element = db.Column(db.String(20), nullable=False)
    element_class = db.Column(db.String(50))
    html_label = db.Column(db.String(20))
    label_class = db.Column(db.String(50))
    news = db.relationship('News', backref='author', lazy=True)

    def __repr__(self) -> str:
        return f'Company({self.name}, {self.base_url})'
Exemplo n.º 12
0
class News(db.Model):
    __tablename__ = 'news'
    id = db.Column(db.Integer, primary_key=True)
    title = db.Column(db.String(200), nullable=False)
    category = db.Column(db.String(30))
    relevance = db.Column(db.Integer)
    url = db.Column(db.String(200))
    posted_at = db.Column(db.DateTime(), default=datetime.utcnow)
    company_id = db.Column(db.Integer,
                           db.ForeignKey('company.id'),
                           nullable=False)

    def __repr__(self) -> str:
        return f'News({self.title}, {self.posted_at})'
Exemplo n.º 13
0
class User(db.Model, Serializer):
    __tablename__ = "User"
    id = db.Column(db.Integer, primary_key=True, autoincrement=True)
    name = db.Column(db.String(20))
    username = db.Column(db.String(20), unique=True, nullable=False)
    password_hash = db.Column(db.String(128), nullable=False)
    gender = db.Column(db.Integer)
    faculty = db.Column(db.String(128))
    department = db.Column(db.String(128))
    following = db.Column(db.String(1000))
    admin = db.Column(db.Boolean, nullable=False)

    def set_password(self, password):
        self.password_hash = generate_password_hash(password)

    def verify_password(self, password):
        return check_password_hash(self.password_hash, password)

    def serialize(self):
        exclude = ['password_hash', 'admin']
        d = Serializer.serialize(self)
        [d.pop(attr, None) for attr in exclude]
        return d
Exemplo n.º 14
0
class News(db.Model, Serializer):
    __tablename__ = "News"
    url = db.Column(db.String(256), primary_key=True)
    source_id = db.Column(db.Integer, db.ForeignKey('NewsSource.id', ondelete='CASCADE'), primary_key=True)
    source = db.relationship('NewsSource')
    title = db.Column(db.String(512))
    abstract = db.Column(db.String(2048))
    image_url = db.Column(db.String(256))
    date = db.Column(db.Date, index=True)

    def serialize(self):
        d = Serializer.serialize(self)
        d['source'] = self.source.name
        return d
Exemplo n.º 15
0
class Category(db.Model):

    category_name = db.Column(db.String(30), primary_key=True)
    news = db.relationship('News', secondary=news_category)
Exemplo n.º 16
0
from werkzeug.security import check_password_hash, generate_password_hash

from news_app import db
from flask_login import UserMixin

# many-to-many relation between category and news model
news_category = db.Table(
    'news_category',
    db.Column('news_id', db.Integer, db.ForeignKey('news.news_id')),
    db.Column('category_name', db.String(29),
              db.ForeignKey('category.category_name')),
)


# News table model
class News(db.Model):

    news_id = db.Column(db.Integer, primary_key=True)
    heading = db.Column(db.String(40), nullable=False)
    description = db.Column(db.String(1000), nullable=False)
    # many to one relation with User model
    user_id = db.Column(db.Integer, db.ForeignKey('user.user_id'))


# category table model
class Category(db.Model):

    category_name = db.Column(db.String(30), primary_key=True)
    news = db.relationship('News', secondary=news_category)