Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

more data checks in scrapers #705

Merged
merged 1 commit into from
Jul 16, 2024
Merged
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
4 changes: 3 additions & 1 deletion catalog/sites/bangumi.py
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,9 @@ def scrape(self):
[title] + (other_title or []) + ([orig_title] if orig_title else [])
)
localized_title = [{"lang": detect_language(t), "text": t} for t in titles]
localized_desc = [{"lang": detect_language(brief), "text": brief}]
localized_desc = (
[{"lang": detect_language(brief), "text": brief}] if brief else []
)
data = {
"localized_title": localized_title,
"localized_description": localized_desc,
Expand Down
4 changes: 3 additions & 1 deletion catalog/sites/bgg.py
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,9 @@ def scrape(self):
pd = ResourceContent(
metadata={
"localized_title": localized_title,
"localized_description": [{"lang": "en", "text": brief}],
"localized_description": (
[{"lang": "en", "text": brief}] if brief else []
),
"title": title,
"other_title": other_title,
"genre": category,
Expand Down
2 changes: 1 addition & 1 deletion catalog/sites/douban_book.py
Original file line number Diff line number Diff line change
Expand Up @@ -190,7 +190,7 @@ def scrape(self):
"subtitle": subtitle,
"localized_title": [{"lang": lang, "text": title}],
"localized_subtitle": [{"lang": lang, "text": subtitle}],
"localized_description": [{"lang": lang, "text": brief}],
"localized_description": [{"lang": lang, "text": brief}] if brief else [],
"orig_title": orig_title,
"author": authors,
"translator": translators,
Expand Down
4 changes: 3 additions & 1 deletion catalog/sites/douban_game.py
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,9 @@ def scrape(self):

titles = uniq([title] + other_title + ([orig_title] if orig_title else []))
localized_title = [{"lang": detect_language(t), "text": t} for t in titles]
localized_desc = [{"lang": detect_language(brief), "text": brief}]
localized_desc = (
[{"lang": detect_language(brief), "text": brief}] if brief else []
)

pd = ResourceContent(
metadata={
Expand Down
4 changes: 3 additions & 1 deletion catalog/sites/douban_movie.py
Original file line number Diff line number Diff line change
Expand Up @@ -212,7 +212,9 @@ def scrape(self):
+ (other_title if other_title else [])
)
localized_title = [{"lang": detect_language(t), "text": t} for t in titles]
localized_desc = [{"lang": detect_language(brief), "text": brief}]
localized_desc = (
[{"lang": detect_language(brief), "text": brief}] if brief else []
)
pd = ResourceContent(
metadata={
"title": title,
Expand Down
2 changes: 1 addition & 1 deletion catalog/sites/douban_music.py
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ def scrape(self):
data = {
"title": title,
"localized_title": localized_title,
"localized_description": [{"lang": lang, "text": brief}],
"localized_description": [{"lang": lang, "text": brief}] if brief else [],
"artist": artist,
"genre": genre,
"release_date": release_date,
Expand Down
4 changes: 3 additions & 1 deletion catalog/sites/goodreads.py
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,9 @@ def scrape(self, response=None):
lang = detect_language(b["title"] + " " + (b["description"] or ""))
data["localized_title"] = [{"lang": lang, "text": b["title"]}]
data["localized_subtitle"] = [] # Goodreads does not support subtitle
data["localized_description"] = [{"lang": lang, "text": b["description"]}]
data["localized_description"] = (
[{"lang": lang, "text": b["description"]}] if b["description"] else []
)

if data["brief"]:
data["brief"] = re.sub(
Expand Down
6 changes: 4 additions & 2 deletions catalog/sites/rss.py
Original file line number Diff line number Diff line change
Expand Up @@ -88,15 +88,17 @@ def scrape(self):
feed = self.parse_feed_from_url(self.url)
if not feed:
raise ValueError(f"no feed avaialble in {self.url}")
title = feed["title"]
title = feed["title"].strip()
if not title:
raise ParseError(self, "title")
desc = html_to_text(feed["description"])
lang = detect_language(title + " " + desc)
pd = ResourceContent(
metadata={
"title": title,
"brief": desc,
"localized_title": [{"lang": lang, "text": title}],
"localized_description": [{"lang": lang, "text": desc}],
"localized_description": [{"lang": lang, "text": desc}] if desc else [],
"host": (
[feed.get("itunes_author")] if feed.get("itunes_author") else []
),
Expand Down