Set min jpeg size. Organize logging into single method. Use auto GC instead of manual. Better file handling.

This commit is contained in:
2023-11-05 16:12:23 -05:00
parent 70ce4477a8
commit 345e27b345
3 changed files with 22 additions and 23 deletions

View File

@@ -1,5 +1,4 @@
import urequests
import gc, sys
import ElementTree
@@ -40,33 +39,28 @@ class uNextcloud:
if content_type != None:
file_list.append(self.File(href.text, content_type.text))
response.close()
gc.collect()
return file_list
except AttributeError:
response.close()
gc.collect()
return None
else:
response.close()
gc.collect()
return None
def download_file_to_path(self, url_path, destination_path):
response = urequests.request("GET", self.url+url_path, auth=(self.username, self.password))
if 200 <= response.status_code < 300:
dest = open(destination_path, 'wb')
data = bytearray(1024)
len = 0
while True:
print(f"downloaded {len}")
gc.collect()
if response.raw.readinto(data) == 0:
break
len += 1024
dest.write(data)
dest.close()
with open(destination_path, 'wb') as dest:
data = bytearray(1024)
while True:
print(f"downloaded {len}")
if response.raw.readinto(data) == 0:
break
len += 1024
dest.write(data)
dest.flush()
response.close()
gc.collect()
else:
response.close()
raise Exception()