forked from indymedia/epicyon
flake8 format
parent
d55fe8bb59
commit
bfe37d5ae7
58
schedule.py
58
schedule.py
|
@ -13,7 +13,9 @@ from utils import getStatusNumber
|
|||
from utils import loadJson
|
||||
from outbox import postMessageToOutbox
|
||||
|
||||
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
|
||||
"""
|
||||
scheduleIndexFilename = baseDir + '/accounts/' + handle + '/schedule.index'
|
||||
|
@ -46,7 +48,8 @@ def updatePostSchedule(baseDir: str,handle: str,httpd,maxScheduledPosts: int) ->
|
|||
indexLines.append(line)
|
||||
# convert string date to int
|
||||
postTime = \
|
||||
datetime.datetime.strptime(dateStr,"%Y-%m-%dT%H:%M:%S%z").replace(tzinfo=None)
|
||||
datetime.datetime.strptime(dateStr, "%Y-%m-%dT%H:%M:%S%z")
|
||||
postTime = postTime.replace(tzinfo=None)
|
||||
postDaysSinceEpoch = \
|
||||
(postTime - datetime.datetime(1970, 1, 1)).days
|
||||
if daysSinceEpoch < postDaysSinceEpoch:
|
||||
|
@ -82,23 +85,23 @@ def updatePostSchedule(baseDir: str,handle: str,httpd,maxScheduledPosts: int) ->
|
|||
|
||||
if nickname:
|
||||
httpd.postToNickname = nickname
|
||||
if not postMessageToOutbox(postJsonObject,nickname, \
|
||||
httpd,baseDir, \
|
||||
httpd.httpPrefix, \
|
||||
httpd.domain, \
|
||||
httpd.domainFull, \
|
||||
httpd.onionDomain, \
|
||||
httpd.port, \
|
||||
httpd.recentPostsCache, \
|
||||
httpd.followersThreads, \
|
||||
httpd.federationList, \
|
||||
httpd.sendThreads, \
|
||||
httpd.postLog, \
|
||||
httpd.cachedWebfingers, \
|
||||
httpd.personCache, \
|
||||
httpd.allowDeletion, \
|
||||
httpd.useTor, \
|
||||
httpd.projectVersion, \
|
||||
if not postMessageToOutbox(postJsonObject, nickname,
|
||||
httpd, baseDir,
|
||||
httpd.httpPrefix,
|
||||
httpd.domain,
|
||||
httpd.domainFull,
|
||||
httpd.onionDomain,
|
||||
httpd.port,
|
||||
httpd.recentPostsCache,
|
||||
httpd.followersThreads,
|
||||
httpd.federationList,
|
||||
httpd.sendThreads,
|
||||
httpd.postLog,
|
||||
httpd.cachedWebfingers,
|
||||
httpd.personCache,
|
||||
httpd.allowDeletion,
|
||||
httpd.useTor,
|
||||
httpd.projectVersion,
|
||||
httpd.debug):
|
||||
indexLines.remove(line)
|
||||
os.remove(postFilename)
|
||||
|
@ -116,13 +119,15 @@ def updatePostSchedule(baseDir: str,handle: str,httpd,maxScheduledPosts: int) ->
|
|||
deleteSchedulePost = True
|
||||
|
||||
# write the new schedule index file
|
||||
scheduleIndexFile=baseDir+'/accounts/'+handle+'/schedule.index'
|
||||
scheduleIndexFile = \
|
||||
baseDir + '/accounts/' + handle + '/schedule.index'
|
||||
scheduleFile = open(scheduleIndexFile, "w+")
|
||||
if scheduleFile:
|
||||
for line in indexLines:
|
||||
scheduleFile.write(line)
|
||||
scheduleFile.close()
|
||||
|
||||
|
||||
def runPostSchedule(baseDir: str, httpd, maxScheduledPosts: int):
|
||||
"""Dispatches scheduled posts
|
||||
"""
|
||||
|
@ -134,11 +139,13 @@ def runPostSchedule(baseDir: str,httpd,maxScheduledPosts: int):
|
|||
if '@' not in account:
|
||||
continue
|
||||
# scheduled posts index for this account
|
||||
scheduleIndexFilename=baseDir+'/accounts/'+account+'/schedule.index'
|
||||
scheduleIndexFilename = \
|
||||
baseDir + '/accounts/' + account + '/schedule.index'
|
||||
if not os.path.isfile(scheduleIndexFilename):
|
||||
continue
|
||||
updatePostSchedule(baseDir, account, httpd, maxScheduledPosts)
|
||||
|
||||
|
||||
def runPostScheduleWatchdog(projectVersion: str, httpd) -> None:
|
||||
"""This tries to keep the scheduled post thread running even if it dies
|
||||
"""
|
||||
|
@ -155,15 +162,18 @@ def runPostScheduleWatchdog(projectVersion: str,httpd) -> None:
|
|||
httpd.thrPostSchedule.start()
|
||||
print('Restarting scheduled posts...')
|
||||
|
||||
|
||||
def removeScheduledPosts(baseDir: str, nickname: str, domain: str) -> None:
|
||||
"""Removes any scheduled posts
|
||||
"""
|
||||
# remove the index
|
||||
scheduleIndexFilename=baseDir+'/accounts/'+nickname+'@'+domain+'/schedule.index'
|
||||
scheduleIndexFilename = \
|
||||
baseDir + '/accounts/' + nickname + '@' + domain + '/schedule.index'
|
||||
if os.path.isfile(scheduleIndexFilename):
|
||||
os.remove(scheduleIndexFilename)
|
||||
# remove the scheduled posts
|
||||
scheduledDir=baseDir+'/accounts/'+nickname+'@'+domain+'/scheduled'
|
||||
scheduledDir = baseDir + '/accounts/' + \
|
||||
nickname + '@' + domain + '/scheduled'
|
||||
if not os.path.isdir(scheduledDir):
|
||||
return
|
||||
for scheduledPostFilename in os.listdir(scheduledDir):
|
||||
|
@ -171,5 +181,5 @@ def removeScheduledPosts(baseDir: str,nickname: str,domain: str) -> None:
|
|||
try:
|
||||
if os.path.isfile(filePath):
|
||||
os.remove(filePath)
|
||||
except:
|
||||
except BaseException:
|
||||
pass
|
||||
|
|
Loading…
Reference in New Issue