Skip to content

Commit

Permalink
fix get douban url error
Browse files Browse the repository at this point in the history
  • Loading branch information
malinkang committed Jul 16, 2024
1 parent 4c01293 commit a631186
Showing 1 changed file with 16 additions and 15 deletions.
31 changes: 16 additions & 15 deletions scripts/book.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,22 +23,23 @@ def get_douban_url(isbn):
print(f"get_douban_url {isbn} ")
params = {"query": isbn, "page": "1", "category": "book"}
r = requests.get("https://neodb.social/api/catalog/search", params=params)
books = r.json().get("data")
if books is None or len(books) == 0:
return None
results = list(filter(lambda x: x.get("isbn") == isbn, books))
if len(results) == 0:
return None
result = results[0]
urls = list(
filter(
lambda x: x.get("url").startswith("https://book.douban.com"),
result.get("external_resources", []),
if r.ok:
books = r.json().get("data")
if books is None or len(books) == 0:
return None
results = list(filter(lambda x: x.get("isbn") == isbn, books))
if len(results) == 0:
return None
result = results[0]
urls = list(
filter(
lambda x: x.get("url").startswith("https://book.douban.com"),
result.get("external_resources", []),
)
)
)
if len(urls) == 0:
return None
return urls[0].get("url")
if len(urls) == 0:
return None
return urls[0].get("url")


def insert_book_to_notion(books, index, bookId):
Expand Down

0 comments on commit a631186

Please sign in to comment.