diff --git a/.gitignore b/.gitignore index 5d381cc..b390322 100644 --- a/.gitignore +++ b/.gitignore @@ -1,3 +1,5 @@ +*.pkl +*.csv # ---> Python # Byte-compiled / optimized / DLL files __pycache__/ diff --git a/data-view.py b/data-view.py new file mode 100644 index 0000000..c38daee --- /dev/null +++ b/data-view.py @@ -0,0 +1,6 @@ +import pandas as pd +from datetime import datetime + +data_dict = pd.read_pickle("saved_data_dict.pkl") +data_df = pd.DataFrame(data_dict) +data_df.T.to_csv("data_df.csv") diff --git a/data.py b/data.py new file mode 100644 index 0000000..2308ea5 --- /dev/null +++ b/data.py @@ -0,0 +1,60 @@ +import requests +import ast +from datetime import datetime +from time import sleep +import pickle + +data_url = "http://192.168.1.221/get_livedata_info" + +data_response = requests.get(data_url) + +data_dict = ast.literal_eval(data_response.content.decode('utf-8')) + +den_dict = data_dict['wh25'][0] +outdoor_dict = data_dict['ch_aisle'][0] +lroom_dict = data_dict['ch_aisle'][1] +roffice_dict = data_dict['ch_aisle'][2] +toffice_dict = data_dict['ch_aisle'][3] +broom_dict = data_dict['ch_aisle'][4] +lightning_dict = data_dict['lightning'][0] +# print(den_dict.keys()) +# print(outdoor_dict.keys()) +# print(lroom_dict.keys()) +# print(roffice_dict.keys()) +# print(toffice_dict.keys()) +# print(broom_dict.keys()) +# print(lightning_dict.keys()) +try: + with open('saved_data_dict.pkl', 'rb') as f: + data_dict = pickle.load(f) +except: + data_dict = {} + +datum_dict = {} +datum_dict['den_temp'] = den_dict['intemp'] +datum_dict['den_humi'] = den_dict['inhumi'] +datum_dict['den_pabs'] = den_dict['abs'] +datum_dict['den_prel'] = den_dict['rel'] +datum_dict['lroom_temp'] = lroom_dict['temp'] +datum_dict['lroom_humi'] = lroom_dict['humidity'] +datum_dict['lroom_batt'] = lroom_dict['battery'] +datum_dict['roffice_temp'] = roffice_dict['temp'] +datum_dict['roffice_humi'] = roffice_dict['humidity'] +datum_dict['roffice_batt'] = roffice_dict['battery'] +datum_dict['toffice_temp'] = toffice_dict['temp'] +datum_dict['toffice_humi'] = toffice_dict['humidity'] +datum_dict['toffice_batt'] = toffice_dict['battery'] +datum_dict['broom_temp'] = broom_dict['temp'] +datum_dict['broom_humi'] = broom_dict['humidity'] +datum_dict['broom_batt'] = broom_dict['battery'] +datum_dict['outdoor_temp'] = outdoor_dict['temp'] +datum_dict['outdoor_humi'] = outdoor_dict['humidity'] +datum_dict['outdoor_batt'] = outdoor_dict['battery'] +datum_dict['lghtng_dist'] = lightning_dict['distance'] +datum_dict['lghtng_date'] = lightning_dict['date'] +datum_dict['lghtng_time'] = lightning_dict['timestamp'] +datum_dict['lghtng_scnt'] = lightning_dict['count'] +datum_dict['lghtng_batt'] = lightning_dict['battery'] +data_dict[datetime.now().strftime('%Y%m%d-%H%M%S')] = datum_dict +with open('saved_data_dict.pkl', 'wb') as f: + pickle.dump(data_dict, f)