diff --git a/archive_updater.py b/archive_updater.py index e879f04..8839c00 100644 --- a/archive_updater.py +++ b/archive_updater.py @@ -93,6 +93,8 @@ def parser(): ,default=argparse.SUPPRESS) parser.add_argument("-md", help="format",action='store_true' ,default=argparse.SUPPRESS) + parser.add_argument("-i", help="for a command line download input", + type=str, default=argparse.SUPPRESS) args = parser.parse_args() print(args) @@ -107,8 +109,12 @@ def parser(): regex=args.r if(args.mode==downloadInput): - print("downloading") - download(keep_text_format) + if hasattr(args, 'i'): + print(args.i) + download_cli(args.i) + else: + print("downloading") + download(keep_text_format) elif(args.mode==updateInput): archiveUpdate(findNovel(regex),keep_text_format) diff --git a/src/main_functions.py b/src/main_functions.py index 9df074b..34a3240 100644 --- a/src/main_functions.py +++ b/src/main_functions.py @@ -172,6 +172,48 @@ def download(keep_text_format=False): novel.processNovel() +def download_cli(userInput:str): + novel_info = userInput.strip().split(';') + if(len(novel_info)<2): + novel_info.append('') + + novel=Novel(novel_info[0],novel_info[1]) + novel=novel.updateObject() + if(novel==0): + return + #detect if the novel has already been downloaded + match=findNovel(novel.code) + if (len(match)>0): + print(match[0][:25]+'... \t folder already exists') + return + + dir='' + if (name==''): + name=novel.getNovelTitle() + + name=checkFileName(name) + print(name) + dir='./novel_list/'+novel.code+' '+name + dir = checkFilePathLength(dir) + + if novel.code+' '+name not in match: + try : + os.mkdir('%s'%dir) + except FileExistsError: + print("the folder already exists") + return + else: + print(novel.code+' '+name+' folder already imported, update to fetch updates') + return + + print("dir= "+dir) + + #dir='./novel_list/'+code+' '+name + novel.setDir(dir) + novel.setLastChapter(0) + novel.processNovel() + + def getFolderStatus(): """register as csv every folder name and the number of chapter""" dir='./novel_list' diff --git a/src/tests/tests.py b/src/tests/tests.py index e75e37a..8374e01 100644 --- a/src/tests/tests.py +++ b/src/tests/tests.py @@ -18,6 +18,9 @@ class TestMainFunctions(unittest.TestCase): + def init(self): + os.mkdir('novel_list') + def test_find(self): self.assertTrue(len(findNovel("")) == len(os.listdir('novel_list')))