mirror of https://gitlab.com/bashrc2/epicyon
Replace file operations with function
parent
784808961a
commit
27ce1a8772
|
|
@ -120,9 +120,11 @@ def _search_virtual_box_posts(base_dir: str, nickname: str, domain: str,
|
||||||
post_filename = path + '/' + post_filename.strip()
|
post_filename = path + '/' + post_filename.strip()
|
||||||
if not os.path.isfile(post_filename):
|
if not os.path.isfile(post_filename):
|
||||||
continue
|
continue
|
||||||
with open(post_filename, 'r', encoding='utf-8') as fp_post:
|
data = load_string(post_filename,
|
||||||
data = fp_post.read().lower()
|
'EX: _search_virtual_box_posts ' +
|
||||||
|
'unable to read ' + post_filename)
|
||||||
|
if data is not None:
|
||||||
|
data = data.lower()
|
||||||
not_found: bool = False
|
not_found: bool = False
|
||||||
for keyword in search_words:
|
for keyword in search_words:
|
||||||
if keyword not in data:
|
if keyword not in data:
|
||||||
|
|
@ -180,9 +182,10 @@ def search_box_posts(base_dir: str, nickname: str, domain: str,
|
||||||
for root, _, fnames in os.walk(path):
|
for root, _, fnames in os.walk(path):
|
||||||
for fname in fnames:
|
for fname in fnames:
|
||||||
file_path = os.path.join(root, fname)
|
file_path = os.path.join(root, fname)
|
||||||
try:
|
data = load_string(file_path,
|
||||||
with open(file_path, 'r', encoding='utf-8') as fp_post:
|
'EX: search_box_posts unable to read ' +
|
||||||
data = fp_post.read()
|
file_path + ' [ex]')
|
||||||
|
if data is not None:
|
||||||
data_lower = data.lower()
|
data_lower = data.lower()
|
||||||
|
|
||||||
not_found: bool = False
|
not_found: bool = False
|
||||||
|
|
@ -226,8 +229,5 @@ def search_box_posts(base_dir: str, nickname: str, domain: str,
|
||||||
res.append(file_path)
|
res.append(file_path)
|
||||||
if len(res) >= max_results:
|
if len(res) >= max_results:
|
||||||
return res
|
return res
|
||||||
except OSError as exc:
|
|
||||||
print('EX: search_box_posts unable to read ' +
|
|
||||||
file_path + ' ' + str(exc))
|
|
||||||
break
|
break
|
||||||
return res
|
return res
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue