diff --git a/__pycache__/bookrequest.cpython-310.pyc b/__pycache__/bookrequest.cpython-310.pyc index c6accb1..22dae4d 100644 Binary files a/__pycache__/bookrequest.cpython-310.pyc and b/__pycache__/bookrequest.cpython-310.pyc differ diff --git a/bookrequest.py b/bookrequest.py index eb0fcbc..82e6590 100644 --- a/bookrequest.py +++ b/bookrequest.py @@ -1,5 +1,13 @@ from libgen_api import * -import requests, sys, getopt +import requests, sys, getopt, configparser, shutil, os + +config = configparser.ConfigParser() +try: + config.read('config.ini') +except Exception as e: + print(e) + print('Config file not found. Please ensure conf.ini is in the same \ + location as bookrequest.py') def searchBook(book, unattended=False): s = LibgenSearch() @@ -36,6 +44,8 @@ def downloadBook(bookDict): r = requests.get(bookDict['link'], allow_redirects=True) open(bookDict['title']+'.epub', 'wb').write(r.content) print('Book Downloaded!') + os.makedirs(config['data']['folder_location'] + '\\' + bookDict['author']) + shutil.move(bookDict['title']+'.epub', config['data']['folder_location'] + '\\' + bookDict['author'] + '\\' + bookDict['title']+'.epub') def main(argv): diff --git a/config.ini b/config.ini new file mode 100644 index 0000000..fa2560f --- /dev/null +++ b/config.ini @@ -0,0 +1,2 @@ +[data] +folder_location = z:\books\ \ No newline at end of file diff --git a/requirments.txt b/requirments.txt index 15ebea2..c7ef473 100644 --- a/requirments.txt +++ b/requirments.txt @@ -1,2 +1,3 @@ libgen_api==1.0.0 -nicegui==1.2.2 \ No newline at end of file +nicegui==1.2.2 +configparser=3.11.2 \ No newline at end of file