Move function

merge-requests/30/head
Bob Mottram 2020-01-13 10:49:03 +00:00
parent 0b2a6910ec
commit b4bfca3def
2 changed files with 26 additions and 27 deletions

View File

@ -50,7 +50,6 @@ from content import replaceEmojiFromTags
from auth import createBasicAuthHeader from auth import createBasicAuthHeader
from config import getConfigParam from config import getConfigParam
from blocking import isBlocked from blocking import isBlocked
from schedule import addSchedulePost
try: try:
from BeautifulSoup import BeautifulSoup from BeautifulSoup import BeautifulSoup
except ImportError: except ImportError:
@ -474,6 +473,32 @@ def updateHashtagsIndex(baseDir: str,tag: {},newPostId: str) -> None:
print('WARN: Failed to write entry to tags file '+ \ print('WARN: Failed to write entry to tags file '+ \
tagsFilename+' '+str(e)) tagsFilename+' '+str(e))
def addSchedulePost(baseDir: str,nickname: str,domain: str, \
eventDateStr: str,postId: str) -> None:
"""Adds a scheduled post to the index
"""
handle=nickname+'@'+domain
scheduleIndexFilename=baseDir+'/accounts/'+handle+'/schedule.index'
indexStr=eventDateStr+' '+postId.replace('/','#')
if os.path.isfile(scheduleIndexFilename):
if indexStr not in open(scheduleIndexFilename).read():
try:
with open(scheduleIndexFilename, 'r+') as scheduleFile:
content = scheduleFile.read()
scheduleFile.seek(0, 0)
scheduleFile.write(indexStr+'\n'+content)
if debug:
print('DEBUG: scheduled post added to index')
except Exception as e:
print('WARN: Failed to write entry to scheduled posts index '+ \
scheduleIndexFilename+' '+str(e))
else:
scheduleFile=open(scheduleIndexFilename,'w')
if scheduleFile:
scheduleFile.write(indexStr+'\n')
scheduleFile.close()
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, \
followersOnly: bool,saveToFile: bool,clientToServer: bool, \ followersOnly: bool,saveToFile: bool,clientToServer: bool, \

View File

@ -12,32 +12,6 @@ import datetime
from utils import loadJson from utils import loadJson
from outbox import postMessageToOutbox from outbox import postMessageToOutbox
def addSchedulePost(baseDir: str,nickname: str,domain: str, \
eventDateStr: str,postId: str) -> None:
"""Adds a scheduled post to the index
"""
handle=nickname+'@'+domain
scheduleIndexFilename=baseDir+'/accounts/'+handle+'/schedule.index'
indexStr=eventDateStr+' '+postId.replace('/','#')
if os.path.isfile(scheduleIndexFilename):
if indexStr not in open(scheduleIndexFilename).read():
try:
with open(scheduleIndexFilename, 'r+') as scheduleFile:
content = scheduleFile.read()
scheduleFile.seek(0, 0)
scheduleFile.write(indexStr+'\n'+content)
if debug:
print('DEBUG: scheduled post added to index')
except Exception as e:
print('WARN: Failed to write entry to scheduled posts index '+ \
scheduleIndexFilename+' '+str(e))
else:
scheduleFile=open(scheduleIndexFilename,'w')
if scheduleFile:
scheduleFile.write(indexStr+'\n')
scheduleFile.close()
def updatePostSchedule(baseDir: str,handle: str,httpd,maxScheduledPosts: int) -> None: def updatePostSchedule(baseDir: str,handle: str,httpd,maxScheduledPosts: int) -> None:
"""Checks if posts are due to be delivered and if so moves them to the outbox """Checks if posts are due to be delivered and if so moves them to the outbox
""" """