def main(): from read_file import load from gooodreads import get_goodread_info from write_file import render in_file = flags.in_file or './../README.MD' out_file = flags.out_file or './../README-new.md' file_type = flags.file_type or 'new' sort_by = flags.sort_by or 'rating' reverse = True if sort_by == 'rating' else False library = load(in_file, file_type) get_goodread_info(library) library = sort(library, sort_by, reverse) render(in_file, out_file, library)
def main(): from read_file import load from gooodreads import get_goodread_info from write_file import render in_file = flags.in_file or "./../README.md" out_file = flags.out_file or "./../README-new.md" input_file_type = flags.input_file_type or "new" sort_by = flags.sort_by or "rating" force = flags.force store_json = flags.store_json reverse = True if sort_by == "rating" else False library = load(in_file, input_file_type) get_goodread_info(library, force) library = sort(library, sort_by, reverse) render(in_file, out_file, library) if store_json: with open("out.json", "w") as f: f.write(simplejson.dumps(format_library(library), indent=4, sort_keys=True))
for required_field in required_fields: if required_field not in existing_book: print(f"Missing {required_field}") 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")) for category in library: category_name = clean_category(category) for book in library[category]: if (title := book["title"]) in existing_book_names_to_details: existing_book = existing_book_names_to_details[title] if book_has_all_fields(existing_book): print(f"🆗 {title}") continue new_book = { "title": title, "author": book["author"], "url": book["url"], "category": category_name,