Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 4 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -92,11 +92,13 @@ print(result)
[
{
"title": "The Murder After the Night Before",
"book_id": "38cb5b56-23f1-48fd-b4b3-a80e07a19775"
"book_id": "38cb5b56-23f1-48fd-b4b3-a80e07a19775",
"authors": ["Katy Brent"]
},
{
"title": "The Graces",
"book_id": "653b54b3-a79d-4c2e-ae40-eae281a91315"
"book_id": "653b54b3-a79d-4c2e-ae40-eae281a91315",
"authors": ["Laure Eve"]
}
]

Expand Down
22 changes: 18 additions & 4 deletions storygraph_api/parse/user_parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,16 +5,25 @@
class UserParser:
@staticmethod
@parsing_exception
def parse_html(html):
def parse_html(html, id_enclosure=None):
soup = BeautifulSoup(html, 'html.parser')
if id_enclosure:
soup = soup.find_all('div', attrs={"id": id_enclosure})[0]
books_list = []
books = soup.find_all('div', class_="book-title-author-and-series")
for book in books:
title = book.find('a').text.strip()
book_id = book.find('a')['href'].split('/')[-1]
a_list = book.find_all('a')
authors = []
for a in a_list:
if a['href'].startswith("/books/"):
title = a.text.strip()
book_id = a['href'].split('/')[-1]
if a['href'].startswith("/authors/"):
authors.append(a.text.strip())
books_list.append({
'title': title,
'book_id': book_id
'book_id': book_id,
'authors': authors
})
data = list({(book['title'], book['book_id']): book for book in books_list}.values())
return data
Expand All @@ -29,6 +38,11 @@ def to_read(uname, cookie):
content = UserScraper.to_read(uname,cookie)
return UserParser.parse_html(content)

@staticmethod
def up_next(uname, cookie):
content = UserScraper.to_read(uname, cookie)
return UserParser.parse_html(content, "up-next-section")

@staticmethod
def books_read(uname, cookie):
content = UserScraper.books_read(uname,cookie)
Expand Down
5 changes: 5 additions & 0 deletions storygraph_api/users_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,11 @@ def to_read(self,uname,cookie):
data = UserParser.to_read(uname,cookie)
return json.dumps(data,indent=4)

@handle_exceptions
def up_next(self, uname, cookie):
data = UserParser.up_next(uname,cookie)
return json.dumps(data,indent=4)

@handle_exceptions
def books_read(self,uname,cookie):
data = UserParser.books_read(uname,cookie)
Expand Down