-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmodels.py
More file actions
27 lines (23 loc) · 984 Bytes
/
models.py
File metadata and controls
27 lines (23 loc) · 984 Bytes
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
from datetime import datetime
import json
from app import db
class CrawlHistory(db.Model):
"""Model for storing crawl history."""
id = db.Column(db.Integer, primary_key=True)
url = db.Column(db.String(500), nullable=False)
instructions = db.Column(db.Text, nullable=True)
result_summary = db.Column(db.String(200), nullable=True)
# Add new column for storing the full result JSON
result_data = db.Column(db.Text, nullable=True)
timestamp = db.Column(db.DateTime, default=datetime.utcnow)
def set_result_data(self, result_dict):
"""Store the crawl result as JSON in the database."""
if result_dict:
self.result_data = json.dumps(result_dict)
def get_result_data(self):
"""Retrieve the crawl result from JSON in the database."""
if self.result_data:
return json.loads(self.result_data)
return None
def __repr__(self):
return f'<CrawlHistory {self.url}>'