@@ -201,14 +201,16 @@ def url_encode(url):
201
201
"""
202
202
return url .replace (" " , "+" ).replace ("%" , "%25" ).replace (":" , "%3A" )
203
203
204
- def get_strftime (self , time_format , location = None ):
204
+ def get_strftime (self , time_format , location = None , max_attempts = 10 ):
205
205
"""
206
206
Fetch a custom strftime relative to your location.
207
207
208
208
:param str location: Your city and country, e.g. ``"America/New_York"``.
209
+ :param max_attempts: The maximum number of of attempts to connect to WiFi before
210
+ failing or use None to disable. Defaults to 10.
209
211
210
212
"""
211
- self .connect ()
213
+ self .connect (max_attempts = max_attempts )
212
214
api_url = None
213
215
reply = None
214
216
try :
@@ -256,14 +258,18 @@ def get_strftime(self, time_format, location=None):
256
258
257
259
return reply
258
260
259
- def get_local_time (self , location = None ):
261
+ def get_local_time (self , location = None , max_attempts = 10 ):
260
262
"""
261
263
Fetch and "set" the local time of this microcontroller to the local time at the location, using an internet time API.
262
264
263
265
:param str location: Your city and country, e.g. ``"America/New_York"``.
266
+ :param max_attempts: The maximum number of of attempts to connect to WiFi before
267
+ failing or use None to disable. Defaults to 10.
264
268
265
269
"""
266
- reply = self .get_strftime (TIME_SERVICE_FORMAT , location = location )
270
+ reply = self .get_strftime (
271
+ TIME_SERVICE_FORMAT , location = location , max_attempts = max_attempts
272
+ )
267
273
if reply :
268
274
times = reply .split (" " )
269
275
the_date = times [0 ]
0 commit comments