fix goodreads search
This commit is contained in:
parent
c90d2fbd44
commit
53d63c3911
2 changed files with 19 additions and 2 deletions
|
@ -57,7 +57,20 @@ class Goodreads:
|
|||
results = []
|
||||
search_url = f"https://www.goodreads.com/search?page={page}&q={quote_plus(q)}"
|
||||
try:
|
||||
r = requests.get(search_url, timeout=3)
|
||||
r = requests.get(
|
||||
search_url,
|
||||
timeout=3,
|
||||
headers={
|
||||
"User-Agent": "Mozilla/5.0 (Macintosh; Intel Mac OS X 10.15; rv:107.0) Gecko/20100101 Firefox/107.0",
|
||||
"Accept": "text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8",
|
||||
"Accept-Language": "zh-CN,zh;q=0.8,zh-TW;q=0.7,zh-HK;q=0.5,en-US;q=0.3,en;q=0.2",
|
||||
"Accept-Encoding": "gzip, deflate",
|
||||
"Connection": "keep-alive",
|
||||
"DNT": "1",
|
||||
"Upgrade-Insecure-Requests": "1",
|
||||
"Cache-Control": "no-cache",
|
||||
},
|
||||
)
|
||||
if r.url.startswith("https://www.goodreads.com/book/show/"):
|
||||
# Goodreads will 302 if only one result matches ISBN
|
||||
site = SiteManager.get_site_by_url(r.url)
|
||||
|
|
|
@ -21,7 +21,11 @@ class Command(BaseCommand):
|
|||
if options["refresh"]:
|
||||
for site in MastodonApplication.objects.exclude(disabled=True):
|
||||
allow_multiple_redir = True
|
||||
response = create_app(site.api_domain, allow_multiple_redir)
|
||||
try:
|
||||
response = create_app(site.api_domain, allow_multiple_redir)
|
||||
except Exception as e:
|
||||
self.stdout.write(f"Error creating app on {site.api_domain}: {e}")
|
||||
continue
|
||||
if response.status_code != 200:
|
||||
self.stdout.write(
|
||||
f"Error creating app on {site.api_domain}: {response.status_code}"
|
||||
|
|
Loading…
Add table
Reference in a new issue