#!/usr/bin/env python # -*- coding: utf-8 -*- """檢查資料庫中的資料""" from hbr_crawler.hbr_crawler.database import get_database_manager db = get_database_manager() result = db.execute_query('SELECT COUNT(*) as count FROM articles', database='db_A101') if result and len(result) > 0: print(f"資料庫中的文章數量: {result[0]['count']}") # 顯示最近5筆 recent = db.execute_query('SELECT id, title, url, crawled_at FROM articles ORDER BY crawled_at DESC LIMIT 5', database='db_A101') if recent: print("\n最近5筆文章:") for article in recent: title = article.get('title', '無標題') print(f" - {article['id']}: {title[:50]}...") else: print("無法查詢資料庫或資料庫中沒有資料")