Set min jpeg size. Organize logging into single method. Use auto GC instead of manual. Better file handling.
This commit is contained in:
@@ -1,2 +1,2 @@
|
|||||||
#!/bin/bash
|
#!/bin/bash
|
||||||
convert "$1" -resize '800x480!' -define modulate:colorspace=HSB -modulate 100,120 -level 2% -quality 70 "${1%.*}.inky.jpeg"
|
convert "$1" -resize '800x480!' -define modulate:colorspace=HSB -modulate 100,120 -level 2% -quality 60 -define jpeg:extent=120kb "${1%.*}.inky.jpeg"
|
||||||
|
|||||||
19
main.py
19
main.py
@@ -5,20 +5,25 @@ import inky_frame
|
|||||||
import gc
|
import gc
|
||||||
import random
|
import random
|
||||||
|
|
||||||
|
def write_err(text):
|
||||||
|
with open('/sd/errors.log', 'a+') as error_log:
|
||||||
|
error_log.write(f'{text} \n')
|
||||||
|
|
||||||
|
gc.enable()
|
||||||
|
gc.threshold(50000)
|
||||||
|
|
||||||
sd_spi = machine.SPI(0, sck=machine.Pin(18, machine.Pin.OUT), mosi=machine.Pin(19, machine.Pin.OUT), miso=machine.Pin(16, machine.Pin.OUT))
|
sd_spi = machine.SPI(0, sck=machine.Pin(18, machine.Pin.OUT), mosi=machine.Pin(19, machine.Pin.OUT), miso=machine.Pin(16, machine.Pin.OUT))
|
||||||
sd = sdcard.SDCard(sd_spi, machine.Pin(22))
|
sd = sdcard.SDCard(sd_spi, machine.Pin(22))
|
||||||
uos.mount(sd, "/sd")
|
uos.mount(sd, "/sd")
|
||||||
gc.collect()
|
|
||||||
|
|
||||||
from secrets import WIFI_SSID, WIFI_PASSWORD, NEXTCLOUD_USERNAME, NEXTCLOUD_PASSWORD
|
from secrets import WIFI_SSID, WIFI_PASSWORD, NEXTCLOUD_USERNAME, NEXTCLOUD_PASSWORD
|
||||||
try:
|
try:
|
||||||
ih.network_connect_better(WIFI_SSID, WIFI_PASSWORD)
|
ih.network_connect_better(WIFI_SSID, WIFI_PASSWORD)
|
||||||
except RuntimeError as e:
|
except RuntimeError as e:
|
||||||
print(e)
|
print(e)
|
||||||
with open('/sd/errors.log', 'a+') as error_log:
|
write_err(e)
|
||||||
error_log.write(f'{e} \n')
|
|
||||||
#Likely a network oops, try starting again
|
#Likely a network oops, try starting again
|
||||||
|
uos.umount("/sd")
|
||||||
machine.soft_reset()
|
machine.soft_reset()
|
||||||
|
|
||||||
try:
|
try:
|
||||||
@@ -27,9 +32,9 @@ try:
|
|||||||
response = nc.get_folder_items("eink-frame")
|
response = nc.get_folder_items("eink-frame")
|
||||||
except OSError as e:
|
except OSError as e:
|
||||||
print(e)
|
print(e)
|
||||||
with open('/sd/errors.log', 'a+') as error_log:
|
write_err(e)
|
||||||
error_log.write(f'{e} \n')
|
|
||||||
#Likely a network oops, try starting again
|
#Likely a network oops, try starting again
|
||||||
|
uos.umount("/sd")
|
||||||
machine.soft_reset()
|
machine.soft_reset()
|
||||||
|
|
||||||
try:
|
try:
|
||||||
@@ -48,9 +53,8 @@ if response != None:
|
|||||||
with open('/sd/last_wallpaper', 'w+') as update_last:
|
with open('/sd/last_wallpaper', 'w+') as update_last:
|
||||||
update_last.write(ran.url_path)
|
update_last.write(ran.url_path)
|
||||||
print(ran.url_path)
|
print(ran.url_path)
|
||||||
gc.collect()
|
print(gc.mem_free())
|
||||||
nc.download_file_to_path(ran.url_path, "/sd/current_image.jpg")
|
nc.download_file_to_path(ran.url_path, "/sd/current_image.jpg")
|
||||||
gc.collect()
|
|
||||||
from picographics import PicoGraphics, DISPLAY_INKY_FRAME_7 as DISPLAY
|
from picographics import PicoGraphics, DISPLAY_INKY_FRAME_7 as DISPLAY
|
||||||
from jpegdec import JPEG
|
from jpegdec import JPEG
|
||||||
graphics = PicoGraphics(DISPLAY)
|
graphics = PicoGraphics(DISPLAY)
|
||||||
@@ -60,4 +64,5 @@ if response != None:
|
|||||||
j.decode()
|
j.decode()
|
||||||
graphics.update()
|
graphics.update()
|
||||||
|
|
||||||
|
uos.umount("/sd")
|
||||||
inky_frame.sleep_for(180)
|
inky_frame.sleep_for(180)
|
||||||
|
|||||||
@@ -1,5 +1,4 @@
|
|||||||
import urequests
|
import urequests
|
||||||
import gc, sys
|
|
||||||
import ElementTree
|
import ElementTree
|
||||||
|
|
||||||
|
|
||||||
@@ -40,33 +39,28 @@ class uNextcloud:
|
|||||||
if content_type != None:
|
if content_type != None:
|
||||||
file_list.append(self.File(href.text, content_type.text))
|
file_list.append(self.File(href.text, content_type.text))
|
||||||
response.close()
|
response.close()
|
||||||
gc.collect()
|
|
||||||
return file_list
|
return file_list
|
||||||
except AttributeError:
|
except AttributeError:
|
||||||
response.close()
|
response.close()
|
||||||
gc.collect()
|
|
||||||
return None
|
return None
|
||||||
else:
|
else:
|
||||||
response.close()
|
response.close()
|
||||||
gc.collect()
|
|
||||||
return None
|
return None
|
||||||
|
|
||||||
def download_file_to_path(self, url_path, destination_path):
|
def download_file_to_path(self, url_path, destination_path):
|
||||||
response = urequests.request("GET", self.url+url_path, auth=(self.username, self.password))
|
response = urequests.request("GET", self.url+url_path, auth=(self.username, self.password))
|
||||||
if 200 <= response.status_code < 300:
|
if 200 <= response.status_code < 300:
|
||||||
dest = open(destination_path, 'wb')
|
|
||||||
data = bytearray(1024)
|
|
||||||
len = 0
|
len = 0
|
||||||
while True:
|
with open(destination_path, 'wb') as dest:
|
||||||
print(f"downloaded {len}")
|
data = bytearray(1024)
|
||||||
gc.collect()
|
while True:
|
||||||
if response.raw.readinto(data) == 0:
|
print(f"downloaded {len}")
|
||||||
break
|
if response.raw.readinto(data) == 0:
|
||||||
len += 1024
|
break
|
||||||
dest.write(data)
|
len += 1024
|
||||||
dest.close()
|
dest.write(data)
|
||||||
|
dest.flush()
|
||||||
response.close()
|
response.close()
|
||||||
gc.collect()
|
|
||||||
else:
|
else:
|
||||||
response.close()
|
response.close()
|
||||||
raise Exception()
|
raise Exception()
|
||||||
|
|||||||
Reference in New Issue
Block a user