mirror of https://gitlab.com/bashrc2/epicyon
Search function
parent
51db9230ae
commit
4e9077547b
26
utils.py
26
utils.py
|
@ -7,6 +7,7 @@ __email__ = "bob@freedombone.net"
|
||||||
__status__ = "Production"
|
__status__ = "Production"
|
||||||
|
|
||||||
import os
|
import os
|
||||||
|
import re
|
||||||
import time
|
import time
|
||||||
import shutil
|
import shutil
|
||||||
import datetime
|
import datetime
|
||||||
|
@ -729,3 +730,28 @@ def isBlogPost(postJsonObject: {}) -> bool:
|
||||||
if postJsonObject['object']['type'] != 'Article':
|
if postJsonObject['object']['type'] != 'Article':
|
||||||
return False
|
return False
|
||||||
return True
|
return True
|
||||||
|
|
||||||
|
|
||||||
|
def searchBoxPosts(baseDir: str, nickname: str, domain: str,
|
||||||
|
searchRegex: str, maxResults: int,
|
||||||
|
boxName='outbox') -> []:
|
||||||
|
"""Uses a regular expression to search for posts
|
||||||
|
and returns a list of the filenames
|
||||||
|
"""
|
||||||
|
path = baseDir + '/accounts' + nickname + '@' + domain + '/' + boxName
|
||||||
|
if not os.path.isdir(path):
|
||||||
|
return []
|
||||||
|
regObj = re.compile(searchRegex)
|
||||||
|
|
||||||
|
res = []
|
||||||
|
for root, dirs, fnames in os.walk(path):
|
||||||
|
for fname in fnames:
|
||||||
|
filePath = os.path.join(root, fname)
|
||||||
|
with open(filePath, 'r') as file:
|
||||||
|
data = file.read()
|
||||||
|
if not regObj.match(data):
|
||||||
|
continue
|
||||||
|
res.append(filePath)
|
||||||
|
if len(res) >= maxResults:
|
||||||
|
return res
|
||||||
|
return res
|
||||||
|
|
Loading…
Reference in New Issue