2 Commity aee65dff74 ... 44d021b5ae

Autor SHA1 Wiadomość Data
  Jason Tarka 44d021b5ae Add retries for fetching the usage data 11 miesięcy temu
  Jason Tarka aee65dff74 Add retries for fetching the usage data 11 miesięcy temu
1 zmienionych plików z 6 dodań i 2 usunięć
  1. 6 2
      main.py

+ 6 - 2
main.py

@@ -12,6 +12,7 @@
 import pyemvue
 import pyemvue
 import json
 import json
 import time
 import time
+import sys
 
 
 from pyemvue.enums import Scale, Unit
 from pyemvue.enums import Scale, Unit
 from pyemvue import PyEmVue
 from pyemvue import PyEmVue
@@ -23,6 +24,9 @@ DAYS_BACK = 14 # Number of days in the past to get per-minute data for.
 MAX_HOURS = 12 # The maxinum number of hours that can be retrieved at once.
 MAX_HOURS = 12 # The maxinum number of hours that can be retrieved at once.
 MAX_ATTEMPTS = 5
 MAX_ATTEMPTS = 5
 
 
+def eprint(*args, **kwargs):
+    print(*args, file=sys.stderr, **kwargs)
+
 # Get & display minutely data for all devices.
 # Get & display minutely data for all devices.
 def allUsageOverTime(vue: PyEmVue):
 def allUsageOverTime(vue: PyEmVue):
 	devices = vue.get_devices()
 	devices = vue.get_devices()
@@ -74,13 +78,13 @@ def getChartUsage(vue: PyEmVue, channel, start_time, end_time):
 				)
 				)
 		except Exception as e:
 		except Exception as e:
 			if attempt < MAX_ATTEMPTS:
 			if attempt < MAX_ATTEMPTS:
-				print(
+				eprint(
 					f'Attempt {attempt} for channel {channel.name}',
 					f'Attempt {attempt} for channel {channel.name}',
 					f'from {start_time} to {end_time}',
 					f'from {start_time} to {end_time}',
 					f'failed:', e)
 					f'failed:', e)
 				time.sleep(5)
 				time.sleep(5)
 			else:
 			else:
-				print(f'Failed after {attempt} attempts')
+				eprint(f'Failed after {attempt} attempts')
 				raise
 				raise
 
 
 if __name__ == '__main__':
 if __name__ == '__main__':