forked from indymedia/epicyon
Option for maximum mirrored articles
parent
6411ffcd62
commit
9391fa57c9
|
@ -11981,7 +11981,8 @@ def loadTokens(baseDir: str, tokensDict: {}, tokensLookup: {}) -> None:
|
||||||
tokensLookup[token] = nickname
|
tokensLookup[token] = nickname
|
||||||
|
|
||||||
|
|
||||||
def runDaemon(maxNewswireFeedSizeKb: int,
|
def runDaemon(maxMirroredArticles: int,
|
||||||
|
maxNewswireFeedSizeKb: int,
|
||||||
maxNewswirePostsPerSource: int,
|
maxNewswirePostsPerSource: int,
|
||||||
showPublishedDateOnly: bool,
|
showPublishedDateOnly: bool,
|
||||||
votingTimeMins: int,
|
votingTimeMins: int,
|
||||||
|
@ -12116,6 +12117,9 @@ def runDaemon(maxNewswireFeedSizeKb: int,
|
||||||
# Show only the date at the bottom of posts, and not the time
|
# Show only the date at the bottom of posts, and not the time
|
||||||
httpd.showPublishedDateOnly = showPublishedDateOnly
|
httpd.showPublishedDateOnly = showPublishedDateOnly
|
||||||
|
|
||||||
|
# maximum number of news articles to mirror
|
||||||
|
httpd.maxMirroredArticles = maxMirroredArticles
|
||||||
|
|
||||||
if registration == 'open':
|
if registration == 'open':
|
||||||
httpd.registration = True
|
httpd.registration = True
|
||||||
else:
|
else:
|
||||||
|
|
19
epicyon.py
19
epicyon.py
|
@ -120,6 +120,11 @@ parser.add_argument('--maxFeedSize',
|
||||||
dest='maxNewswireFeedSizeKb', type=int,
|
dest='maxNewswireFeedSizeKb', type=int,
|
||||||
default=2048,
|
default=2048,
|
||||||
help='Maximum newswire rss/atom feed size in K')
|
help='Maximum newswire rss/atom feed size in K')
|
||||||
|
parser.add_argument('--maxMirroredArticles',
|
||||||
|
dest='maxMirroredArticles', type=int,
|
||||||
|
default=100,
|
||||||
|
help='Maximum number of news articles to mirror.' +
|
||||||
|
' Set to zero for indefinite mirroring.')
|
||||||
parser.add_argument('--postcache', dest='maxRecentPosts', type=int,
|
parser.add_argument('--postcache', dest='maxRecentPosts', type=int,
|
||||||
default=512,
|
default=512,
|
||||||
help='The maximum number of recent posts to store in RAM')
|
help='The maximum number of recent posts to store in RAM')
|
||||||
|
@ -1937,15 +1942,18 @@ if dateonly:
|
||||||
maxNewswirePostsPerSource = \
|
maxNewswirePostsPerSource = \
|
||||||
getConfigParam(baseDir, 'maxNewswirePostsPerSource')
|
getConfigParam(baseDir, 'maxNewswirePostsPerSource')
|
||||||
if maxNewswirePostsPerSource:
|
if maxNewswirePostsPerSource:
|
||||||
if maxNewswirePostsPerSource.isdigit():
|
args.maxNewswirePostsPerSource = int(maxNewswirePostsPerSource)
|
||||||
args.maxNewswirePostsPerSource = maxNewswirePostsPerSource
|
|
||||||
|
|
||||||
# set the maximum size of a newswire rss/atom feed in Kilobytes
|
# set the maximum size of a newswire rss/atom feed in Kilobytes
|
||||||
maxNewswireFeedSizeKb = \
|
maxNewswireFeedSizeKb = \
|
||||||
getConfigParam(baseDir, 'maxNewswireFeedSizeKb')
|
getConfigParam(baseDir, 'maxNewswireFeedSizeKb')
|
||||||
if maxNewswireFeedSizeKb:
|
if maxNewswireFeedSizeKb:
|
||||||
if maxNewswireFeedSizeKb.isdigit():
|
args.maxNewswireFeedSizeKb = int(maxNewswireFeedSizeKb)
|
||||||
args.maxNewswireFeedSizeKb = maxNewswireFeedSizeKb
|
|
||||||
|
maxMirroredArticles = \
|
||||||
|
getConfigParam(baseDir, 'maxMirroredArticles')
|
||||||
|
if maxMirroredArticles is not None:
|
||||||
|
args.maxMirroredArticles = int(maxMirroredArticles)
|
||||||
|
|
||||||
YTDomain = getConfigParam(baseDir, 'youtubedomain')
|
YTDomain = getConfigParam(baseDir, 'youtubedomain')
|
||||||
if YTDomain:
|
if YTDomain:
|
||||||
|
@ -1960,7 +1968,8 @@ if setTheme(baseDir, themeName, domain):
|
||||||
print('Theme set to ' + themeName)
|
print('Theme set to ' + themeName)
|
||||||
|
|
||||||
if __name__ == "__main__":
|
if __name__ == "__main__":
|
||||||
runDaemon(args.maxNewswireFeedSizeKb,
|
runDaemon(args.maxMirroredArticles,
|
||||||
|
args.maxNewswireFeedSizeKb,
|
||||||
args.maxNewswirePostsPerSource,
|
args.maxNewswirePostsPerSource,
|
||||||
args.dateonly,
|
args.dateonly,
|
||||||
args.votingtime,
|
args.votingtime,
|
||||||
|
|
|
@ -348,6 +348,17 @@ def newswireHashtagProcessing(session, baseDir: str, postJsonObject: {},
|
||||||
return True
|
return True
|
||||||
|
|
||||||
|
|
||||||
|
def createNewsMirror(baseDir: str, url: str,
|
||||||
|
maxMirroredArticles: int) -> bool:
|
||||||
|
"""Creates a local mirror of a news article
|
||||||
|
"""
|
||||||
|
mirrorDir = baseDir + '/accounts/newsmirror'
|
||||||
|
if not os.path.isdir(mirrorDir):
|
||||||
|
os.mkdir(mirrorDir)
|
||||||
|
|
||||||
|
return True
|
||||||
|
|
||||||
|
|
||||||
def convertRSStoActivityPub(baseDir: str, httpPrefix: str,
|
def convertRSStoActivityPub(baseDir: str, httpPrefix: str,
|
||||||
domain: str, port: int,
|
domain: str, port: int,
|
||||||
newswire: {},
|
newswire: {},
|
||||||
|
@ -356,7 +367,8 @@ def convertRSStoActivityPub(baseDir: str, httpPrefix: str,
|
||||||
session, cachedWebfingers: {},
|
session, cachedWebfingers: {},
|
||||||
personCache: {},
|
personCache: {},
|
||||||
federationList: [],
|
federationList: [],
|
||||||
sendThreads: [], postLog: []) -> None:
|
sendThreads: [], postLog: [],
|
||||||
|
maxMirroredArticles: int) -> None:
|
||||||
"""Converts rss items in a newswire into posts
|
"""Converts rss items in a newswire into posts
|
||||||
"""
|
"""
|
||||||
basePath = baseDir + '/accounts/news@' + domain + '/outbox'
|
basePath = baseDir + '/accounts/news@' + domain + '/outbox'
|
||||||
|
@ -431,6 +443,11 @@ def convertRSStoActivityPub(baseDir: str, httpPrefix: str,
|
||||||
if not blog:
|
if not blog:
|
||||||
continue
|
continue
|
||||||
|
|
||||||
|
mirrored = item[7]
|
||||||
|
if mirrored:
|
||||||
|
if not createNewsMirror(baseDir, url, maxMirroredArticles):
|
||||||
|
continue
|
||||||
|
|
||||||
idStr = \
|
idStr = \
|
||||||
httpPrefix + '://' + domain + '/users/news' + \
|
httpPrefix + '://' + domain + '/users/news' + \
|
||||||
'/statuses/' + statusNumber + '/replies'
|
'/statuses/' + statusNumber + '/replies'
|
||||||
|
@ -571,7 +588,8 @@ def runNewswireDaemon(baseDir: str, httpd,
|
||||||
httpd.personCache,
|
httpd.personCache,
|
||||||
httpd.federationList,
|
httpd.federationList,
|
||||||
httpd.sendThreads,
|
httpd.sendThreads,
|
||||||
httpd.postLog)
|
httpd.postLog,
|
||||||
|
httpd.maxMirroredArticles)
|
||||||
print('Newswire feed converted to ActivityPub')
|
print('Newswire feed converted to ActivityPub')
|
||||||
|
|
||||||
# wait a while before the next feeds update
|
# wait a while before the next feeds update
|
||||||
|
|
6
tests.py
6
tests.py
|
@ -290,7 +290,7 @@ def createServerAlice(path: str, domain: str, port: int,
|
||||||
onionDomain = None
|
onionDomain = None
|
||||||
i2pDomain = None
|
i2pDomain = None
|
||||||
print('Server running: Alice')
|
print('Server running: Alice')
|
||||||
runDaemon(1024, 5, False, 0, False, 1, False, False, False,
|
runDaemon(100, 1024, 5, False, 0, False, 1, False, False, False,
|
||||||
5, True, True, 'en', __version__,
|
5, True, True, 'en', __version__,
|
||||||
"instanceId", False, path, domain,
|
"instanceId", False, path, domain,
|
||||||
onionDomain, i2pDomain, None, port, port,
|
onionDomain, i2pDomain, None, port, port,
|
||||||
|
@ -353,7 +353,7 @@ def createServerBob(path: str, domain: str, port: int,
|
||||||
onionDomain = None
|
onionDomain = None
|
||||||
i2pDomain = None
|
i2pDomain = None
|
||||||
print('Server running: Bob')
|
print('Server running: Bob')
|
||||||
runDaemon(1024, 5, False, 0, False, 1, False, False, False,
|
runDaemon(100, 1024, 5, False, 0, False, 1, False, False, False,
|
||||||
5, True, True, 'en', __version__,
|
5, True, True, 'en', __version__,
|
||||||
"instanceId", False, path, domain,
|
"instanceId", False, path, domain,
|
||||||
onionDomain, i2pDomain, None, port, port,
|
onionDomain, i2pDomain, None, port, port,
|
||||||
|
@ -390,7 +390,7 @@ def createServerEve(path: str, domain: str, port: int, federationList: [],
|
||||||
onionDomain = None
|
onionDomain = None
|
||||||
i2pDomain = None
|
i2pDomain = None
|
||||||
print('Server running: Eve')
|
print('Server running: Eve')
|
||||||
runDaemon(1024, 5, False, 0, False, 1, False, False, False,
|
runDaemon(100, 1024, 5, False, 0, False, 1, False, False, False,
|
||||||
5, True, True, 'en', __version__,
|
5, True, True, 'en', __version__,
|
||||||
"instanceId", False, path, domain,
|
"instanceId", False, path, domain,
|
||||||
onionDomain, i2pDomain, None, port, port,
|
onionDomain, i2pDomain, None, port, port,
|
||||||
|
|
Loading…
Reference in New Issue