diff options
| author | 2020-03-04 23:30:37 +0530 | |
|---|---|---|
| committer | 2020-03-04 23:30:37 +0530 | |
| commit | 1c7b2d8a212ee837adf5dedb617310fea3b45080 (patch) | |
| tree | 31554df513dbc73fc1ddc5d1c2680906672bfc27 | |
| parent | Merge branch 'tags_overhaul' of https://github.com/RohanJnr/bot into tags_ove... (diff) | |
Use "pathlib" instead of "os" module and context manager
The pathlib module simplifies opening and reading files, hence the os module and the context manager are no longer used.
Diffstat (limited to '')
| -rw-r--r-- | bot/cogs/tags.py | 20 |
1 files changed, 9 insertions, 11 deletions
diff --git a/bot/cogs/tags.py b/bot/cogs/tags.py index 1c6b6aa21..7b5e3ed3a 100644 --- a/bot/cogs/tags.py +++ b/bot/cogs/tags.py @@ -1,5 +1,4 @@ import logging -import os import re import time from pathlib import Path @@ -39,18 +38,17 @@ class Tags(Cog): async def get_tags(self) -> None: """Get all tags.""" # Save all tags in memory. - tag_files = os.listdir("bot/resources/tags") + tag_files = Path("bot", "resources", "tags").iterdir() for file in tag_files: - p = Path("bot", "resources", "tags", file) - tag_title = os.path.splitext(file)[0].lower() - with p.open() as f: - tag = { - "title": tag_title, - "embed": { - "description": f.read() - } + file_path = Path(file) + tag_title = file_path.stem + tag = { + "title": tag_title, + "embed": { + "description": file_path.read_text() } - self._cache[tag_title] = tag + } + self._cache[tag_title] = tag @staticmethod def _fuzzy_search(search: str, target: str) -> float: |