gogo
This commit is contained in:
54
src/cache.py
54
src/cache.py
@@ -74,6 +74,26 @@ class CacheManager:
|
||||
)
|
||||
""")
|
||||
|
||||
# Add new columns to auctions table if they don't exist
|
||||
cursor = conn.execute("PRAGMA table_info(auctions)")
|
||||
auction_columns = {row[1] for row in cursor.fetchall()}
|
||||
|
||||
if 'city' not in auction_columns:
|
||||
conn.execute("ALTER TABLE auctions ADD COLUMN city TEXT")
|
||||
if 'country' not in auction_columns:
|
||||
conn.execute("ALTER TABLE auctions ADD COLUMN country TEXT")
|
||||
if 'type' not in auction_columns:
|
||||
conn.execute("ALTER TABLE auctions ADD COLUMN type TEXT")
|
||||
if 'lot_count' not in auction_columns:
|
||||
conn.execute("ALTER TABLE auctions ADD COLUMN lot_count INTEGER DEFAULT 0")
|
||||
if 'closing_time' not in auction_columns:
|
||||
conn.execute("ALTER TABLE auctions ADD COLUMN closing_time TEXT")
|
||||
if 'discovered_at' not in auction_columns:
|
||||
conn.execute("ALTER TABLE auctions ADD COLUMN discovered_at INTEGER")
|
||||
|
||||
# Add index for country filtering
|
||||
conn.execute("CREATE INDEX IF NOT EXISTS idx_auctions_country ON auctions(country)")
|
||||
|
||||
# Add new columns to lots table if they don't exist
|
||||
cursor = conn.execute("PRAGMA table_info(lots)")
|
||||
columns = {row[1] for row in cursor.fetchall()}
|
||||
@@ -126,6 +146,8 @@ class CacheManager:
|
||||
conn.execute("ALTER TABLE lots ADD COLUMN lot_condition TEXT")
|
||||
if 'appearance' not in columns:
|
||||
conn.execute("ALTER TABLE lots ADD COLUMN appearance TEXT")
|
||||
if 'scraped_at_timestamp' not in columns:
|
||||
conn.execute("ALTER TABLE lots ADD COLUMN scraped_at_timestamp INTEGER")
|
||||
|
||||
# Create bid_history table
|
||||
conn.execute("""
|
||||
@@ -224,19 +246,36 @@ class CacheManager:
|
||||
|
||||
def save_auction(self, auction_data: Dict):
|
||||
"""Save auction data to database"""
|
||||
# Parse location into city and country
|
||||
location = auction_data.get('location', '')
|
||||
city = None
|
||||
country = None
|
||||
if location:
|
||||
parts = [p.strip() for p in location.split(',')]
|
||||
if len(parts) >= 2:
|
||||
city = parts[0]
|
||||
country = parts[-1]
|
||||
|
||||
with sqlite3.connect(self.db_path) as conn:
|
||||
conn.execute("""
|
||||
INSERT OR REPLACE INTO auctions
|
||||
(auction_id, url, title, location, lots_count, first_lot_closing_time, scraped_at)
|
||||
VALUES (?, ?, ?, ?, ?, ?, ?)
|
||||
(auction_id, url, title, location, lots_count, first_lot_closing_time, scraped_at,
|
||||
city, country, type, lot_count, closing_time, discovered_at)
|
||||
VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)
|
||||
""", (
|
||||
auction_data['auction_id'],
|
||||
auction_data['url'],
|
||||
auction_data['title'],
|
||||
auction_data['location'],
|
||||
location,
|
||||
auction_data.get('lots_count', 0),
|
||||
auction_data.get('first_lot_closing_time', ''),
|
||||
auction_data['scraped_at']
|
||||
auction_data['scraped_at'],
|
||||
city,
|
||||
country,
|
||||
'online', # Troostwijk is online platform
|
||||
auction_data.get('lots_count', 0), # Duplicate to lot_count for consistency
|
||||
auction_data.get('first_lot_closing_time', ''), # Use first_lot_closing_time as closing_time
|
||||
int(time.time())
|
||||
))
|
||||
conn.commit()
|
||||
|
||||
@@ -252,8 +291,8 @@ class CacheManager:
|
||||
year_manufactured, condition_score, condition_description,
|
||||
serial_number, manufacturer, damage_description,
|
||||
followers_count, estimated_min_price, estimated_max_price, lot_condition, appearance,
|
||||
scraped_at)
|
||||
VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)
|
||||
scraped_at, scraped_at_timestamp)
|
||||
VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)
|
||||
""", (
|
||||
lot_data['lot_id'],
|
||||
lot_data.get('auction_id', ''),
|
||||
@@ -288,7 +327,8 @@ class CacheManager:
|
||||
lot_data.get('estimated_max_price'),
|
||||
lot_data.get('lot_condition', ''),
|
||||
lot_data.get('appearance', ''),
|
||||
lot_data['scraped_at']
|
||||
lot_data['scraped_at'],
|
||||
int(time.time())
|
||||
))
|
||||
conn.commit()
|
||||
|
||||
|
||||
Reference in New Issue
Block a user