Created
November 29, 2021 13:29
-
-
Save crosstyan/de36129a85d02797b1e950a0ca45723e to your computer and use it in GitHub Desktop.
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
| import time | |
| import random | |
| import pandas as pd | |
| import datetime | |
| import atexit | |
| d = { | |
| 'pressure': [], | |
| 'temperature': [], | |
| 'time':[] | |
| } | |
| df = pd.DataFrame(data=d) | |
| def save_csv() -> None: | |
| time_now: str = datetime.datetime.now().strftime('%Y%m%d-%H%M-%S') | |
| df.to_csv(f"{time_now}.csv", index=False, date_format='%Y-%m-%d %H:%M:%S') | |
| print("Saved") | |
| atexit.register(save_csv) | |
| while True: | |
| measure_value = random.randrange(0, 100) | |
| measure_temperature = random.randrange(10, 30) | |
| time_now = pd.Timestamp.now() | |
| data = { | |
| 'time':time_now, | |
| 'pressure': measure_value, | |
| 'temperature': measure_temperature, | |
| } | |
| df = df.append(data, ignore_index=True) | |
| print(data) | |
| time.sleep(1) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment