-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdatabase.py
More file actions
34 lines (29 loc) · 1.31 KB
/
database.py
File metadata and controls
34 lines (29 loc) · 1.31 KB
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
from flask_sqlalchemy import SQLAlchemy
from sqlalchemy import func
from datetime import datetime
db = SQLAlchemy()
class SecurityNews(db.Model):
__tablename__ = 'security_news'
id = db.Column(db.Integer, primary_key=True)
title = db.Column(db.String(500), nullable=False)
source = db.Column(db.String(100), nullable=False) # Bleeping Computer, Dark Reading, etc.
url = db.Column(db.String(500), unique=True, nullable=False)
description = db.Column(db.Text)
severity = db.Column(db.String(20), default='medium') # critical, high, medium, low
published_date = db.Column(db.DateTime, default=datetime.utcnow)
added_date = db.Column(db.DateTime, default=datetime.utcnow)
category = db.Column(db.String(100)) # vulnerability, breach, alert, news
sent_to_whatsapp = db.Column(db.Boolean, default=False)
def to_dict(self):
return {
'id': self.id,
'title': self.title,
'source': self.source,
'url': self.url,
'description': self.description,
'severity': self.severity,
'published_date': self.published_date.strftime('%Y-%m-%d %H:%M') if self.published_date else '',
'category': self.category
}
def __repr__(self):
return f'<SecurityNews {self.id}: {self.title[:50]}>'