Skip to content

Commit

Permalink
Add fetch emojimix data workflow
Browse files Browse the repository at this point in the history
  • Loading branch information
DoroWolf committed Jun 21, 2024
1 parent 602f208 commit c0c5db9
Show file tree
Hide file tree
Showing 2 changed files with 105 additions and 0 deletions.
45 changes: 45 additions & 0 deletions .github/workflows/update-emojimix-data.yml
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 }}
60 changes: 60 additions & 0 deletions scripts/fetch_emojimix_data.py
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)

0 comments on commit c0c5db9

Please sign in to comment.