Skip to content

Commit ee78cef

Browse files
authored
change to support Winddata from Anemometer
1 parent 5227e5a commit ee78cef

1 file changed

Lines changed: 16 additions & 15 deletions

File tree

samples/weather2file.py

Lines changed: 16 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -434,10 +434,9 @@ def _to_dataframe(self, module_data_body, module_data, station_name, station_mac
434434

435435
def get_module_df(self, newest_utctime, station_name, station_mac, module_data_overview, end_date_timestamp, dtype={}, time_z=None):
436436
logging.info(f'Processing {module_data_overview["module_name"]}...')
437-
438-
437+
439438
module_name = module_data_overview["module_name"]
440-
439+
441440
# We start by collecting new data
442441
keep_collecting_module_data = True
443442

@@ -461,9 +460,11 @@ def get_module_df(self, newest_utctime, station_name, station_mac, module_data_o
461460
keep_collecting_module_data = False
462461
else:
463462
logging.info(f'Collecting data for {module_name}...')
464-
463+
465464
while(keep_collecting_module_data):
466-
465+
if (module_data_overview['data_type'] == 'wind'):
466+
module_data_overview['data_type'] = ['WindStrength', 'WindAngle', 'GustStrength', 'GustAngle']
467+
467468
# Get new data from Netatmo
468469
d = self._get_field_dict(station_mac,
469470
module_data_overview['_id'],
@@ -500,7 +501,7 @@ def get_module_df(self, newest_utctime, station_name, station_mac, module_data_o
500501
logging.error(e)
501502
keep_collecting_module_data = False
502503
logging.error(f'Something fishy is going on... Aborting collection for module {module_name}')
503-
504+
504505

505506
if data:
506507
df_module = pd.concat(data,ignore_index=True)
@@ -595,11 +596,11 @@ def main():
595596
else:
596597
logging.basicConfig(format=" %(levelname)s: %(message)s", level=verbose_dict[args.verbose])
597598

598-
599+
599600
# Handle dataframes (loading, appending, saving).
600601
df_handler = df_handler_dict[args.format](file_name=args.file_name, output_path=args.output_path)
601602

602-
603+
603604
# Rate handler to make sure that we don't exceed Netatmos user rate limits
604605
rate_limit_handler = RateLimitHandler(
605606
user_request_limit_per_ten_seconds=args.ten_second_rate_limit,
@@ -608,12 +609,12 @@ def main():
608609

609610

610611
for station_name, station_data_overview in rate_limit_handler.get_stations():
611-
612+
612613
station_mac = station_data_overview['_id']
613-
614+
614615
station_timezone = timezone(station_data_overview['place']['timezone'])
615616
logging.info(f'Timezone {station_timezone} extracted from data.')
616-
617+
617618
end_datetime_timestamp = np.floor(datetime.timestamp(station_timezone.localize(args.end_datetime)))
618619
newest_utc = df_handler.get_newest_timestamp(station_data_overview['_id'])
619620
df_handler.append(
@@ -627,7 +628,7 @@ def main():
627628
station_timezone))
628629

629630
for module_data_overview in station_data_overview['modules']:
630-
631+
631632
df_handler.append(
632633
rate_limit_handler.get_module_df(
633634
df_handler.get_newest_timestamp(module_data_overview['_id']),
@@ -636,8 +637,8 @@ def main():
636637
module_data_overview,
637638
end_datetime_timestamp,
638639
df_handler.dtype_dict,
639-
station_timezone))
640-
640+
station_timezone))
641+
641642

642643

643644

@@ -646,4 +647,4 @@ def main():
646647

647648
if __name__ == "__main__":
648649
main()
649-
650+

0 commit comments

Comments
 (0)