mirror of https://gitlab.com/bashrc2/epicyon
Storing hashtags for incoming posts
parent
95f46cf276
commit
8ef0a72489
42
inbox.py
42
inbox.py
|
@ -12,6 +12,7 @@ import datetime
|
||||||
import time
|
import time
|
||||||
import json
|
import json
|
||||||
from shutil import copyfile
|
from shutil import copyfile
|
||||||
|
from utils import isPublicPost
|
||||||
from utils import getCachedPostFilename
|
from utils import getCachedPostFilename
|
||||||
from utils import removePostFromCache
|
from utils import removePostFromCache
|
||||||
from utils import urlPermitted
|
from utils import urlPermitted
|
||||||
|
@ -59,6 +60,45 @@ from webinterface import individualPostAsHtml
|
||||||
from webinterface import getIconsDir
|
from webinterface import getIconsDir
|
||||||
from question import questionUpdateVotes
|
from question import questionUpdateVotes
|
||||||
|
|
||||||
|
def storeHashTags(baseDir: str,postJsonObject: {}) -> None:
|
||||||
|
"""Extracts hashtags from an incoming post and updates the
|
||||||
|
relevant tags files.
|
||||||
|
"""
|
||||||
|
if not isPublicPost(postJsonObject):
|
||||||
|
return
|
||||||
|
if not postJsonObject.get('object'):
|
||||||
|
return
|
||||||
|
if not isinstance(postJsonObject['object'], dict):
|
||||||
|
return
|
||||||
|
if not postJsonObject['object'].get('tag'):
|
||||||
|
return
|
||||||
|
if not postJsonObject.get('id'):
|
||||||
|
return
|
||||||
|
if not isinstance(postJsonObject['object']['tag'], list):
|
||||||
|
return
|
||||||
|
tagsDir=baseDir+'/tags'
|
||||||
|
for tag in postJsonObject['object']['tag']:
|
||||||
|
if not tag.get('type'):
|
||||||
|
continue
|
||||||
|
if tag['type']!='Hashtag':
|
||||||
|
continue
|
||||||
|
if not tag.get('name'):
|
||||||
|
continue
|
||||||
|
tagName=tag['name'].replace('#','')
|
||||||
|
tagsFilename=tagsDir+'/'+tag['name']+'.txt'
|
||||||
|
postUrl=postJsonObject['id'].replace('/activity','').replace('/','#')
|
||||||
|
if not os.path.isfile(tagsFilename):
|
||||||
|
tagsFile=open(tagsFilename, "w+")
|
||||||
|
if tagsFile:
|
||||||
|
tagsFile.write(postUrl+'\n')
|
||||||
|
tagsFile.close()
|
||||||
|
else:
|
||||||
|
if postUrl not in open(tagsFilename).read():
|
||||||
|
tagsFile=open(tagsFilename, "a+")
|
||||||
|
if tagsFile:
|
||||||
|
tagsFile.write(postUrl+'\n')
|
||||||
|
tagsFile.close()
|
||||||
|
|
||||||
def inboxStorePostToHtmlCache(recentPostsCache: {},maxRecentPosts: int, \
|
def inboxStorePostToHtmlCache(recentPostsCache: {},maxRecentPosts: int, \
|
||||||
translate: {}, \
|
translate: {}, \
|
||||||
baseDir: str,httpPrefix: str, \
|
baseDir: str,httpPrefix: str, \
|
||||||
|
@ -1876,6 +1916,8 @@ def inboxAfterCapabilities(recentPostsCache: {},maxRecentPosts: int, \
|
||||||
|
|
||||||
inboxUpdateCalendar(baseDir,handle,postJsonObject)
|
inboxUpdateCalendar(baseDir,handle,postJsonObject)
|
||||||
|
|
||||||
|
storeHashTags(baseDir,postJsonObject)
|
||||||
|
|
||||||
if not unitTest:
|
if not unitTest:
|
||||||
if debug:
|
if debug:
|
||||||
print('DEBUG: saving inbox post as html to cache')
|
print('DEBUG: saving inbox post as html to cache')
|
||||||
|
|
Loading…
Reference in New Issue