You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
30 lines
763 B
30 lines
763 B
import httpx
|
|
import os
|
|
import Utils
|
|
import hashlib
|
|
|
|
|
|
class FileCache:
|
|
|
|
def __init__(self, link, ext):
|
|
self.link = link
|
|
path = os.path.expanduser("~") + "/.config/inomnibus/file_cache/"
|
|
h = hashlib.sha1()
|
|
h.update(self.link.encode())
|
|
self.file_path = path + h.hexdigest() + "." + ext
|
|
|
|
def download(self):
|
|
try:
|
|
file = httpx.get(self.link, follow_redirects=True)
|
|
open(self.file_path, "wb").write(file.content)
|
|
return self.file_path
|
|
except BaseException as e:
|
|
Utils.writeLog(str(e))
|
|
return None
|
|
|
|
def fetch(self):
|
|
if os.path.isfile(self.file_path):
|
|
return self.file_path
|
|
else:
|
|
return self.download()
|