Make fulfill.py accept file names

This commit is contained in:
Florian Bach 2022-04-28 16:50:55 +02:00
parent 222dc1fe35
commit fa6ad1da5d

View File

@ -41,7 +41,7 @@ def download(replyData):
if (rights_xml_str is None): if (rights_xml_str is None):
print("Building rights.xml failed!") print("Building rights.xml failed!")
exit(1) return False
book_name = None book_name = None
@ -65,7 +65,7 @@ def download(replyData):
if (ret != 200): if (ret != 200):
print("Download failed with error %d" % (ret)) print("Download failed with error %d" % (ret))
exit() return False
with open(filename_tmp, "rb") as f: with open(filename_tmp, "rb") as f:
book_content = f.read(10) book_content = f.read(10)
@ -89,7 +89,7 @@ def download(replyData):
zf.close() zf.close()
print("File successfully fulfilled to " + filename) print("File successfully fulfilled to " + filename)
exit(0) return True
elif filetype == ".pdf": elif filetype == ".pdf":
print("Successfully downloaded PDF, patching encryption ...") print("Successfully downloaded PDF, patching encryption ...")
@ -104,24 +104,36 @@ def download(replyData):
os.remove("tmp_" + filename) os.remove("tmp_" + filename)
if (ret): if (ret):
print("File successfully fulfilled to " + filename) print("File successfully fulfilled to " + filename)
return True
else: else:
print("Errors occurred while patching " + filename) print("Errors occurred while patching " + filename)
exit(1) return False
exit(0)
else: else:
print("Error: Weird filetype") print("Error: Weird filetype")
exit(1) return False
def main(): def main():
print("Fulfilling book ...")
success, replyData = fulfill("URLLink.acsm") if len(sys.argv) < 2:
files = [ "URLLink.acsm" ]
else:
files = sys.argv[1:]
for file in files:
print("Fulfilling book '" + file + "' ...")
success, replyData = fulfill(file)
if (success is False): if (success is False):
print("Hey, that didn't work!") print("Hey, that didn't work!")
print(replyData) print(replyData)
else: else:
print("Downloading book ...") print("Downloading book '" + file + "' ...")
download(replyData) success = download(replyData)
if (success is False):
print("That didn't work!")
if __name__ == "__main__": if __name__ == "__main__":