Skip to content

Instantly share code, notes, and snippets.

@h3xagn
Created May 7, 2022 14:37
Show Gist options
  • Select an option

  • Save h3xagn/5a7c3dc5558fc944649fa3ce44609448 to your computer and use it in GitHub Desktop.

Select an option

Save h3xagn/5a7c3dc5558fc944649fa3ce44609448 to your computer and use it in GitHub Desktop.
Build ETL from device to cloud: https://h3xagn.com
def process_data_task(eqmt_ip: str, json_data: dict):
"""Process data tasks"""
# get current time
file_time = datetime.now()
file_datetime = file_time.strftime("%Y-%m-%d_%H-%M-%S-%f")
file_datetime_ts = file_time.strftime("%Y-%m-%d %H:%M:%S.%f")
# generate json filename and path
json_filename = f'data_{json_data["sn"]}_{file_datetime}.json'
json_file_path = f"{base_dir}\\data\\raw\\{json_filename}"
# save json file to disk
with open(json_file_path, "w") as jsonfile:
json.dump(json_data, jsonfile)
log.info(f"--- Raw JSON data file saved: '{json_filename}'.")
# transform json data to CSV
log.info(f"--- Starting data transformation for '{json_filename}'...")
transform_data(file_datetime, json_data, file_datetime_ts)
log.info(f"--- Data transformation complete for '{json_filename}'.")
# log background tasks completed
log.info(f"--- Background task completed 'process_data_task'.")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment