from datetime import timedelta from pathlib import Path from common import common_config from utils.conf import var FLOW_DIR = Path(__file__).parent QUERIES_DIR = FLOW_DIR / 'queries' FLOW_NAME = 'spotify' PROVIDER = 'spotify' storeid = 286 feedid = 1 # SELECT feedid FROM dim_feed WHERE feedname = 'Spotify Streams' DEV_MODE = bool(var('SPOTIFY_DEV_MODE', False)) ARCHIVE_S3_BUCKET = common_config.COMMON_ARCHIVE_S3_BUCKET ARCHIVE_S3_KEY_PATH_TEMPLATE = 'SpotifyV2/archives/{date}/{report_name}/{licensor}/' # deadline for data to be ingested DATA_THRESHOLD = timedelta(days=4) # usual deley for data from provider DATA_DELAY = timedelta(hours=24) # Spotify usually issues report +1 day AWS_CONN_ID = var('SPOTIFY_AWS_CONN_ID', common_config.COMMON_AWS_CONN_ID) FILE_FORMAT = r""" -- it is needed to load json lines from file with such options -- to skip errors and load entire file. TYPE='CSV' COMPRESSION=GZIP FIELD_DELIMITER = NONE ESCAPE = '0x11' FIELD_OPTIONALLY_ENCLOSED_BY='"' ESCAPE_UNENCLOSED_FIELD='0x11' """ # SELECT licensorid # FROM dim_licensor # WHERE feedid = %(feedid)s AND distributor = %(licensor)s) licensors = { 'theorchard': dict( licensorid=[19, 20], ), 'sme': dict( licensorid=[21], ), } reports = { 'streams': { 'staging_raw': 'staging_raw_spotify_v2', 'use_countries': True, 'api_resource_name': 'streams', }, 'sub_30_sec_streams': { 'staging_raw': 'staging_raw_spotify_sub30', 'use_countries': True, 'api_resource_name': 'sub_30_sec_streams', }, 'aggregated_streams': { 'staging_raw': 'staging_raw_spotify_aggregated_streams', # it is needed to load filename in staging raw table 'filename': True, 'separate_query_for_cleaning_staging_raw': True, 'api_resource_name': 'aggregatedstreams', }, 'users': { 'api_resource_name': 'users', }, 'tracks': { 'staging_raw': 'spotify_tracks', 'api_resource_name': 'tracks', } } common_reports = ['users', 'tracks'] fact_analytics_report = 'streams' # report for load_aggregated_skips_and_saves aggregated_report = 'aggregated_streams' temp_staging_raw_table = ( 'temp_staging_raw_spotify_{report_name}_{date_nodash}_{licensor}') staging_fact_table_template = 'staging_fact_analytics_{feed_name}_{date_nodash}_{licensor}' transitional_temp_table = 'transitional_temp_table_{report_name}_{date_nodash}_{licensor}' file_pattern = '{report_name}_{date:%Y-%m-%d}{country_code}_{licensor}.gz' # The maximum allowed number of errors in the file snowflake_error_limit = 10000 spotify_api_credentials = {} spotify_api_licensors = ['theorchard'] # spotify_api_licensors = ['theorchard', 'sme'] for licensor in spotify_api_licensors: licensor_upper = licensor.upper() spotify_api_credentials[licensor] = dict( client_id=var(f'SPOTIFY_{licensor_upper}_API_CLIENT_ID'), client_secret=var(f'SPOTIFY_{licensor_upper}_API_CLIENT_SECRET'), licensor=var(f'SPOTIFY_{licensor_upper}_API_LICENSOR'), version='v1' ) countries = [ 'AD', 'AE', 'AF', 'AG', 'AI', 'AL', 'AM', 'AN', 'AO', 'AQ', 'AR', 'AS', 'AT', 'AU', 'AW', 'AX', 'AZ', 'BA', 'BB', 'BD', 'BE', 'BF', 'BG', 'BH', 'BI', 'BJ', 'BL', 'BM', 'BN', 'BO', 'BQ', 'BR', 'BS', 'BT', 'BV', 'BW', 'BY', 'BZ', 'CA', 'CC', 'CD', 'CF', 'CG', 'CH', 'CI', 'CK', 'CL', 'CM', 'CN', 'CO', 'CR', 'CS', 'CU', 'CV', 'CW', 'CX', 'CY', 'CZ', 'DE', 'DJ', 'DK', 'DM', 'DO', 'DZ', 'EC', 'EE', 'EG', 'EH', 'ER', 'ES', 'ET', 'FI', 'FJ', 'FK', 'FM', 'FO', 'FR', 'GA', 'GB', 'GD', 'GE', 'GF', 'GG', 'GH', 'GI', 'GL', 'GM', 'GN', 'GP', 'GQ', 'GR', 'GS', 'GT', 'GU', 'GW', 'GY', 'HK', 'HM', 'HN', 'HR', 'HT', 'HU', 'ID', 'IE', 'IL', 'IM', 'IN', 'IO', 'IQ', 'IR', 'IS', 'IT', 'JE', 'JM', 'JO', 'JP', 'KE', 'KG', 'KH', 'KI', 'KM', 'KN', 'KP', 'KR', 'KW', 'KY', 'KZ', 'LA', 'LB', 'LC', 'LI', 'LK', 'LR', 'LS', 'LT', 'LU', 'LV', 'LY', 'MA', 'MC', 'MD', 'ME', 'MF', 'MG', 'MH', 'MK', 'ML', 'MM', 'MN', 'MO', 'MP', 'MQ', 'MR', 'MS', 'MT', 'MU', 'MV', 'MW', 'MX', 'MY', 'MZ', 'NA', 'NC', 'NE', 'NF', 'NG', 'NI', 'NL', 'NO', 'NP', 'NR', 'NU', 'NZ', 'OM', 'PA', 'PE', 'PF', 'PG', 'PH', 'PK', 'PL', 'PM', 'PN', 'PR', 'PS', 'PT', 'PW', 'PY', 'QA', 'RE', 'RO', 'RS', 'RU', 'RW', 'SA', 'SB', 'SC', 'SD', 'SE', 'SG', 'SH', 'SI', 'SJ', 'SK', 'SL', 'SM', 'SN', 'SO', 'SR', 'SS', 'ST', 'SV', 'SX', 'SY', 'SZ', 'TC', 'TD', 'TF', 'TG', 'TH', 'TJ', 'TK', 'TL', 'TM', 'TN', 'TO', 'TR', 'TT', 'TV', 'TW', 'TZ', 'UA', 'UG', 'UM', 'US', 'UY', 'UZ', 'VA', 'VC', 'VE', 'VG', 'VI', 'VN', 'VU', 'WF', 'WS', 'XK', 'YE', 'YT', 'ZA', 'ZM', 'ZW', 'ZZ'] expected_countries = [ 'AD', 'AR', 'AT', 'AU', 'BE', 'BG', 'BO', 'BR', 'CA', 'CH', 'CL', 'CO', 'CR', 'CY', 'CZ', 'DE', 'DK', 'DO', 'EC', 'EE', 'ES', 'FI', 'FR', 'GB', 'GR', 'GT', 'HK', 'HN', 'HU', 'IE', 'IS', 'IT', 'LI', 'LT', 'LU', 'LV', 'MC', 'MT', 'MX', 'MY', 'NI', 'NL', 'NO', 'NZ', 'PA', 'PE', 'PH', 'PL', 'PT', 'PY', 'SE', 'SG', 'SK', 'SV', 'TR', 'TW', 'US', 'UY' ] dimension_tables = { 'tables_to_update': [ 'dim_sourcetype', 'dim_subscriptiontype', 'dim_subscriptionpaytier', 'dim_playlist', 'dim_user', ], 'include_to_report': [ 'dim_sourcetype', 'dim_subscriptiontype', 'dim_subscriptionpaytier' ], # 'sns_topic': os.environ.get( # 'FEED_INGESTION_SNS_TOPIC', # 'arn:aws:sns:us-east-1:437795906767:dev-swf-feed-ingestion:' # 'e17576f8-b905-45a9-b863-0eaceca54f4d') }