parent
2564246126
commit
9a2af39be7
@ -0,0 +1,29 @@
|
||||
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()
|
||||
Loading…
Reference in new issue