From 422a16aa0c4e239b59549ab1d22b6d236a7fbbd5 Mon Sep 17 00:00:00 2001 From: KWON Date: Tue, 8 Jul 2025 14:36:09 +0900 Subject: [PATCH] =?UTF-8?q?=EB=8D=B0=EC=9D=B4=ED=84=B0=EB=B2=A0=EC=9D=B4?= =?UTF-8?q?=EC=8A=A4=20=EC=9D=B4=EB=A6=84=20=EC=88=98=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- lib/air_quality.py | 2 +- lib/ga4.py | 34 +++++++++++++++++++++------------- lib/weather_asos.py | 2 +- 3 files changed, 23 insertions(+), 15 deletions(-) diff --git a/lib/air_quality.py b/lib/air_quality.py index 6d0fc27..9d8a503 100644 --- a/lib/air_quality.py +++ b/lib/air_quality.py @@ -129,7 +129,7 @@ def main(): yesterday = (datetime.now() - timedelta(days=1)).date() engine = db.engine - table = db_schema.fg_manager_static_air + table = db_schema.air with engine.connect() as conn: for station_name in station_list: diff --git a/lib/ga4.py b/lib/ga4.py index b218d30..26b8289 100644 --- a/lib/ga4.py +++ b/lib/ga4.py @@ -156,10 +156,18 @@ def determine_date_range(table, config_start, config_end, force_update, engine): yesterday = datetime.now().date() - timedelta(days=1) actual_end = min(yesterday, config_end) latest_db_date = get_latest_date_from_db(engine, table) - if latest_db_date and not force_update: - actual_start = latest_db_date + timedelta(days=1) - else: + + if force_update: actual_start = config_start + else: + if latest_db_date is not None: + actual_start = latest_db_date + timedelta(days=1) + else: + actual_start = config_start + + if actual_start > actual_end: + return None, None + return actual_start, actual_end # ------------------------ @@ -170,8 +178,8 @@ def process_dimension_metric(engine, client, property_id, config, table, dims, m config_end = datetime.strptime(config.get("endDt", datetime.now().strftime("%Y%m%d")), "%Y%m%d").date() actual_start, actual_end = determine_date_range(table, config_start, config_end, force_update, engine) - if actual_start > actual_end: - print(f"[INFO] 이미 모든 데이터가 수집되어 있습니다: {actual_start} > {actual_end}") + if actual_start is None or actual_end is None: + print(f"[INFO] 이미 모든 데이터가 수집되어 있습니다 또는 수집 범위가 없습니다.") return for start_dt, end_dt in date_range_chunks(actual_start, actual_end, max_rows): @@ -209,15 +217,15 @@ def main(): update_config_file_with_max_rows(max_rows) tasks = [ - (db_schema.fg_manager_static_ga4_by_date, ["date"], ["activeUsers", "screenPageViews", "sessions"]), - (db_schema.fg_manager_static_ga4_by_source, ["date", "sessionSource"], ["sessions"]), - (db_schema.fg_manager_static_ga4_by_medium, ["date", "sessionMedium"], ["sessions"]), - (db_schema.fg_manager_static_ga4_by_device, ["date", "deviceCategory"], ["activeUsers"]), - (db_schema.fg_manager_static_ga4_by_country, ["date", "country"], ["activeUsers"]), - (db_schema.fg_manager_static_ga4_by_city, ["date", "city"], ["activeUsers"]) + (db_schema.ga4_by_date, ["date"], ["activeUsers", "screenPageViews", "sessions"]), + (db_schema.ga4_by_source, ["date", "sessionSource"], ["sessions"]), + (db_schema.ga4_by_medium, ["date", "sessionMedium"], ["sessions"]), + (db_schema.ga4_by_device, ["date", "deviceCategory"], ["activeUsers"]), + (db_schema.ga4_by_country, ["date", "country"], ["activeUsers"]), + (db_schema.ga4_by_city, ["date", "city"], ["activeUsers"]) ] - with ThreadPoolExecutor(max_workers=4) as executor: + with ThreadPoolExecutor(max_workers=max_workers) as executor: futures = [ executor.submit(process_dimension_metric, engine, client, property_id, ga4_cfg, table, dims, mets, max_rows, debug, force_update) @@ -229,4 +237,4 @@ def main(): print("[INFO] GA4 데이터 수집 및 저장 완료") if __name__ == '__main__': - main() \ No newline at end of file + main() diff --git a/lib/weather_asos.py b/lib/weather_asos.py index a11f76c..de28269 100644 --- a/lib/weather_asos.py +++ b/lib/weather_asos.py @@ -132,7 +132,7 @@ def main(): debug = config.get("debug", False) force_update = config.get("force_update", False) - table = db_schema.fg_manager_static_weather + table = db_schema.weather engine = db.engine now = datetime.now()