Skip to content

Commit

Permalink
Merge pull request #29 from theslavicbear/development
Browse files Browse the repository at this point in the history
Development
  • Loading branch information
theslavicbear authored Aug 13, 2019
2 parents 8ed2ced + 6025e8e commit 1dd8396
Show file tree
Hide file tree
Showing 8 changed files with 35 additions and 17 deletions.
4 changes: 3 additions & 1 deletion Ebook-Publisher.py
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,8 @@ def MakeClass(url):
args=parser.parse_args()

if args.quiet:
sys.stdout=open(os.devnull, 'w')
Common.quiet=True
#sys.stdout=open(os.devnull, 'w')
#print('quiet enabled')

stdin=False
Expand All @@ -113,6 +114,7 @@ def MakeClass(url):
else:
wd=args.directory
cwd=os.getcwd()
#TODO should use non-relative path
wd=os.path.join(cwd, wd)
if not os.path.exists(wd):
os.makedirs(wd)
Expand Down
6 changes: 3 additions & 3 deletions Site/Chyoa.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
from bs4 import BeautifulSoup
import re
import sys
from Site import Progress
from Site import Common
import os

class Chyoa:
Expand Down Expand Up @@ -65,10 +65,10 @@ def __init__(self, url):
sys.stdout=open(os.devnull, 'w')

#if args.quiet:
print(self.title+'\n'+str(self.authors)+'\n'+self.summary)
Common.prnt(self.title+'\n'+str(self.authors)+'\n'+self.summary)
#print(self.chapters)

self.pbar=Progress.Progress(self.length)
self.pbar=Common.Progress(self.length)


#for name in self.renames:
Expand Down
10 changes: 5 additions & 5 deletions Site/Classicreader.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
import requests
import re
import sys
from Site import Progress
from Site import Common
class Classicreader:

def __init__(self, url):
Expand All @@ -21,9 +21,9 @@ def __init__(self, url):
soup=BeautifulSoup(page.content, 'html.parser')
#grabs important metadata information
self.title=soup.find('span', attrs={'class': 'book-header'}).get_text()
print(self.title)
Common.prnt(self.title)
self.author=soup.find('span', attrs={'class': 'by-line'}).contents[1].get_text()
print(self.author)
Common.prnt(self.author)

#looks to see if on table of contents page
#exception handling could be removed from here
Expand All @@ -45,7 +45,7 @@ def __init__(self, url):
url='https://www.classicreader.com'+soup.find_all('a', attrs={'class':'categories'})[7].get('href')
page=requests.get(url)
soup=BeautifulSoup(page.content, 'html.parser')
print('got table of contents page')
Common.prnt('got table of contents page')
except:
paragraphs=soup.find_all('p')
#print(paragraphs)
Expand All @@ -64,7 +64,7 @@ def __init__(self, url):

links=soup.find_all('a', attrs={'class': 'chapter-title'})

self.pbar=Progress.Progress(len(links))
self.pbar=Common.Progress(len(links))
#self.pbar.Update()

for i in links:
Expand Down
15 changes: 15 additions & 0 deletions Site/Progress.py → Site/Common.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,13 @@
import sys

#Module contains common functions needed by all sites

quiet = False

def prnt(out, f=False):
if not quiet and not f:
print(out)

class Progress:

#toolbar_width=40
Expand All @@ -8,14 +16,21 @@ class Progress:
step=0

def __init__(self, size):
if quiet:
return
self.size=size
sys.stdout.write("[%s]" % (" " * self.size))
sys.stdout.flush()
sys.stdout.write("\b" * (self.size+1))

def Update(self):
if quiet:
return
sys.stdout.write("=")
sys.stdout.flush()

def End(self):
if quiet:
return
sys.stdout.write('\n')

6 changes: 3 additions & 3 deletions Site/Fanfiction.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
import re
import urllib.parse
import sys
from Site import Progress
from Site import Common

#TODO clean up and comment
class Fanfiction:
Expand Down Expand Up @@ -62,7 +62,7 @@ def __init__(self, url):
self.summary=soup.find_all('div', attrs={'class': 'xcontrast_txt'})[0].text.strip()
self.author=soup.find_all('a', attrs={'class': 'xcontrast_txt'})[2].text.strip()
self.title=soup.find('b', attrs={'class': 'xcontrast_txt'}).text.strip()
print(self.title+'\nby '+self.author+'\n'+self.summary)
Common.prnt(self.title+'\nby '+self.author+'\n'+self.summary)


#setup progress bar
Expand All @@ -73,7 +73,7 @@ def __init__(self, url):
print("Non-first page entered. Ebook-Publisher will only add subsequent pages and chapter titles will be wrong")
for i in soup.find_all('button', attrs={'type': 'BUTTON'}):
if i.text.strip()=='Next >':
self.pbar=Progress.Progress(len(self.chapters))
self.pbar=Common.Progress(len(self.chapters))
self.pbar.Update()
self.AddNextPage(soup)
break
Expand Down
3 changes: 2 additions & 1 deletion Site/Literotica.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import requests
from time import sleep
import sys
from Site import Common
class Literotica:
def __init__(self, url):
self.title=''
Expand All @@ -26,7 +27,7 @@ def __init__(self, url):
self.author=authorhtml.text.strip()
self.rawstoryhtml[0]=soup.find('div', attrs={'class': 'b-story-body-x x-r15'})
self.story=self.rawstoryhtml[0].text.strip()
print(self.title+' by '+self.author)
Common.prnt(self.title+' by '+self.author)

if soup.find('a', attrs={'class': 'b-pager-next'}) is not None:
self.AddNextPage(soup)
Expand Down
6 changes: 3 additions & 3 deletions Site/Wattpad.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
from bs4 import BeautifulSoup
import requests
import sys
from Site import Progress
from Site import Common
from random import randint

class Wattpad:
Expand Down Expand Up @@ -37,11 +37,11 @@ def __init__(self, url):
self.summary=soup.find('p', attrs={'class': 'item-description'}).get_text()
self.rawstoryhtml.append(soup.find('pre'))

print(self.title+'\nby '+ self.author+'\n'+self.summary)
Common.prnt(self.title+'\nby '+ self.author+'\n'+self.summary)

self.length=len(soup.find('ul', attrs={'class':'table-of-contents'}).find_all('li'))

self.pbar=Progress.Progress(self.length)
self.pbar=Common.Progress(self.length)
self.pbar.Update()

#print(self.rawstoryhtml[0].prettify())
Expand Down
2 changes: 1 addition & 1 deletion Site/__init__.py
Original file line number Diff line number Diff line change
@@ -1 +1 @@
__all__=["Literotica","Fanfiction","Classicreader","Chyoa","Wattpad"]
__all__=["Literotica","Fanfiction","Classicreader","Chyoa","Wattpad", "Common"]

0 comments on commit 1dd8396

Please sign in to comment.