Convert RSS to AP in reverse order

main
Bob Mottram 2020-10-07 19:46:42 +01:00
parent cbab604acc
commit 404912cd31
1 changed files with 15 additions and 5 deletions

View File

@ -8,6 +8,7 @@ __status__ = "Production"
import os import os
import time import time
from collections import OrderedDict
from newswire import getDictFromNewswire from newswire import getDictFromNewswire
from posts import createBlogPost from posts import createBlogPost
from utils import saveJson from utils import saveJson
@ -21,10 +22,16 @@ def updateFeedsIndex(baseDir: str, domain: str, postId: str) -> None:
indexFilename = basePath + '/outbox.index' indexFilename = basePath + '/outbox.index'
if os.path.isfile(indexFilename): if os.path.isfile(indexFilename):
feedsFile = open(indexFilename, 'a+') if postId not in open(indexFilename).read():
if feedsFile: try:
feedsFile.write(postId + '\n') with open(indexFilename, 'r+') as feedsFile:
feedsFile.close() content = feedsFile.read()
feedsFile.seek(0, 0)
feedsFile.write(postId + '\n' + content)
print('DEBUG: feeds post added to index')
except Exception as e:
print('WARN: Failed to write entry to feeds posts index ' +
indexFilename + ' ' + str(e))
else: else:
feedsFile = open(indexFilename, 'w+') feedsFile = open(indexFilename, 'w+')
if feedsFile: if feedsFile:
@ -42,7 +49,10 @@ def convertRSStoActivityPub(baseDir: str, httpPrefix: str,
if not os.path.isdir(basePath): if not os.path.isdir(basePath):
os.mkdir(basePath) os.mkdir(basePath)
for dateStr, item in newswire.items(): newswireReverse = \
OrderedDict(sorted(newswire.items(), reverse=True))
for dateStr, item in newswireReverse.items():
# convert the date to the format used by ActivityPub # convert the date to the format used by ActivityPub
dateStr = dateStr.replace(' ', 'T') dateStr = dateStr.replace(' ', 'T')
dateStr = dateStr.replace('+00:00', 'Z') dateStr = dateStr.replace('+00:00', 'Z')