Skip to content

Commit

Permalink
edits to init file
Browse files Browse the repository at this point in the history
  • Loading branch information
Mitchell Laferla committed Jul 3, 2023
1 parent d86233f commit 7308ec5
Showing 1 changed file with 39 additions and 16 deletions.
55 changes: 39 additions & 16 deletions monitoring_weekly/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
import sys
import importlib.util


# Azure function timer. To alter timer cadence see function.json file
def main(mytimer: func.TimerRequest) -> None:
utc_timestamp = datetime.datetime.utcnow().replace(
tzinfo=datetime.timezone.utc).isoformat()
Expand All @@ -16,23 +16,46 @@ def main(mytimer: func.TimerRequest) -> None:
logging.info('Python timer trigger function ran at %s', utc_timestamp)


# call function with script name in folder that you wish to run. Do not include file extension ie: ".py"

try:
run_script('weekly_sama_reporting')
run_script('weekly_autolinker_100_links_audit')
run_script('weekly_insights_brand_monitoring')
run_script('weekly_new_brand_combos')
run_script('weekly_new_store_monitoring')

except:
print("There was a problem running a script")


def run_script(script_name):
script_path = os.path.join(os.path.dirname(__file__), f'{script_name}.py')
script_path = os.path.join(os.path.dirname(__file__), f'{script_name}')

s = importlib.util.spec_from_file_location(script_name, script_path)
m = importlib.util.module_from_spec(s)
sys.modules[s.name] = m
s.loader.exec_module(m)
s.loader.exec_module(m)


def batch_execution(file_list):

exceptions = [] #store errors

for file in files:
try:
run_script(file)
except Exception as e:
exceptions.append(e)
else:
print('Success')

return exceptions

# list of scripts running in function, if adding new script add to list.
files = ['weekly_sama_reporting.py',
'weekly_autolinker_100_links_audit.py',
'weekly_insights_brand_monitoring.py',
'weekly_new_brand_combos.py',
'weekly_new_store_monitoring.py']

batch_execution(files)

# try:
# run_script('weekly_sama_reporting.py')
# run_script('weekly_autolinker_100_links_audit.py')
# run_script('weekly_insights_brand_monitoring.py')
# run_script('weekly_new_brand_combos.py')
# run_script('weekly_new_store_monitoring.py')

# except:
# print("There was a problem running a script")


0 comments on commit 7308ec5

Please sign in to comment.