Skip to content
This repository has been archived by the owner on Apr 1, 2024. It is now read-only.

Commit

Permalink
test
Browse files Browse the repository at this point in the history
  • Loading branch information
andlo committed Nov 4, 2018
1 parent 048ec90 commit 63f197c
Showing 1 changed file with 10 additions and 9 deletions.
19 changes: 10 additions & 9 deletions __init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ def handle_fairytalez(self, message):
self.speak_dialog('no_story')
return
self.speak_dialog('i_know_that', data={"story":result[0]})
self.log.info(result + " " index.get(result[0]))
#self.log.info(result + " " + result[0])
self.settings['story'] = result[0]
self.tell_story(index.get(result[0]), 0)

Expand All @@ -39,7 +39,6 @@ def handle_continue(self, message):

def tell_story(self, url, bookmark):
self.is_reading = True
bookmark = bookmark+1
self.settings['bookmark'] = bookmark
lines = self.get_story(url)
for line in lines[bookmark:]:
Expand All @@ -48,26 +47,28 @@ def tell_story(self, url, bookmark):
self.speak(line, wait=True)
self.settings['bookmark'] += 1
self.is_reading = False
self.settings['bookmark'] = 0
self.settings['story'] = None

def stop(self):
if self.is_reading:
self.is_reading = False
return True

#def get_soup(url):
# try:
# return BeautifulSoup(requests.get(url).text,"html.parser")
# except Exception as SockException:
# print(SockException)
def get_soup(self, url):
try:
return BeautifulSoup(requests.get(url).text,"html.parser")
except Exception as SockException:
self.log.error(SockException)

def get_story(self, url):
soup = BeautifulSoup(requests.get(url).text,"html.parser")
soup = self.get_soup(url)
lines = [a.text.strip() for a in soup.find(id="main").find_all("p")[1:]]
lines = [l for l in lines if not l.startswith("{") and not l.endswith("}")]
return lines

def get_index(self, url):
soup = BeautifulSoup(requests.get(url).text,"html.parser")
soup = self.get_soup(url)
index = {}
for link in soup.find(id="main").find_all('a'):
index.update({link.text[2:] : link.get("href")})
Expand Down

0 comments on commit 63f197c

Please sign in to comment.