2 Komitmen aee65dff74 ... 44d021b5ae

Pembuat SHA1 Pesan Tanggal
  Jason Tarka 44d021b5ae Add retries for fetching the usage data 11 bulan lalu
  Jason Tarka aee65dff74 Add retries for fetching the usage data 11 bulan lalu
1 mengubah file dengan 6 tambahan dan 2 penghapusan
  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__':