2021-01-14 04:47:44 +00:00
|
|
|
#!/usr/bin/env python
|
2021-01-14 04:41:14 +00:00
|
|
|
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")
|
2021-01-14 04:47:44 +00:00
|
|
|
gemini_file.write("# swiftmandolin's reading list\n")
|
2021-01-14 04:41:14 +00:00
|
|
|
write_books(gemini_file)
|
2021-01-14 04:47:44 +00:00
|
|
|
write_footer(gemini_file)
|
2021-01-14 04:41:14 +00:00
|
|
|
|
|
|
|
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):
|
2021-01-14 04:47:44 +00:00
|
|
|
write_list("currently reading", current, file)
|
|
|
|
write_list("want to read", to_read_books, file)
|
|
|
|
write_list("finished reading", read_books, file)
|
|
|
|
|
|
|
|
def write_footer(file):
|
|
|
|
file.write("\n")
|
2021-01-14 04:50:03 +00:00
|
|
|
file.write("=> https://git.sr.ht/~swiftmandolin/gemini-goodreads generated from goodreads csv")
|
2021-01-14 04:41:14 +00:00
|
|
|
|
|
|
|
if __name__ == "__main__":
|
|
|
|
main()
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|