Skip to content

Commit

Permalink
code: remove async get and emoji import
Browse files Browse the repository at this point in the history
  • Loading branch information
matiusz committed Jun 19, 2024
1 parent 2df7dd0 commit dc03913
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 9 deletions.
2 changes: 1 addition & 1 deletion songbook/src/flask/flask_app.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ def serve_js():
@app.route("/<category>/<song>.html")
async def start(category = None, song = None):
songs = sb.sb
cats = await getCategoriesConfig(os.path.join(config.dataFolder, config.categoriesFile), songs, allowEmojis=True)
cats = getCategoriesConfig(os.path.join(config.dataFolder, config.categoriesFile), songs, allowEmojis=True)
try:
song = Song.loadFromCatAndTitle(category, song)

Expand Down
2 changes: 1 addition & 1 deletion songbook/src/songbookTeXmaker.py
Original file line number Diff line number Diff line change
Expand Up @@ -227,7 +227,7 @@ async def _asyncMain():

songbookDict = makeSongbookDict(gatheredSongs)

cats = await getCategoriesConfig(os.path.join(config.dataFolder, config.categoriesFile), songbookDict)
cats = getCategoriesConfig(os.path.join(config.dataFolder, config.categoriesFile), songbookDict)

for cat in songbookDict.values():
cat.setCatMapping(cats)
Expand Down
33 changes: 26 additions & 7 deletions songbook/src/tools/getCategoriesConfig.py
Original file line number Diff line number Diff line change
@@ -1,18 +1,37 @@
import emoji
import aiofiles
import re
import json

from .codings import deUTF8
from .loggerSetup import logging

logger = logging.getLogger(__name__)
def remove_emojis(s):
return ''.join(c for c in s if c not in emoji.EMOJI_DATA)
def remove_emojis(df_bios):
emoj = re.compile("["
u"\U0001F600-\U0001F64F" # emoticons
u"\U0001F300-\U0001F5FF" # symbols & pictographs
u"\U0001F680-\U0001F6FF" # transport & map symbols
u"\U0001F1E0-\U0001F1FF" # flags (iOS)
u"\U00002500-\U00002BEF" # chinese char
u"\U00002702-\U000027B0"
u"\U00002702-\U000027B0"
u"\U000024C2-\U0001F251"
u"\U0001f926-\U0001f937"
u"\U00010000-\U0010ffff"
u"\u2640-\u2642"
u"\u2600-\u2B55"
u"\u200d"
u"\u23cf"
u"\u23e9"
u"\u231a"
u"\ufe0f" # dingbats
u"\u3030"
"]+", re.UNICODE)
return re.sub(emoj, '', df_bios)

async def getCategoriesConfig(categoryDictFile, songbookDict, allowEmojis = False):
def getCategoriesConfig(categoryDictFile, songbookDict, allowEmojis = False):
try:
async with aiofiles.open(categoryDictFile, "rb") as configFile:
configFileText = deUTF8(await configFile.read())
with open(categoryDictFile, "rb") as configFile:
configFileText = deUTF8(configFile.read())
if not allowEmojis:
configFileText = remove_emojis(configFileText)
cats_dict = json.loads(configFileText)
Expand Down

0 comments on commit dc03913

Please sign in to comment.