from datetime import datetime, timedelta from pathlib import Path from typing import Optional from common import common_config from utils.conf import var FLOW_DIR = Path(__file__).parent QUERIES_DIR = FLOW_DIR / 'queries' FLOW_NAME = 'youtube_monthly' DROP_S3_BUCKET = var('YOUTUBE_MONTHLY_DROP_S3_BUCKET', common_config.COMMON_SFTP_S3_BUCKET) DROP_S3_KEY_PATH = var('YOUTUBE_MONTHLY_DROP_S3_KEY_PATH', 'ftp/youtube/') ARCHIVE_S3_BUCKET = var('COMMON_ARCHIVE_S3_BUCKET', common_config.COMMON_ARCHIVE_S3_BUCKET) ARCHIVE_S3_KEY_PATH_TEMPLATE = var('YOUTUBE_MONTHLY_ARCHIVE_S3_KEY_PATH_TEMPLATE', 'YouTubeMonthly/reports/{report_name}/{date:%Y-%m-%d}/') AWS_DROP_BUCKET_CONN_ID = var('YOUTUBE_MONTHLY_AWS_DROP_BUCKET_CONN_ID', common_config.COMMON_AWS_CONN_ID) AWS_ARCHIVE_BUCKET_CONN_ID = var('YOUTUBE_MONTHLY_AWS_ARCHIVE_BUCKET_CONN_ID', common_config.COMMON_AWS_CONN_ID) # deadline for data to be ingested DATA_THRESHOLD = timedelta(days=20) # usual deley for data from provider DATA_DELAY = timedelta(days=10) def report_id(report_name: str, sub_report_name: Optional[str]=None): if sub_report_name: return f'{report_name}__{sub_report_name}' return report_name def stagin_raw_table_name(report_name: str, sub_report_name: Optional[str]=None): return f'staging_raw_youtube_monthly_{report_id(report_name, sub_report_name)}' def subreport_csv_filename(report_name: str, sub_report_name: str): return f'{report_id(report_name, sub_report_name)}.csv' reports = { # 'legacy_monthly': { # # Legacy 'monthly' report # # the data overlapped with 'rawdata_v1_0' report below # # YouTube_dmgi_M_20220801_20220831_rawdata_v1-0.csv.zip # # YouTube_theorchardmusic_M_20220701_20220731_rawdata_v1-0.csv.gz # 'file_pattern': 'YouTube_{account}_M_{start_date:%Y%m%d}_{end_date:%Y%m%d}_rawdata_v1-0.csv{compression}', # noqa: E501 # 'staging_raw_table': 'staging_raw_youtube_monthly_v2', # 'accounts': { # 'dmgi': { # 'compression': '.zip' # }, # 'theorchardmusic': { # 'compression': '.gz' # }, # } # }, 'label_ap_report': { 'file_pattern': 'YouTube_263000_{account}_label_AP_{start_date:%Y%m%d}_report.csv', # NOQA: E501 'accounts': { 'theorchardmusic': {} } }, 'adjustment_red_music_rawdata_video_v1_1': { 'file_pattern': 'YouTube_{account}_M_{start_date:%Y%m%d}_{end_date:%Y%m%d}_adjustment_red_music_rawdata_video_v1-1.csv.gz', # noqa: E501 'staging_raw_table': None, 'subreports': { 'video_claim_raw_report': { 'report_title': 'Video Claim Raw Report', 'file_pattern': 'YouTube_{account}_M_{start_date:%Y%m%d}_{end_date:%Y%m%d}_adjustment_red_music_rawdata_video_v1-1__video_claim_raw_report.csv', # noqa: E501 'staging_raw_table': 'staging_raw_youtube_monthly_adjustment_red_music_rawdata_video_v1_1__video_claim_raw_report' # noqa: E501 } }, 'accounts': { 'dmgi': { 'dag_args': dict( start_date=datetime(2021, 5, 1), ), } } }, 'fake_report': { 'file_pattern': 'ouTube_{account}_M_{start_date:%Y%m%d}_{end_date:%Y%m%d}_adjustment_red_music_rawdata_video_v1-1.csv.gz', # noqa: E501 'accounts': { 'dmgi': { 'dag_args': dict( start_date=datetime(2022, 8, 1), max_active_runs=10, ), } } }, 'red_rawdata_video_v1_1': { 'file_pattern': 'YouTube_{account}_M_{start_date:%Y%m%d}_{end_date:%Y%m%d}_red_rawdata_video_v1-1.csv.gz', # noqa: E501 'staging_raw_table': None, 'subreports': { 'video_claim_raw_report': { 'report_title': 'Video Claim Raw Report', 'file_pattern': 'YouTube_{account}_M_{start_date:%Y%m%d}_{end_date:%Y%m%d}_red_rawdata_video_v1-1__video_claim_raw_report.csv', # noqa: E501 'staging_raw_table': 'staging_raw_youtube_monthly_red_rawdata_video_v1_1__video_claim_raw_report' # noqa: E501 } }, 'accounts': { 'dmgi': {} } }, 'red_music_rawdata_video_v1_1': { 'file_pattern': 'YouTube_{account}_M_{start_date:%Y%m%d}_{end_date:%Y%m%d}_red_music_rawdata_video_v1-1.csv.gz', # noqa: E501 'staging_raw_table': None, 'subreports': { 'video_claim_raw_report': { 'report_title': 'Video Claim Raw Report', 'file_pattern': 'YouTube_{account}_M_{start_date:%Y%m%d}_{end_date:%Y%m%d}_red_music_rawdata_video_v1-1__video_claim_raw_report.csv', # noqa: E501 'staging_raw_table': 'staging_raw_youtube_monthly_red_music_rawdata_video_v1_1__video_claim_raw_report' # noqa: E501 } }, 'accounts': { 'dmgi': {} } }, 'red_summary_v1_1': { 'file_pattern': 'YouTube_{account}_M_{start_date:%Y%m%d}_{end_date:%Y%m%d}_red_summary_v1-1.csv.gz', # noqa: E501 'staging_raw_table': None, 'subreports': { 'non_music_summary': { 'report_title': 'Non Music Summary', }, 'music_summary': { 'report_title': 'Music Summary', } }, 'accounts': { 'dmgi': {} } }, 'adjustment_red_rawdata_video_v1_1': { 'file_pattern': 'YouTube_{account}_M_{start_date:%Y%m%d}_{end_date:%Y%m%d}_adjustment_red_rawdata_video_v1-1.csv.gz', # noqa: E501 'staging_raw_table': None, 'subreports': { 'video_claim_raw_report': { 'report_title': 'Video Claim Raw Report', 'file_pattern': 'YouTube_{account}_M_{start_date:%Y%m%d}_{end_date:%Y%m%d}_adjustment_red_rawdata_video_v1-1__video_claim_raw_report.csv', # noqa: E501 'staging_raw_table': 'staging_raw_youtube_monthly_adjustment_red_rawdata_video_v1_1__video_claim_raw_report' # noqa: E501 } }, 'accounts': { 'theorchardmusic': {} } }, 'videoclaim_rawdata_v1_0': { 'file_pattern': 'YouTube_{account}_M_{start_date:%Y%m%d}_{end_date:%Y%m%d}_videoclaim_rawdata_v1-0.csv.gz', # noqa: E501 'staging_raw_table': 'staging_raw_youtube_monthly_videoclaim_rawdata_v1_0', # noqa: E501 'accounts': { 'theorchardmusic': {} } }, 'adj_claim_summary_v1_1': { 'file_pattern': 'YouTube_{account}_M_{start_date:%Y%m%d}_ADJ_claim_summary_v1-1.csv.gz', # noqa: E501 'staging_raw_table': 'staging_raw_youtube_monthly_adj_claim_summary_v1_1', # noqa: E501 'accounts': { 'theorchardmusic': {} } }, 'adjustment_red_label_rawdata_video_v1_1': { 'file_pattern': 'YouTube_{account}_M_{start_date:%Y%m%d}_{end_date:%Y%m%d}_adjustment_red_label_rawdata_video_v1-1.csv.gz', # noqa: E501 'staging_raw_table': None, 'subreports': { 'video_claim_raw_report': { 'report_title': 'Video Claim Raw Report', 'file_pattern': 'YouTube_{account}_M_{start_date:%Y%m%d}_{end_date:%Y%m%d}_adjustment_red_label_rawdata_video_v1-1__video_claim_raw_report.csv', # noqa: E501 'staging_raw_table': 'staging_raw_youtube_monthly_adjustment_red_label_rawdata_video_v1_1__video_claim_raw_report' # noqa: E501 } }, 'accounts': { 'theorchardmusic': {} } }, 'rawdata_v1_0': { 'file_pattern': 'YouTube_{account}_M_{start_date:%Y%m%d}_{end_date:%Y%m%d}_rawdata_v1-0.csv.gz', # noqa: E501 'staging_raw_table': 'staging_raw_youtube_monthly_rawdata_v1_0', 'accounts': { 'theorchardmusic': {} } }, 'red_label_rawdata_video_v1_1': { 'file_pattern': 'YouTube_{account}_M_{start_date:%Y%m%d}_{end_date:%Y%m%d}_red_label_rawdata_video_v1-1.csv.gz', # noqa: E501 'staging_raw_table': None, 'subreports': { 'video_claim_raw_report': { 'report_title': 'Video Claim Raw Report', 'file_pattern': 'YouTube_{account}_M_{start_date:%Y%m%d}_{end_date:%Y%m%d}_red_label_rawdata_video_v1-1__video_claim_raw_report.csv', # noqa: E501 'staging_raw_table': 'staging_raw_youtube_monthly_red_label_rawdata_video_v1_1__video_claim_raw_report' # noqa: E501 } }, 'accounts': { 'theorchardmusic': {} } }, 'red_label_summary_v1_1': { 'file_pattern': 'YouTube_{account}_M_{start_date:%Y%m%d}_{end_date:%Y%m%d}_red_label_summary_v1-1.csv.gz', # noqa: E501 'staging_raw_table': None, 'subreports': { 'subscriber_summary': { 'report_title': 'Subscriber Summary', 'file_pattern': 'YouTube_{account}_M_{start_date:%Y%m%d}_{end_date:%Y%m%d}_red_label_summary_v1-1__subscriber_summary.csv', # noqa: E501 'staging_raw_table': 'staging_raw_youtube_monthly_red_label_summary_v1_1__subscriber_summary' # noqa: E501 }, 'music_summary': { 'report_title': 'Music Summary', 'file_pattern': 'YouTube_{account}_M_{start_date:%Y%m%d}_{end_date:%Y%m%d}_red_label_summary_v1-1__music_summary.csv', # noqa: E501 'staging_raw_table': 'staging_raw_youtube_monthly_red_label_summary_v1_1__music_summary' # noqa: E501 }, 'non_music_summary': { 'report_title': 'Non Music Summary', 'file_pattern': 'YouTube_{account}_M_{start_date:%Y%m%d}_{end_date:%Y%m%d}_red_label_summary_v1-1__non_music_summary.csv', # noqa: E501 'staging_raw_table': 'staging_raw_youtube_monthly_red_label_summary_v1_1__non_music_summary' # noqa: E501 } }, 'accounts': { 'theorchardmusic': {} } }, 'adj_video_raw_v1_1': { 'file_pattern': 'YouTube_{account}_M_{start_date:%Y%m%d}_ADJ_video_raw_v1-1.csv.gz', # noqa: E501 'staging_raw_table': 'staging_raw_youtube_monthly_adj_video_raw_v1_1', 'accounts': { 'theorchardmusic': {} } } }