@@ -135,6 +135,8 @@ class PyPortal:
135
135
:param regexp_path: The list of regexp strings to get data out (use a single regexp group). Can
136
136
be list of regexps for multiple data points. Defaults to ``None`` to not
137
137
use regexp.
138
+ :param convert_image: Determine whether or not to use the AdafruitIO image converter service.
139
+ Set as False if your image is already resized. Defaults to True.
138
140
:param default_bg: The path to your default background image file or a hex color.
139
141
Defaults to 0x000000.
140
142
:param status_neopixel: The pin for the status NeoPixel. Use ``board.NEOPIXEL`` for the on-board
@@ -184,6 +186,7 @@ def __init__(
184
186
headers = None ,
185
187
json_path = None ,
186
188
regexp_path = None ,
189
+ convert_image = True ,
187
190
default_bg = 0x000000 ,
188
191
status_neopixel = None ,
189
192
text_font = terminalio .FONT ,
@@ -210,6 +213,7 @@ def __init__(
210
213
):
211
214
212
215
self ._debug = debug
216
+ self ._convert_image = convert_image
213
217
214
218
try :
215
219
if hasattr (board , "TFT_BACKLIGHT" ):
@@ -743,8 +747,11 @@ def wget(self, url, filename, *, chunk_size=12000):
743
747
744
748
if self ._debug :
745
749
print (r .headers )
746
- content_length = int (r .headers ["content-length" ])
747
- remaining = content_length
750
+ if "content-length" in r .headers :
751
+ content_length = int (r .headers ["content-length" ])
752
+ remaining = content_length
753
+ else :
754
+ raise RuntimeError ("Content-length missing from headers" )
748
755
print ("Saving data to " , filename )
749
756
stamp = time .monotonic ()
750
757
file = open (filename , "wb" )
@@ -971,21 +978,23 @@ def fetch(self, refresh_url=None, timeout=10):
971
978
if image_url :
972
979
try :
973
980
print ("original URL:" , image_url )
974
- if iwidth < iheight :
975
- image_url = self .image_converter_url (
976
- image_url ,
977
- int (
978
- self ._image_resize [1 ]
979
- * self ._image_resize [1 ]
980
- / self ._image_resize [0 ]
981
- ),
982
- self ._image_resize [1 ],
983
- )
984
- else :
985
- image_url = self .image_converter_url (
986
- image_url , self ._image_resize [0 ], self ._image_resize [1 ]
987
- )
988
- print ("convert URL:" , image_url )
981
+ if self ._convert_image :
982
+ if iwidth < iheight :
983
+ image_url = self .image_converter_url (
984
+ image_url ,
985
+ int (
986
+ self ._image_resize [1 ]
987
+ * self ._image_resize [1 ]
988
+ / self ._image_resize [0 ]
989
+ ),
990
+ self ._image_resize [1 ],
991
+ )
992
+ else :
993
+ image_url = self .image_converter_url (
994
+ image_url , self ._image_resize [0 ], self ._image_resize [1 ]
995
+ )
996
+
997
+ print ("convert URL:" , image_url )
989
998
# convert image to bitmap and cache
990
999
# print("**not actually wgetting**")
991
1000
filename = "/cache.bmp"
0 commit comments