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