-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
code: move categoriesConfig to separate module
- Loading branch information
Showing
3 changed files
with
27 additions
and
23 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
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
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,24 @@ | ||
import emoji | ||
import aiofiles | ||
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) | ||
|
||
async def getCategoriesConfig(categoryDictFile, songbookDict, allowEmojis = False): | ||
try: | ||
async with aiofiles.open(categoryDictFile, "rb") as configFile: | ||
configFileText = deUTF8(await configFile.read()) | ||
if not allowEmojis: | ||
configFileText = remove_emojis(configFileText) | ||
cats_dict = json.loads(configFileText) | ||
|
||
except FileNotFoundError: | ||
logger.warning("Category titles mapping file not found") | ||
cats_dict = {cat: cat for cat in sorted( | ||
songbookDict.keys())} | ||
return cats_dict |