From 5bb6865ba67774f911a1f549045195c185fc493a Mon Sep 17 00:00:00 2001 From: Vishnu KS Date: Sun, 23 Aug 2020 23:11:05 +0530 Subject: [PATCH] utils: Run black. --- utils/update_json_files.py | 35 ++++++++++++++++++++++++++++++----- 1 file changed, 30 insertions(+), 5 deletions(-) diff --git a/utils/update_json_files.py b/utils/update_json_files.py index 987f69a..67c3af1 100644 --- a/utils/update_json_files.py +++ b/utils/update_json_files.py @@ -5,7 +5,18 @@ from read_file import load from gooodreads import get_details 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): for required_field in required_fields: @@ -14,12 +25,14 @@ def book_has_all_fields(book): return False return True + def clean_category(category_raw): if "### " in category_raw: return category_raw[4:] if "## " in category_raw: return category_raw[3:] + if __name__ == "__main__": library = load("../README.md", "new") existing_book_names_to_details = json.load(open("books.json")) @@ -36,14 +49,20 @@ if __name__ == "__main__": "title": title, "author": book["author"], "url": book["url"], - "category": category_name + "category": category_name, } fetched = get_details(new_book) if fetched: print(f"✅ {title}") existing_book_names_to_details[title] = new_book 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: print(f"❌ Error while fetching {title}") time.sleep(1) @@ -53,7 +72,13 @@ if __name__ == "__main__": book_list.append(book) 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: - json.dump(book_list, f, sort_keys=True, indent=4, separators=(',', ': ')) + json.dump(book_list, f, sort_keys=True, indent=4, separators=(",", ": "))