77"""
88
99import os
10- import logging
1110import time
1211import threading
1312from typing import List , Optional
13+ from loguru import logger
1414
1515from gentrade .scraper .extractor import ArticleContentExtractor
1616
1919from gentrade .news .rss import RssProvider
2020from gentrade .news .finnhub import FinnhubNewsProvider
2121
22- LOG = logging .getLogger (__name__ )
23-
2422
2523class NewsFactory :
2624 """Factory class for creating news provider instances based on provider type.
@@ -99,15 +97,15 @@ def _fetch_thread(self, provider, aggregator, ticker, category,
9997 news = provider .fetch_stock_news (
10098 ticker , category , max_hour_interval , max_count
10199 )
102- LOG .info (
100+ logger .info (
103101 f"Fetched { len (news )} stock news articles for { ticker } from "
104102 f"{ provider .__class__ .__name__ } "
105103 )
106104 else :
107105 news = provider .fetch_latest_market_news (
108106 category , max_hour_interval , max_count
109107 )
110- LOG .info (
108+ logger .info (
111109 f"Fetched { len (news )} market news articles from "
112110 f"{ provider .__class__ .__name__ } "
113111 )
@@ -117,7 +115,7 @@ def _fetch_thread(self, provider, aggregator, ticker, category,
117115 item .summary = ace .clean_html (item .summary )
118116 if is_process :
119117 item .content = ace .extract_content (item .url )
120- LOG .info (item .content )
118+ logger .info (item .content )
121119
122120 with aggregator .db_lock :
123121 aggregator .db .add_news (news )
@@ -142,10 +140,10 @@ def sync_news(
142140 """
143141 current_time = time .time ()
144142 if current_time < self .db .last_sync + 3600 :
145- LOG .info ("Skipping sync: Last sync was less than 1 hour ago." )
143+ logger .info ("Skipping sync: Last sync was less than 1 hour ago." )
146144 return
147145
148- LOG .info ("Starting news sync..." )
146+ logger .info ("Starting news sync..." )
149147
150148 threads = []
151149 for provider in self .providers :
@@ -160,10 +158,9 @@ def sync_news(
160158 thread .join ()
161159
162160 self .db .last_sync = current_time
163- LOG .info ("News sync completed." )
161+ logger .info ("News sync completed." )
164162
165163if __name__ == "__main__" :
166- logging .basicConfig (level = logging .INFO )
167164 db = NewsDatabase ()
168165
169166 try :
@@ -186,18 +183,18 @@ def sync_news(
186183
187184 # Log results
188185 all_news = db .get_all_news ()
189- LOG .info (f"Total articles in database: { len (all_news )} " )
186+ logger .info (f"Total articles in database: { len (all_news )} " )
190187
191188 if all_news :
192- LOG .info ("Example article:" )
193- LOG .info (all_news [0 ].to_dict ())
189+ logger .info ("Example article:" )
190+ logger .info (all_news [0 ].to_dict ())
194191
195192 for news_item in all_news :
196- LOG .info ("--------------------------------" )
193+ logger .info ("--------------------------------" )
197194 print (news_item .headline )
198195 print (news_item .url )
199196 print (news_item .content )
200- LOG .info ("--------------------------------" )
197+ logger .info ("--------------------------------" )
201198
202199 except ValueError as e :
203- LOG .error (f"Error during news aggregation: { e } " )
200+ logger .error (f"Error during news aggregation: { e } " )
0 commit comments