From 4cdfbd93a21a6aa6afd5a85a33bb85ce873e8684 Mon Sep 17 00:00:00 2001 From: dogeystamp Date: Thu, 6 Jun 2024 15:19:50 -0400 Subject: [PATCH] [hanzi-flash] added --- hanzi-flash/README.md | 5 +++++ hanzi-flash/hanzi_flash.py | 25 +++++++++++++++++++++++++ 2 files changed, 30 insertions(+) create mode 100644 hanzi-flash/README.md create mode 100644 hanzi-flash/hanzi_flash.py diff --git a/hanzi-flash/README.md b/hanzi-flash/README.md new file mode 100644 index 0000000..b43682b --- /dev/null +++ b/hanzi-flash/README.md @@ -0,0 +1,5 @@ +# hanzi-flash + +Generate flashcards for a range of frequent hanzi characters. + +You need the [hanziDB CSV](https://github.com/ruddfawcett/hanziDB.csv) file for this to work. diff --git a/hanzi-flash/hanzi_flash.py b/hanzi-flash/hanzi_flash.py new file mode 100644 index 0000000..62e5d59 --- /dev/null +++ b/hanzi-flash/hanzi_flash.py @@ -0,0 +1,25 @@ +#!/usr/bin/env python3 +""" +Generate flashcards for a range of frequent hanzi characters. + +Based on https://github.com/ruddfawcett/hanziDB.csv +""" + +import csv +import itertools +import argparse +from pathlib import Path + +parser = argparse.ArgumentParser() +parser.add_argument("-s", "--start", default=0, type=int) +parser.add_argument("-e", "--end", default=99999999, type=int) +parser.add_argument("-O", "--output", default="hanzi_flash.csv", type=Path) +parser.add_argument("-i", "--input", default="hanzi_db.csv", type=Path) +args = parser.parse_args() + +with open(args.input) as csv_file: + reader = csv.reader(csv_file) + with open(args.output, "w") as outp_file: + writer = csv.writer(outp_file) + for row in itertools.islice(reader, args.start, args.end + 1): + writer.writerow([row[1], f"{row[2]} ({row[3]})"])