Dummy ADE account and Arguments

This commit is contained in:
bipinkrish
2023-02-24 00:12:15 +05:30
parent b2759bc182
commit a89c55ce39
10 changed files with 141 additions and 49 deletions

View File

@@ -4,38 +4,63 @@ from setup.fulfill import downloadFile
from decrypt.decodePDF import decryptPDF
from decrypt.decodeEPUB import decryptEPUB
# setting up the account and keys
loginAndGetKey()
import argparse
from os import mkdir, remove, rename
from os.path import exists
# acsm file
acsmFile = input("Enter ACSM file (press enter if the file name is URLLink.acsm): ")
if acsmFile == "":
from os.path import exists
if exists("URLLink.acsm"):
acsmFile = "URLLink.acsm"
else:
print("URLLink.acsm file does not exists")
from setup.params import FILE_DEVICEKEY, FILE_DEVICEXML, FILE_ACTIVATIONXML
from decrypt.params import KEYPATH
from setup.data import createDefaultFiles
def main(acsmFile, login):
# user login
if login:
if not exists("account"):
mkdir("account")
loginAndGetKey()
exit(0)
# setting up the account and keys
if not (exists(FILE_ACTIVATIONXML) and exists(FILE_DEVICEXML) and exists(FILE_DEVICEKEY) and exists(KEYPATH)):
if not exists("account"):
mkdir("account")
createDefaultFiles()
# cheek for file existance
if not exists(acsmFile):
print(f"{acsmFile} file does not exist")
print()
exit(1)
# downlaod
enrcyptedFile = downloadFile(acsmFile)
print(enrcyptedFile)
print()
# decrypt
if enrcyptedFile.endswith(".pdf"):
decryptedFile = decryptPDF(enrcyptedFile)
elif enrcyptedFile.endswith(".epub"):
decryptedFile = decryptEPUB(enrcyptedFile)
else:
print("Not in supported file formats")
# download
encryptedFile = downloadFile(acsmFile)
print(encryptedFile)
print()
exit(1)
from os import remove, rename
remove(enrcyptedFile)
rename(decryptedFile,enrcyptedFile)
decryptedFile = enrcyptedFile
print(decryptedFile)
print()
# decrypt
if encryptedFile.endswith(".pdf"):
decryptedFile = decryptPDF(encryptedFile)
elif encryptedFile.endswith(".epub"):
decryptedFile = decryptEPUB(encryptedFile)
else:
print("File format not supported")
print()
exit(1)
remove(encryptedFile)
rename(decryptedFile, encryptedFile)
decryptedFile = encryptedFile
print(decryptedFile)
print()
if __name__ == "__main__":
parser = argparse.ArgumentParser(description="Download and Decrypt an encrypted PDF or EPUB file. It uses Dummy account for ADE, you can overide using --login")
parser.add_argument("file", type=str, nargs='?', default="URLLink.acsm", help="Path to the ACSM file")
parser.add_argument("-l", "--login", action="store_true", help="Login to your ADE account. (optional)")
args = parser.parse_args()
if args.file == "URLLink.acsm" and not exists(args.file):
parser.print_help()
else:
main(args.file, args.login)