Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Select an option

  • Save audhiaprilliant/0f1bf02b8d65678f2f1d07fd99dec160 to your computer and use it in GitHub Desktop.

Select an option

Save audhiaprilliant/0f1bf02b8d65678f2f1d07fd99dec160 to your computer and use it in GitHub Desktop.
Apache Airflow as Job Orchestration
# Function to save the daily aggregated data
def summary_save_txt(**context):
value = context['task_instance'].xcom_pull(task_ids = 'summary_scraping_data')
with open(dir_path+'/data/covid19/summary_covid19.txt','r') as f:
lines = f.read().splitlines()
last_line = lines[-1]
if last_line == value:
notif = 'Last update:',re.findall(r'^(.+?),',last_line)[0]
else:
with open(dir_path+'/data/covid19/summary_covid19.txt','a+') as ff:
ff.write('{}\n'.format(value))
ff.close()
notif = 'Up to date data:', re.findall(r'^(.+?),',value)[0]
return(notif)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment