forked from indymedia/epicyon
Prepend to tags index file
parent
b705c99521
commit
484bc2476d
25
posts.py
25
posts.py
|
@ -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, \
|
||||||
|
|
Loading…
Reference in New Issue