Skip to content

Commit

Permalink
Workflow to generate plist file from dictionary.txt
Browse files Browse the repository at this point in the history
  • Loading branch information
DenverCoder1 committed Sep 14, 2023
1 parent 48a8854 commit e300b57
Show file tree
Hide file tree
Showing 2 changed files with 57 additions and 0 deletions.
31 changes: 31 additions & 0 deletions .github/dictionary_to_plist.py
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)
26 changes: 26 additions & 0 deletions .github/workflows/generate-plist.yml
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"

0 comments on commit e300b57

Please sign in to comment.