"""Snowflake connector. Class for the Apple podcast subscription snapshot tasks. """ from datetime import datetime from snowflake_connector.etl_connector import SnowflakeSQLExecutor from snowflake_connector.etl_connector import SQLLoader from feed_ingestion.flows.itunes import config sql_loader = SQLLoader(__file__) class ApplePodcastsContentPerformanceSF(SnowflakeSQLExecutor): """Helper class to abstract Snowflake operations. This class inherits from SnowflakeSQLExecutor class, which provides basic set of methods. This class extends SnowflakeSQLExecutor with some specific methods, which are useful to encapsulate some flow specific operations. """ @property def feed_name(self): """Name of the feed. Should match dir name of this feed, feed_name in config.py of a feed. Returns: str: Feed name """ return config.feed_name @property def feedid(self): """Id of the feed. Returns: str: Feed id """ return config.feedid def load_content_performance_table( self, staging_raw_table, date, vendor_id, vendor_name): """Populate sales summary table.""" processed_daytime = datetime.now().replace(microsecond=0) self.execute_query( sql_loader, 'load_content_performance_table', dict( db=self.sf_config['db'], schema=self.sf_config['schema'], staging_raw_table=staging_raw_table, processed_daytime=processed_daytime, report_date=date, vendor_id=vendor_id, vendor_name=vendor_name )) def delete_from_staging_raw_content_performance( self, staging_raw_table, date, vendor_id): """Delete completed entries from staging raw.""" self.execute_query( sql_loader, 'delete_from_staging_raw', dict( db=self.sf_config['db'], schema=self.sf_config['schema'], staging_raw_table=staging_raw_table, report_date=date, vendor_id=vendor_id ))