LiamKhoaLe commited on
Commit
7298c80
·
1 Parent(s): 36029c6

upd gutenberg

Browse files
Files changed (1) hide show
  1. app/services/project_gutenberg.py +4 -4
app/services/project_gutenberg.py CHANGED
@@ -1,17 +1,17 @@
1
  # app/services/project_gutenberg.py
2
- import httpx, logging, re
3
  from tenacity import retry, stop_after_attempt, wait_fixed
4
 
5
  logger = logging.getLogger("book-query")
6
 
7
- GUTENDEX = "https://gutendex.com/books?search="
8
 
9
  # Query for items return
10
  @retry(stop=stop_after_attempt(3), wait=wait_fixed(1))
11
  async def search(q: str):
12
  """Return at most 5 PDF-downloadable results from Gutendex."""
13
- url = f"{GUTENDEX}{q}"
14
- async with httpx.AsyncClient(timeout=10) as client:
15
  r = await client.get(url)
16
  r.raise_for_status()
17
  books = r.json().get("results", [])[:10]
 
1
  # app/services/project_gutenberg.py
2
+ import httpx, logging, re, urllib.parse
3
  from tenacity import retry, stop_after_attempt, wait_fixed
4
 
5
  logger = logging.getLogger("book-query")
6
 
7
+ GUTENDEX = "https://gutendex.com/books/?search="
8
 
9
  # Query for items return
10
  @retry(stop=stop_after_attempt(3), wait=wait_fixed(1))
11
  async def search(q: str):
12
  """Return at most 5 PDF-downloadable results from Gutendex."""
13
+ url = f"{GUTENDEX}{urllib.parse.quote_plus(q)}"
14
+ async with httpx.AsyncClient(timeout=10, follow_redirects=True) as client:
15
  r = await client.get(url)
16
  r.raise_for_status()
17
  books = r.json().get("results", [])[:10]