utils: Run black.
This commit is contained in:
@@ -5,7 +5,18 @@ from read_file import load
|
|||||||
from gooodreads import get_details
|
from gooodreads import get_details
|
||||||
from bs4 import BeautifulSoup
|
from bs4 import BeautifulSoup
|
||||||
|
|
||||||
required_fields = ["title", "author", "url", "rating", "year", "pages", "image_url", "description", "category"]
|
required_fields = [
|
||||||
|
"title",
|
||||||
|
"author",
|
||||||
|
"url",
|
||||||
|
"rating",
|
||||||
|
"year",
|
||||||
|
"pages",
|
||||||
|
"image_url",
|
||||||
|
"description",
|
||||||
|
"category",
|
||||||
|
]
|
||||||
|
|
||||||
|
|
||||||
def book_has_all_fields(book):
|
def book_has_all_fields(book):
|
||||||
for required_field in required_fields:
|
for required_field in required_fields:
|
||||||
@@ -14,12 +25,14 @@ def book_has_all_fields(book):
|
|||||||
return False
|
return False
|
||||||
return True
|
return True
|
||||||
|
|
||||||
|
|
||||||
def clean_category(category_raw):
|
def clean_category(category_raw):
|
||||||
if "### " in category_raw:
|
if "### " in category_raw:
|
||||||
return category_raw[4:]
|
return category_raw[4:]
|
||||||
if "## " in category_raw:
|
if "## " in category_raw:
|
||||||
return category_raw[3:]
|
return category_raw[3:]
|
||||||
|
|
||||||
|
|
||||||
if __name__ == "__main__":
|
if __name__ == "__main__":
|
||||||
library = load("../README.md", "new")
|
library = load("../README.md", "new")
|
||||||
existing_book_names_to_details = json.load(open("books.json"))
|
existing_book_names_to_details = json.load(open("books.json"))
|
||||||
@@ -36,14 +49,20 @@ if __name__ == "__main__":
|
|||||||
"title": title,
|
"title": title,
|
||||||
"author": book["author"],
|
"author": book["author"],
|
||||||
"url": book["url"],
|
"url": book["url"],
|
||||||
"category": category_name
|
"category": category_name,
|
||||||
}
|
}
|
||||||
fetched = get_details(new_book)
|
fetched = get_details(new_book)
|
||||||
if fetched:
|
if fetched:
|
||||||
print(f"✅ {title}")
|
print(f"✅ {title}")
|
||||||
existing_book_names_to_details[title] = new_book
|
existing_book_names_to_details[title] = new_book
|
||||||
with open("books.json", "w") as f:
|
with open("books.json", "w") as f:
|
||||||
json.dump(existing_book_names_to_details, f, sort_keys=True, indent=4, separators=(',', ': '))
|
json.dump(
|
||||||
|
existing_book_names_to_details,
|
||||||
|
f,
|
||||||
|
sort_keys=True,
|
||||||
|
indent=4,
|
||||||
|
separators=(",", ": "),
|
||||||
|
)
|
||||||
else:
|
else:
|
||||||
print(f"❌ Error while fetching {title}")
|
print(f"❌ Error while fetching {title}")
|
||||||
time.sleep(1)
|
time.sleep(1)
|
||||||
@@ -53,7 +72,13 @@ if __name__ == "__main__":
|
|||||||
book_list.append(book)
|
book_list.append(book)
|
||||||
|
|
||||||
with open("books.json", "w") as f:
|
with open("books.json", "w") as f:
|
||||||
json.dump(existing_book_names_to_details, f, sort_keys=True, indent=4, separators=(',', ': '))
|
json.dump(
|
||||||
|
existing_book_names_to_details,
|
||||||
|
f,
|
||||||
|
sort_keys=True,
|
||||||
|
indent=4,
|
||||||
|
separators=(",", ": "),
|
||||||
|
)
|
||||||
|
|
||||||
with open("books_list.json", "w") as f:
|
with open("books_list.json", "w") as f:
|
||||||
json.dump(book_list, f, sort_keys=True, indent=4, separators=(',', ': '))
|
json.dump(book_list, f, sort_keys=True, indent=4, separators=(",", ": "))
|
||||||
|
|||||||
Reference in New Issue
Block a user