11import argparse
2- from src import make_extract , transform_article_debug , transform_article_web , load_news , init_database , create_news_tables
2+ from src import make_extract , transform_article_debug , transform_article_web , load_news , init_database , create_news_tables , load_web_pipeline , make_extract_web , make_extract_debug
33import logging
44
55logging .basicConfig (
@@ -54,19 +54,19 @@ def pipeline_for_web_user(user_id: int, search_request_id: int, key_word: str, l
5454 while num_of_news < limit :
5555 remaining = limit - num_of_news
5656 if debug :
57- raw_file_name , raw_articles_count = make_extract (key_word , page , page_size )
57+ raw_file_name , raw_articles_count = make_extract_debug (key_word , page , page_size )
5858 if raw_articles_count == 0 :
5959 logger .warning ("there is no more artical" )
6060 break
6161 clean_file_name = transform_article_debug (raw_file_name , key_word , page )
6262 result_num_of_news = load_news (clean_file_name , max_rows = remaining )
63-
64- payload , raw_articles_count = make_extract (key_word , page , page_size )
65- if raw_articles_count == 0 :
66- logger .warning ("there is no more artical" )
67- break
68- clean_file_name = transform_article_web (payload , key_word , page )
69- result_num_of_news = load_news ( clean_file_name , max_rows = remaining )
63+ else :
64+ payload , raw_articles_count = make_extract_web (key_word , page , page_size )
65+ if raw_articles_count == 0 :
66+ logger .warning ("there is no more artical" )
67+ break
68+ clean_data , stats = transform_article_web (payload )
69+ result_num_of_news = load_web_pipeline ( user_id , search_request_id , clean_data , stats )
7070
7171 num_of_news += result_num_of_news
7272 page += 1
@@ -78,23 +78,11 @@ def main()-> None:
7878 try :
7979 init_database ()
8080 create_news_tables ()
81- loaded = pipeline ()
82- logger .info ("Pipline finished. loaded rows: %s" , loaded )
83- except Exception as e :
84- logger .exception ("pipeline failed: %s" , e )
85- raise
86-
87- def main2 (user_id , search_request_id , key_word )-> None :
88- logger .info ("Starting pipeline, init database, build table.." )
89- try :
90- init_database ()
91- create_news_tables ()
92- loaded = pipeline_for_web_user (user_id ,search_request_id , key_word , 20 , 50 )
81+ loaded = pipeline_for_web_user ()
9382 logger .info ("Pipline finished. loaded rows: %s" , loaded )
9483 except Exception as e :
9584 logger .exception ("pipeline failed: %s" , e )
9685 raise
9786
98-
9987if __name__ == "__main__" :
10088 main ()
0 commit comments