Install black.

This commit is contained in:
Vishnu KS
2020-08-23 15:34:58 +05:30
parent 3bd0ce9bd6
commit d723ec905b
11 changed files with 3498 additions and 84 deletions

View File

@@ -7,65 +7,62 @@ import simplejson
# ARGUMENT HANDLING
try:
import argparse
parser = argparse.ArgumentParser(description='Process file.')
parser = argparse.ArgumentParser(description="Process file.")
parser.add_argument("--in_file", help="File to process, defaults to ./../README.MD")
parser.add_argument(
'--in_file',
help='File to process, defaults to ./../README.MD')
parser.add_argument(
'--out_file',
help='File to save to, defaults to ./../README-NEW.MD')
parser.add_argument(
'--input_file_type',
choices=['old', 'new'],
help='old if links are displayed in a list, new if in a table')
parser.add_argument(
'--sort_by',
choices = ['rating', 'title', 'author', 'year'],
help='defaults to rating')
parser.add_argument(
'--force',
dest='force',
action='store_true',
default=False
"--out_file", help="File to save to, defaults to ./../README-NEW.MD"
)
parser.add_argument(
'--store-json',
dest='store_json',
action='store_true',
default=False
"--input_file_type",
choices=["old", "new"],
help="old if links are displayed in a list, new if in a table",
)
parser.add_argument(
"--sort_by",
choices=["rating", "title", "author", "year"],
help="defaults to rating",
)
parser.add_argument("--force", dest="force", action="store_true", default=False)
parser.add_argument(
"--store-json", dest="store_json", action="store_true", default=False
)
flags = parser.parse_args()
except ImportError:
flags = None
def sort(library, key_to_sort_on, reverse = False):
def sort(library, key_to_sort_on, reverse=False):
new_library = {}
for key in library:
books = library[key]
new_library[key] = sorted(books, key=lambda k: k[key_to_sort_on], reverse=reverse)
new_library[key] = sorted(
books, key=lambda k: k[key_to_sort_on], reverse=reverse
)
return new_library
def format_library(library):
formated_library = []
for category in library:
for book in library[category]:
book["category"] = category[len("## "):]
book["category"] = category[len("## ") :]
formated_library.append(book)
return formated_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'
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
reverse = True if sort_by == "rating" else False
library = load(in_file, input_file_type)
get_goodread_info(library, force)
@@ -74,5 +71,7 @@ def main():
if store_json:
with open("out.json", "w") as f:
f.write(simplejson.dumps(format_library(library), indent=4, sort_keys=True))
if __name__ == '__main__':
if __name__ == "__main__":
main()