Created
May 7, 2022 14:37
-
-
Save h3xagn/5a7c3dc5558fc944649fa3ce44609448 to your computer and use it in GitHub Desktop.
Build ETL from device to cloud: https://h3xagn.com
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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