[hanzi-flash] hsk stuff
This commit is contained in:
parent
4cdfbd93a2
commit
7a5f5f1dc0
@ -2,4 +2,9 @@
|
|||||||
|
|
||||||
Generate flashcards for a range of frequent hanzi characters.
|
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.
|
There are multiple sources for words:
|
||||||
|
|
||||||
|
- [hanziDB CSV](https://github.com/ruddfawcett/hanziDB.csv) (purely frequency based)
|
||||||
|
- [hsk CSV](https://github.com/plaktos/hsk_csv) (common usage words, graded by difficulty)
|
||||||
|
|
||||||
|
Be careful to keep the filenames as `hanzi_db.csv` and `hsk*.csv` because the script tries to recognize these.
|
||||||
|
@ -8,6 +8,7 @@ Based on https://github.com/ruddfawcett/hanziDB.csv
|
|||||||
import csv
|
import csv
|
||||||
import itertools
|
import itertools
|
||||||
import argparse
|
import argparse
|
||||||
|
import re
|
||||||
from pathlib import Path
|
from pathlib import Path
|
||||||
|
|
||||||
parser = argparse.ArgumentParser()
|
parser = argparse.ArgumentParser()
|
||||||
@ -17,9 +18,15 @@ parser.add_argument("-O", "--output", default="hanzi_flash.csv", type=Path)
|
|||||||
parser.add_argument("-i", "--input", default="hanzi_db.csv", type=Path)
|
parser.add_argument("-i", "--input", default="hanzi_db.csv", type=Path)
|
||||||
args = parser.parse_args()
|
args = parser.parse_args()
|
||||||
|
|
||||||
|
offset = 1
|
||||||
|
|
||||||
|
fname: str = args.input.stem
|
||||||
|
if fname.startswith("hsk"):
|
||||||
|
offset = 0
|
||||||
|
|
||||||
with open(args.input) as csv_file:
|
with open(args.input) as csv_file:
|
||||||
reader = csv.reader(csv_file)
|
reader = csv.reader(csv_file)
|
||||||
with open(args.output, "w") as outp_file:
|
with open(args.output, "w") as outp_file:
|
||||||
writer = csv.writer(outp_file)
|
writer = csv.writer(outp_file)
|
||||||
for row in itertools.islice(reader, args.start, args.end + 1):
|
for row in itertools.islice(reader, args.start, args.end + 1):
|
||||||
writer.writerow([row[1], f"{row[2]} ({row[3]})"])
|
writer.writerow([row[offset], f"{row[offset+1]} ({row[offset+2]})"])
|
||||||
|
Loading…
Reference in New Issue
Block a user