diff --git a/mycode/main.py b/mycode/main.py index 60cbe06..7adf7d1 100644 --- a/mycode/main.py +++ b/mycode/main.py @@ -111,43 +111,46 @@ def get_cbma_info_from_db_and_ana(year: str = '2023'): df = pd.read_sql_query(query_gzhs, conn) conn.close() - # 尝试连接官网库进行查询 - import psycopg2 - conn_web = None - df_web = None - try: - conn_web = psycopg2.connect( - "dbname={} user={} password={} host={} port={}".format('edn_cms', 'auditor', 'Lde78B3_cbma', '10.65.253.10', '54321')) - query_web = f""" - SELECT - a_outer.id, - TO_CHAR(a_outer.ctime, 'YYYY') AS pub_year, - TO_CHAR(a_outer.ctime, 'MM') AS pub_month, - TO_CHAR(a_outer.ctime, 'DD') AS pub_day, - a_outer.title, - a_outer.source, - a_outer.hits, - t.title as bankuai, - a_outer.src - FROM - "a_article" a_outer - left join ( - select id, title, father, path - from a_article - where father in (20110528, 19080024) - ) t on a_outer.father = t.id - WHERE - a_outer.TYPE = 3 - and a_outer.deleted is NULL - and EXTRACT ( YEAR FROM a_outer.ctime ) = {year} - and bankuai is not NULL - ORDER BY - a_outer.ctime; - """ - df_web = pd.read_sql_query(query_web, conn_web) - conn_web.close() - except Exception as e: - print(e) + file_path = os.path.join(BASE_DIR, f'cbma_site/{year}.xlsx') + if os.path.exists(file_path): + df_web = pd.read_excel(file_path, sheet_name='Result 1') + else: + import psycopg2 + conn_web = None + df_web = None + try: + conn_web = psycopg2.connect( + "dbname={} user={} password={} host={} port={}".format('edn_cms', 'auditor', 'Lde78B3_cbma', '10.65.253.10', '54321')) + query_web = f""" + SELECT + a_outer.id, + TO_CHAR(a_outer.ctime, 'YYYY') AS pub_year, + TO_CHAR(a_outer.ctime, 'MM') AS pub_month, + TO_CHAR(a_outer.ctime, 'DD') AS pub_day, + a_outer.title, + a_outer.source, + a_outer.hits, + t.title as bankuai, + a_outer.src + FROM + "a_article" a_outer + left join ( + select id, title, father, path + from a_article + where father in (20110528, 19080024) + ) t on a_outer.father = t.id + WHERE + a_outer.TYPE = 3 + and a_outer.deleted is NULL + and EXTRACT ( YEAR FROM a_outer.ctime ) = {year} + and bankuai is not NULL + ORDER BY + a_outer.ctime; + """ + df_web = pd.read_sql_query(query_web, conn_web) + conn_web.close() + except Exception as e: + print(e) df['source'] = '' # 追加总院数据来源