Set min jpeg size. Organize logging into single method. Use auto GC instead of manual. Better file handling.
This commit is contained in:
@@ -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()
|
||||
|
||||
Reference in New Issue
Block a user