Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 27 additions & 0 deletions .github/dictionary_to_plist.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
import plistlib

INPUT_FILE = "dictionary.txt"
OUTPUT_FILE = "generated/dictionary.plist"


def parse_line(line: str) -> tuple[str, str] | tuple[None, None]:
"""Returns the shortcut and phrase from a line in the format "<shortcut><tab><phrase><tab>".
If the line is not in the above format, returns None for both values."""
parts = line.strip().split("\t")
if len(parts) == 2:
return parts[0], parts[1]
else:
return None, None


# Create a list of dictionaries from the input file
data = []
with open(INPUT_FILE, "r", encoding="utf-8") as file:
for line in file:
shortcut, phrase = parse_line(line)
if shortcut is not None and phrase is not None:
data.append({"phrase": phrase, "shortcut": shortcut})

# Write the plist to a file
with open(OUTPUT_FILE, "wb") as plist_file:
plistlib.dump(data, plist_file, fmt=plistlib.FMT_XML)
27 changes: 27 additions & 0 deletions .github/workflows/generate-plist.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
# This workflow will generate a plist file from the dictionary.txt file
name: Generate plist

on:
push:
branches:
- master
workflow_dispatch:

jobs:
deploy:
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v3

- name: Generate plist
run: python ${GITHUB_WORKSPACE}/.github/dictionary_to_plist.py

- name: Add and commit
uses: EndBug/add-and-commit@v9
with:
author_name: GitHub Actions
author_email: 41898282+github-actions[bot]@users.noreply.github.com
github_token: ${{ secrets.GITHUB_TOKEN }}
message: "chore: Update dictionary.plist"
add: "*.plist"
Loading