1
0

2 Ревизии aee65dff74 ... 44d021b5ae

Автор SHA1 Съобщение Дата
  Jason Tarka 44d021b5ae Add retries for fetching the usage data преди 11 месеца
  Jason Tarka aee65dff74 Add retries for fetching the usage data преди 11 месеца
променени са 1 файла, в които са добавени 6 реда и са изтрити 2 реда
  1. 6 2
      main.py

+ 6 - 2
main.py

@@ -12,6 +12,7 @@
 import pyemvue
 import json
 import time
+import sys
 
 from pyemvue.enums import Scale, Unit
 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_ATTEMPTS = 5
 
+def eprint(*args, **kwargs):
+    print(*args, file=sys.stderr, **kwargs)
+
 # Get & display minutely data for all devices.
 def allUsageOverTime(vue: PyEmVue):
 	devices = vue.get_devices()
@@ -74,13 +78,13 @@ def getChartUsage(vue: PyEmVue, channel, start_time, end_time):
 				)
 		except Exception as e:
 			if attempt < MAX_ATTEMPTS:
-				print(
+				eprint(
 					f'Attempt {attempt} for channel {channel.name}',
 					f'from {start_time} to {end_time}',
 					f'failed:', e)
 				time.sleep(5)
 			else:
-				print(f'Failed after {attempt} attempts')
+				eprint(f'Failed after {attempt} attempts')
 				raise
 
 if __name__ == '__main__':