Skip to content

Commit

Permalink
revert PyICU
Browse files Browse the repository at this point in the history
  • Loading branch information
axif0 committed Nov 7, 2024
1 parent efb2f0b commit bb4bf6d
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 40 deletions.
3 changes: 0 additions & 3 deletions src/scribe_data/check/check_pyicu.py
Original file line number Diff line number Diff line change
Expand Up @@ -69,9 +69,6 @@ def fetch_wheel_releases():
"""
url = "https://api.github.com/repos/cgohlke/pyicu-build/releases"
response = requests.get(url)
if response.status_code == 403 and "rate limit exceeded" in response.text.lower():
print("GitHub API rate limit exceeded. Please try again later.")
return [], 0.0 # Return empty list and zero size when rate limit is hit
response.raise_for_status() # raise an error for bad responses

available_wheels = []
Expand Down
15 changes: 1 addition & 14 deletions src/scribe_data/cli/get.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@

import os # for removing original JSON files
import subprocess
import sys
from pathlib import Path
from typing import List, Union

Expand All @@ -36,11 +35,6 @@
)
from scribe_data.wikidata.query_data import query_data

from scribe_data.check.check_pyicu import (
check_and_install_pyicu,
check_if_pyicu_installed,
)


def get_data(
language: str = None,
Expand Down Expand Up @@ -142,14 +136,7 @@ def get_data(
# MARK: Emojis

elif data_type in {"emoji-keywords", "emoji_keywords"}:
if not check_if_pyicu_installed():
check_and_install_pyicu()
# Try to dynamically import the PyICU module
try:
generate_emoji(language=language, output_dir=output_dir)
except ImportError:
os.execv(sys.executable, ["python"] + sys.argv)
generate_emoji(language=language, output_dir=output_dir)
generate_emoji(language=language, output_dir=output_dir)

# MARK: Query Data

Expand Down
53 changes: 30 additions & 23 deletions src/scribe_data/unicode/generate_emoji_keywords.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,10 @@
import os
from pathlib import Path

from scribe_data.check.check_pyicu import (
check_and_install_pyicu,
check_if_pyicu_installed,
)
from scribe_data.unicode.process_unicode import gen_emoji_lexicon
from scribe_data.utils import export_formatted_data, get_language_iso

Expand Down Expand Up @@ -51,30 +55,33 @@ def generate_emoji(language, output_dir: str = None):
-------
None: The function does not return any value but outputs data to the specified directory.
"""
if check_and_install_pyicu() and check_if_pyicu_installed() is False:
print("Thank you.")

iso = get_language_iso(language=language)
path_to_cldr_annotations = (
Path(__file__).parent / "cldr-annotations-full" / "annotations"
)
if iso in os.listdir(path_to_cldr_annotations):
print(f"Emoji Generation for language {language} is supported")
if check_if_pyicu_installed():
iso = get_language_iso(language=language)
path_to_cldr_annotations = (
Path(__file__).parent / "cldr-annotations-full" / "annotations"
)
if iso in os.listdir(path_to_cldr_annotations):
print(f"Emoji Generation for language {language} is supported")

else:
print(f"Emoji Generation for language {language} is not supported")
return
else:
print(f"Emoji Generation for language {language} is not supported")
return

updated_path = output_dir[2:] if output_dir.startswith("./") else output_dir
export_dir = Path(updated_path) / language.capitalize()
export_dir.mkdir(parents=True, exist_ok=True)
updated_path = output_dir[2:] if output_dir.startswith("./") else output_dir
export_dir = Path(updated_path) / language.capitalize()
export_dir.mkdir(parents=True, exist_ok=True)

if emoji_keywords_dict := gen_emoji_lexicon(
language=language,
emojis_per_keyword=EMOJI_KEYWORDS_DICT,
):
export_formatted_data(
file_path=output_dir,
formatted_data=emoji_keywords_dict,
query_data_in_use=True,
language=language.capitalize(),
data_type=DATA_TYPE,
)
if emoji_keywords_dict := gen_emoji_lexicon(
language=language,
emojis_per_keyword=EMOJI_KEYWORDS_DICT,
):
export_formatted_data(
file_path=output_dir,
formatted_data=emoji_keywords_dict,
query_data_in_use=True,
language=language.capitalize(),
data_type=DATA_TYPE,
)

0 comments on commit bb4bf6d

Please sign in to comment.