Skip to content

Instantly share code, notes, and snippets.

@aadishv
Last active February 7, 2025 06:28
Show Gist options
  • Select an option

  • Save aadishv/b57cc1a11ef07bdaa96ea40309eb22cb to your computer and use it in GitHub Desktop.

Select an option

Save aadishv/b57cc1a11ef07bdaa96ea40309eb22cb to your computer and use it in GitHub Desktop.
new and improved utility for generating my Chinese flashcards!
# https://www.hskflashcards.com/downloads/ > Integrated Chinese, 3rd edition
# [above] > PlecoDict 2.0 > part 1
# * Download, save as "file.xml" in working directory
# * Run `yq -p=xml -o=json file.xml` (if not installed, `brew install yq`)
# * Save this script as "main.py" in working directory
# * Open a terminal in working directory and run `python3 main.py > output.txt`
# * Import "output.txt" into Fresh Cards (or any app supporting )
import json
data = json.load(open('file.json'))
for card in data['plecoflash']['cards']['card']:
phrase = card['entry']['headword']
if len(phrase[0]) != 1:
phrase = list(filter(lambda a: a['+@charset'] == 'sc', phrase))[0]['+content']
pinyin = card['entry']['pron']['+content']
english = card['entry']['defn']
level = card['catassign']['+@category'].split()[-1]
if int(level) > 6:
continue
print(f"front-text: {english}")
print(f"back-text: {phrase} ({pinyin})")
print(f"tags: l{level}")
print()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment