-
-
Notifications
You must be signed in to change notification settings - Fork 37
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
2 changed files
with
105 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,45 @@ | ||
name: Build and Push Emojimix Data | ||
|
||
on: | ||
push: | ||
branches: | ||
- master | ||
|
||
jobs: | ||
build: | ||
runs-on: ubuntu-latest | ||
|
||
steps: | ||
- name: Checkout Repository | ||
uses: actions/checkout@v2 | ||
|
||
- name: Set up Python | ||
uses: actions/setup-python@v2 | ||
with: | ||
python-version: '3.9' | ||
|
||
- name: Install dependencies | ||
run: | | ||
python -m pip install --upgrade pip | ||
pip install requests | ||
- name: Run Python script | ||
run: | | ||
python scripts/fetch_emojimix_data.py | ||
- name: Move generated file to assets folder | ||
run: | | ||
mkdir -p ./assets/emojimix | ||
mv output.json ./assets/emojimix/emoji_data.json | ||
- name: Commit changes | ||
run: | | ||
git config --local user.email "[email protected]" | ||
git config --local user.name "GitHub Action" | ||
git add ./assets/emojimix/emoji_data.json | ||
git commit -m "Auto-generated emoji data" | ||
- name: Push changes | ||
uses: ad-m/github-push-action@master | ||
with: | ||
github_token: ${{ secrets.GITHUB_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,60 @@ | ||
import json | ||
import os | ||
import requests | ||
from collections import defaultdict | ||
|
||
def get_data_from_api(api_url): | ||
response = requests.get(api_url) | ||
if response.status_code == 200: | ||
return response.json() | ||
else: | ||
raise ValueError(f"Failed to fetch data from API: {response.status_code}") | ||
|
||
def compress_json(input_data): | ||
data = input_data["data"] | ||
known_supported_emoji = input_data["knownSupportedEmoji"] | ||
|
||
compressed_data = { | ||
"knownSupportedEmoji": known_supported_emoji, | ||
"data": defaultdict(dict), | ||
"date": [] | ||
} | ||
|
||
unique_dates = set() | ||
|
||
for emoji_codepoint, emoji_info in data.items(): | ||
combinations = emoji_info["combinations"] | ||
for left_codepoint, entries in combinations.items(): | ||
for entry in entries: | ||
date = entry["date"] | ||
unique_dates.add(date) | ||
|
||
sorted_dates = sorted(unique_dates) | ||
|
||
date_index_map = {date: idx for idx, date in enumerate(sorted_dates)} | ||
|
||
for emoji_codepoint, emoji_info in data.items(): | ||
combinations = emoji_info["combinations"] | ||
for left_codepoint, entries in combinations.items(): | ||
entries.sort(key=lambda x: x["date"]) | ||
|
||
latest_entry = entries[-1] | ||
left = latest_entry["leftEmojiCodepoint"] | ||
right = latest_entry["rightEmojiCodepoint"] | ||
date = latest_entry["date"] | ||
|
||
key = f'({left}, {right})' | ||
compressed_data["data"][key] = date_index_map[date] | ||
|
||
compressed_data["date"] = sorted_dates | ||
|
||
return compressed_data | ||
|
||
if __name__ == "__main__": | ||
api_url = "https://raw.githubusercontent.com/xsalazar/emoji-kitchen-backend/main/app/metadata.json" | ||
input_data = get_data_from_api(api_url) | ||
compressed_data = compress_json(input_data) | ||
# output_file = os.path.abspath("./assets/emojimix/output.json") | ||
|
||
with open('output.json', "w", encoding="utf-8") as f: | ||
json.dump(compressed_data, f, ensure_ascii=False, indent=2) |