Skip to content

Commit

Permalink
add cli download
Browse files Browse the repository at this point in the history
  • Loading branch information
safirex committed Nov 22, 2022
1 parent 5ee5097 commit f7f43d8
Show file tree
Hide file tree
Showing 3 changed files with 53 additions and 2 deletions.
10 changes: 8 additions & 2 deletions archive_updater.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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)
Expand Down
42 changes: 42 additions & 0 deletions src/main_functions.py
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand Down
3 changes: 3 additions & 0 deletions src/tests/tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -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')))
Expand Down

0 comments on commit f7f43d8

Please sign in to comment.