-
-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Automatically update unicode data once a month.
- Loading branch information
1 parent
c6220f9
commit 9d45dcf
Showing
4 changed files
with
93 additions
and
43 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,37 @@ | ||
name: Update data | ||
|
||
on: | ||
workflow_dispatch: | ||
schedule: | ||
- cron: "0 0 1 * *" # run once a month | ||
|
||
jobs: | ||
resources: | ||
name: Update resources | ||
runs-on: ubuntu-latest | ||
steps: | ||
- uses: actions/checkout@v3 | ||
|
||
- name: Set up Python | ||
uses: actions/setup-python@v4 | ||
with: | ||
python-version: '3.8' | ||
|
||
- name: Install dependencies | ||
run: | | ||
python -m pip install --upgrade pip | ||
pip install -r requirements-data.txt | ||
- name: Update data | ||
run: python scripts/update_data.py | ||
|
||
- name: Commit data | ||
uses: test-room-7/action-update-file@v1 | ||
with: | ||
file-path: | | ||
fontbro/data/unicode-blocks.json | ||
fontbro/data/unicode-scripts.json | ||
commit-msg: "Update `unicode-blocks.json` and `unicode-scripts.json` data." | ||
committer-name: "Fabio Caccamo [bot]" | ||
committer-email: "[email protected]" | ||
github-token: ${{ secrets.WORKFLOWS_UPDATE_DATA_TOKEN }} |
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,4 @@ | ||
fonttools[woff,unicode,pathops] == 4.38.0 | ||
imagehash == 4.3.1 | ||
pillow == 9.4.0 | ||
python-fsutil == 0.9.3 |
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,50 @@ | ||
import fsutil | ||
from fontTools import unicodedata | ||
|
||
from fontbro import Font | ||
|
||
|
||
def _write_data_json(filepath, data): | ||
data_filepath = fsutil.join_path(__file__, filepath) | ||
fsutil.write_file_json(data_filepath, data, indent=4, sort_keys=True) | ||
|
||
|
||
def update_unicode_data(): | ||
blocks = [] | ||
blocks_cache = {} | ||
scripts = [] | ||
scripts_cache = {} | ||
for code in range(0, 0x110000): | ||
block_name = unicodedata.block(code) | ||
if block_name == "No_Block": | ||
continue | ||
block = { | ||
"name": block_name, | ||
} | ||
Font._populate_unicode_items_set(blocks, blocks_cache, block) | ||
script_tag = unicodedata.script(code) | ||
script_name = unicodedata.script_name(script_tag) | ||
script = { | ||
"name": script_name, | ||
"tag": script_tag, | ||
} | ||
Font._populate_unicode_items_set(scripts, scripts_cache, script) | ||
|
||
for block in blocks: | ||
block["characters_total"] = block["characters_count"] | ||
block.pop("characters_count", None) | ||
|
||
for script in scripts: | ||
script["characters_total"] = script["characters_count"] | ||
script.pop("characters_count", None) | ||
|
||
_write_data_json(filepath="../fontbro/data/unicode-blocks.json", data=blocks) | ||
_write_data_json(filepath="../fontbro/data/unicode-scripts.json", data=scripts) | ||
|
||
|
||
def main(): | ||
update_unicode_data() | ||
|
||
|
||
if __name__ == "__main__": | ||
main() |
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