Skip to content

Instantly share code, notes, and snippets.

@crosstyan
Created November 29, 2021 13:29
Show Gist options
  • Select an option

  • Save crosstyan/de36129a85d02797b1e950a0ca45723e to your computer and use it in GitHub Desktop.

Select an option

Save crosstyan/de36129a85d02797b1e950a0ca45723e to your computer and use it in GitHub Desktop.
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