adds code
This commit is contained in:
parent
e85a16d0f7
commit
3d72386e87
|
@ -0,0 +1,2 @@
|
|||
goodreads_library_export.csv
|
||||
reading.gmi
|
|
@ -0,0 +1,57 @@
|
|||
import csv
|
||||
|
||||
read_books = []
|
||||
to_read_books = []
|
||||
current = []
|
||||
|
||||
def main():
|
||||
get_books()
|
||||
sort_books()
|
||||
write_file()
|
||||
|
||||
def get_books():
|
||||
with open("goodreads_library_export.csv") as csv_file:
|
||||
csv_reader = csv.reader(csv_file, delimiter=",")
|
||||
line_count = 0
|
||||
for row in csv_reader:
|
||||
if line_count != 0:
|
||||
book = f"{row[1]} by {row[2]}"
|
||||
if row[18] == "read":
|
||||
read_books.append(book)
|
||||
|
||||
elif row[18] == "to-read":
|
||||
to_read_books.append(book)
|
||||
|
||||
elif row[18] == "currently-reading":
|
||||
current.append(book)
|
||||
|
||||
line_count += 1
|
||||
|
||||
def sort_books():
|
||||
read_books.sort()
|
||||
to_read_books.sort()
|
||||
current.sort()
|
||||
|
||||
def write_file():
|
||||
gemini_file = open("reading.gmi", "w")
|
||||
gemini_file.write("# Reading List\n")
|
||||
write_books(gemini_file)
|
||||
|
||||
def write_list(title, book_list, file):
|
||||
file.write(f"## {title} ({len(book_list)})\n")
|
||||
for book in book_list:
|
||||
file.write(f"{book}\n")
|
||||
file.write("\n")
|
||||
|
||||
def write_books(file):
|
||||
write_list("Currently Reading", current, file)
|
||||
write_list("Want to Read", to_read_books, file)
|
||||
write_list("Finished Reading", read_books, file)
|
||||
|
||||
if __name__ == "__main__":
|
||||
main()
|
||||
|
||||
|
||||
|
||||
|
||||
|
Loading…
Reference in New Issue