Skip to content

Commit

Permalink
Added multithreading option to speed up operations. Closes #20
Browse files Browse the repository at this point in the history
  • Loading branch information
theslavicbear committed Feb 19, 2019
1 parent ea1a6af commit e5060af
Showing 1 changed file with 34 additions and 6 deletions.
40 changes: 34 additions & 6 deletions Ebook-Publisher.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,12 @@
print('Warning: No epub filetype support')
import argparse
import os
import threading
import queue


#Master array of supported sites
#TODO convert this to a dictionary
sites=['www.literotica.com', 'www.fanfiction.net', 'www.fictionpress.com','www.classicreader.com','chyoa.com', 'www.wattpad.com']

#function for making text files
Expand Down Expand Up @@ -87,6 +91,8 @@ def MakeClass(url):
print(domain)
print('Unsupported website, terminating program')
site=None
if args.t:
q.put(site)
return site

#setting up commandline argument parser
Expand All @@ -96,6 +102,7 @@ def MakeClass(url):
parser.add_argument('-f','--file', help="Use text file containing a list of URLs instead of single URL", action='store_true')
parser.add_argument('-d','--directory', help="Directory to place output files. Default ./")
parser.add_argument('-q','--quiet', help="Turns off most terminal output", action='store_true')
parser.add_argument('-t', help="Turns on multithreading mode. Recommend also enabling --quiet", action='store_true')
args=parser.parse_args()

if args.quiet:
Expand All @@ -122,6 +129,8 @@ def MakeClass(url):
ftype=args.output_type

if args.file:

#gets the list of urls
if not stdin:
f=open(args.url, 'r')
urls=f.readlines()
Expand All @@ -130,12 +139,31 @@ def MakeClass(url):
urls=[]
stdinput=sys.stdin.read()
urls=stdinput.split()
for i in urls:
#site=MakeClass(i)
if ftype=='epub':
MakeEpub(MakeClass(i))
else:
MakeText(MakeClass(i))

#the multithreaded variant
if args.t:
q=queue.Queue()
for i in urls:
t=threading.Thread(target=MakeClass, args=(i,), daemon=True)
t.start()
while threading.active_count()>1:
s=q.get()
if ftype=='epub':
#for site in s:
MakeEpub(s)
else:
#for site in s:
MakeText(s)

else:
for i in urls:
#site=MakeClass(i)
if ftype=='epub':
MakeEpub(MakeClass(i))
else:
MakeText(MakeClass(i))

#the single input version
else:
site=MakeClass(args.url)
if site==None:
Expand Down

0 comments on commit e5060af

Please sign in to comment.