-
-
Notifications
You must be signed in to change notification settings - Fork 53
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Workflow to generate plist file from dictionary.txt
- Loading branch information
1 parent
48a8854
commit e300b57
Showing
2 changed files
with
57 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
import plistlib | ||
|
||
INPUT_FILE = "../dictionary.txt" | ||
OUTPUT_FILE = "../dictionary.plist" | ||
|
||
def parse_line(line: str) -> tuple[str | None, str | None]: | ||
""" | ||
Parses a line in the format "<phrase><tab><shortcut><tab>" | ||
and returns the phrase and shortcut. If the line is not | ||
in the correct format, returns None for both values. | ||
""" | ||
parts = line.strip().split('\t') | ||
if len(parts) == 2: | ||
return parts[1], parts[0] | ||
else: | ||
return None, None | ||
|
||
# Read input from a file | ||
input_data = [] | ||
with open(INPUT_FILE, 'r', encoding='utf-8') as file: | ||
for line in file: | ||
phrase, shortcut = parse_line(line) | ||
if phrase is not None and shortcut is not None: | ||
input_data.append((phrase, shortcut)) | ||
|
||
# Create a list of dictionaries | ||
output_data = [{'phrase': phrase, 'shortcut': shortcut} for phrase, shortcut in input_data] | ||
|
||
# Write the plist to a file | ||
with open(OUTPUT_FILE, 'wb') as plist_file: | ||
plistlib.dump(output_data, plist_file, fmt=plistlib.FMT_XML) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
# 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 | ||
message: "chore: Update dictionary.plist" | ||
add: "*.plist" |