Skip to content

Commit 6f73a61

Browse files
committed
allow timezone secret
1 parent abeda71 commit 6f73a61

File tree

1 file changed

+22
-14
lines changed

1 file changed

+22
-14
lines changed

adafruit_pyportal.py

Lines changed: 22 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@
7777
__repo__ = "https://github.com/adafruit/Adafruit_CircuitPython_PyPortal.git"
7878

7979
# pylint: disable=line-too-long
80-
IMAGE_CONVERTER_SERVICE = "http://res.cloudinary.com/schmarty/image/fetch/w_320,h_240,c_fill,f_bmp/"
80+
IMAGE_CONVERTER_SERVICE = "https://res.cloudinary.com/schmarty/image/fetch/w_320,h_240,c_fill,f_bmp/"
8181
#IMAGE_CONVERTER_SERVICE = "http://ec2-107-23-37-170.compute-1.amazonaws.com/rx/ofmt_bmp,rz_320x240/"
8282
TIME_SERVICE_IPADDR = "http://worldtimeapi.org/api/ip"
8383
TIME_SERVICE_LOCATION = "http://worldtimeapi.org/api/timezone/"
@@ -320,7 +320,7 @@ def set_background(self, file_or_color):
320320
321321
"""
322322
print("Set background to ", file_or_color)
323-
while len(self._bg_group) != 0:
323+
while self._bg_group:
324324
self._bg_group.pop()
325325

326326
if not file_or_color:
@@ -461,8 +461,8 @@ def play_file(file_name):
461461
462462
"""
463463
#self._speaker_enable.value = True
464-
with audioio.AudioOut(board.AUDIO_OUT) as audio:
465-
with open(file_name, "rb") as file:
464+
with open(file_name, "rb") as file:
465+
with audioio.AudioOut(board.AUDIO_OUT) as audio:
466466
with audioio.WaveFile(file) as wavefile:
467467
audio.play(wavefile)
468468
while audio.playing:
@@ -487,17 +487,24 @@ def get_local_time(self, location=None):
487487
# pylint: enable=line-too-long
488488
self._connect_esp()
489489
api_url = None
490-
if not location:
491-
api_url = TIME_SERVICE_IPADDR
492-
else:
490+
if secrets['timezone']:
491+
location = secrets['timezone']
492+
if location:
493+
print("Getting time for timezone", location)
493494
api_url = TIME_SERVICE_LOCATION + location
494-
response = requests.get(api_url)
495-
time_json = response.json()
496-
current_time = time_json['datetime']
497-
year_day = time_json['day_of_year']
498-
week_day = time_json['day_of_week']
499-
is_dst = time_json['dst']
495+
else: # we'll try to figure it out from the IP address
496+
print("Getting time from IP address")
497+
api_url = TIME_SERVICE_IPADDR
500498

499+
try:
500+
response = requests.get(api_url)
501+
time_json = response.json()
502+
current_time = time_json['datetime']
503+
year_day = time_json['day_of_year']
504+
week_day = time_json['day_of_week']
505+
is_dst = time_json['dst']
506+
except KeyError:
507+
raise KeyError("Was unable to lookup the time, try setting secrets['timezone'] according to http://worldtimeapi.org/timezones") # pylint: disable=line-too-long
501508
the_date, the_time = current_time.split('T')
502509
year, month, mday = [int(x) for x in the_date.split('-')]
503510
the_time = the_time.split('.')[0]
@@ -741,7 +748,8 @@ def show_QR(self, qr_data, qr_size=128, position=None): # pylint: disable=inval
741748

742749
for b in range(BLOCK_SIZE):
743750
# load this line of data in, as many time as block size
744-
qr_bitmap._load_row(Y_OFFSET + y*BLOCK_SIZE+b, line) # pylint: disable=protected-access
751+
for i, byte in enumerate(line):
752+
qr_bitmap[Y_OFFSET + y*BLOCK_SIZE+b + i] = byte
745753
# pylint: enable=invalid-name
746754

747755
# display the bitmap using our palette

0 commit comments

Comments
 (0)