Prepend to tags index file

main
Bob Mottram 2019-12-17 10:24:52 +00:00
parent b705c99521
commit 484bc2476d
1 changed files with 20 additions and 5 deletions

View File

@ -446,17 +446,32 @@ def updateHashtagsIndex(baseDir: str,tag: {},newPostId: str) -> None:
""" """
if tag['type']!='Hashtag': if tag['type']!='Hashtag':
return return
# create hashtags directory # create hashtags directory
tagsDir=baseDir+'/tags' tagsDir=baseDir+'/tags'
if not os.path.isdir(tagsDir): if not os.path.isdir(tagsDir):
os.mkdir(tagsDir) os.mkdir(tagsDir)
tagName=tag['name'] tagName=tag['name']
tagsFilename=tagsDir+'/'+tagName[1:]+'.txt' tagsFilename=tagsDir+'/'+tagName[1:]+'.txt'
tagFile=open(tagsFilename, "a+") tagline=newPostId+'\n'
if not tagFile:
return if not os.path.isfile(tagsFilename):
tagFile.write(newPostId+'\n') # create a new tags index file
tagFile.close() tagsFile=open(tagsFilename, "w+")
if tagsFile:
tagsFile.write(tagline)
tagsFile.close()
else:
# prepend to tags index file
if tagline not in open(tagsFilename).read():
try:
with open(tagsFilename, 'r+') as tagsFile:
content = tagsFile.read()
tagsFile.seek(0, 0)
tagsFile.write(tagline+content)
except Exception as e:
print('WARN: Failed to write entry to tags file '+ \
tagsFilename+' '+str(e))
def createPostBase(baseDir: str,nickname: str,domain: str,port: int, \ def createPostBase(baseDir: str,nickname: str,domain: str,port: int, \
toUrl: str,ccUrl: str,httpPrefix: str,content: str, \ toUrl: str,ccUrl: str,httpPrefix: str,content: str, \