Compare commits

..

2 commits

Author SHA1 Message Date
monosans 4236017ef8
Avoid using f.readlines() 2023-10-06 17:42:42 +03:00
monosans 1a858cd47d
Refactor file operations 2023-10-06 11:19:29 +03:00
3 changed files with 3 additions and 5 deletions

View file

@ -65,7 +65,7 @@ class KeyManager:
for filename in await aiofiles.os.listdir(os.path.join('api', 'secret')): for filename in await aiofiles.os.listdir(os.path.join('api', 'secret')):
if filename.endswith('.txt'): if filename.endswith('.txt'):
async with aiofiles.open(os.path.join('api', 'secret', 'filename')) as f: async with aiofiles.open(os.path.join('api', 'secret', 'filename')) as f:
for line in await f.readlines(): async for line in f:
if not line.strip(): if not line.strip():
continue continue

View file

@ -14,7 +14,7 @@ except ImportError:
load_dotenv() load_dotenv()
with open(os.path.join(helpers.root, 'api', 'config', 'config.yml', encoding='utf8')) as f: with open(os.path.join(helpers.root, 'api', 'config', 'config.yml'), encoding='utf8') as f:
credits_config = yaml.safe_load(f) credits_config = yaml.safe_load(f)
## MONGODB Setup ## MONGODB Setup

View file

@ -5,9 +5,7 @@ from rich import print
def remove_duplicate_keys(file): def remove_duplicate_keys(file):
with open(file, 'r', encoding='utf8') as f: with open(file, 'r', encoding='utf8') as f:
lines = f.readlines() unique_lines = set(f)
unique_lines = set(lines)
with open(file, 'w', encoding='utf8') as f: with open(file, 'w', encoding='utf8') as f:
f.writelines(unique_lines) f.writelines(unique_lines)