Set a maximum number of posts to appear in the newswire column

This commit is contained in:
bashrc committed 2020-11-22 11:48:53 +00:00
1 parent 0e2a5e0965
commit 7a01f422cf
5 files changed
+34 -7

No files matched your search

+5 -1
View File
@@ -12388,7 +12388,8 @@ def loadTokens(baseDir: str, tokensDict: {}, tokensLookup: {}) -> None:
tokensLookup[token] = nickname
def runDaemon(allowLocalNetworkAccess: bool,
def runDaemon(maxNewswirePosts: int,
allowLocalNetworkAccess: bool,
maxFeedItemSizeKb: int,
publishButtonAtTop: bool,
rssIconAtTop: bool,
@@ -12463,6 +12464,9 @@ def runDaemon(allowLocalNetworkAccess: bool,
# newswire storing rss feeds
httpd.newswire = {}
# maximum number of posts to appear in the newswire on the right column
httpd.maxNewswirePosts = maxNewswirePosts
# This counter is used to update the list of blocked domains in memory.
# It helps to avoid touching the disk and so improves flooding resistance
httpd.blocklistUpdateCtr = 0
+12 -1
View File
@@ -116,6 +116,10 @@ parser.add_argument('--postsPerSource',
dest='maxNewswirePostsPerSource', type=int,
default=4,
help='Maximum newswire posts per feed or account')
parser.add_argument('--maxNewswirePosts',
dest='maxNewswirePosts', type=int,
default=20,
help='Maximum newswire posts in the right column')
parser.add_argument('--maxFeedSize',
dest='maxNewswireFeedSizeKb', type=int,
default=10240,
@@ -2001,6 +2005,12 @@ maxNewswirePostsPerSource = \
if maxNewswirePostsPerSource:
args.maxNewswirePostsPerSource = int(maxNewswirePostsPerSource)
# set the maximum number of newswire posts appearing in the right column
maxNewswirePosts = \
getConfigParam(baseDir, 'maxNewswirePosts')
if maxNewswirePosts:
args.maxNewswirePosts = int(maxNewswirePosts)
# set the maximum size of a newswire rss/atom feed in Kilobytes
maxNewswireFeedSizeKb = \
getConfigParam(baseDir, 'maxNewswireFeedSizeKb')
@@ -2075,7 +2085,8 @@ if setTheme(baseDir, themeName, domain, args.allowLocalNetworkAccess):
print('Theme set to ' + themeName)
if __name__ == "__main__":
runDaemon(args.allowLocalNetworkAccess,
runDaemon(args.maxNewswirePosts,
args.allowLocalNetworkAccess,
args.maxFeedItemSizeKb,
args.publishButtonAtTop,
args.rssIconAtTop,
+2 -1
View File
@@ -718,7 +718,8 @@ def runNewswireDaemon(baseDir: str, httpd,
httpd.maxNewswirePostsPerSource,
httpd.maxNewswireFeedSizeKb,
httpd.maxTags,
httpd.maxFeedItemSizeKb)
httpd.maxFeedItemSizeKb,
httpd.maxNewswirePosts)
except Exception as e:
print('WARN: unable to update newswire ' + str(e))
time.sleep(120)
+9 -1
View File
@@ -677,7 +677,8 @@ def addBlogsToNewswire(baseDir: str, domain: str, newswire: {},
def getDictFromNewswire(session, baseDir: str, domain: str,
maxPostsPerSource: int, maxFeedSizeKb: int,
maxTags: int, maxFeedItemSizeKb: int) -> {}:
maxTags: int, maxFeedItemSizeKb: int,
maxNewswirePosts: int) -> {}:
"""Gets rss feeds as a dictionary from newswire file
"""
subscriptionsFilename = baseDir + '/accounts/newswire.txt'
@@ -728,4 +729,11 @@ def getDictFromNewswire(session, baseDir: str, domain: str,
# sort into chronological order, latest first
sortedResult = OrderedDict(sorted(result.items(), reverse=True))
# are there too many posts? If so then remove the oldest ones
noOfPosts = len(sortedResult.items())
if noOfPosts > maxNewswirePosts:
for n in range(noOfPosts - maxNewswirePosts):
sortedResult.pop()
return sortedResult
+6 -3
View File
@@ -292,8 +292,9 @@ def createServerAlice(path: str, domain: str, port: int,
onionDomain = None
i2pDomain = None
allowLocalNetworkAccess = True
maxNewswirePosts = 20
print('Server running: Alice')
runDaemon(allowLocalNetworkAccess,
runDaemon(maxNewswirePosts, allowLocalNetworkAccess,
2048, False, True, False, False, True, 10, False,
0, 100, 1024, 5, False,
0, False, 1, False, False, False,
@@ -359,8 +360,9 @@ def createServerBob(path: str, domain: str, port: int,
onionDomain = None
i2pDomain = None
allowLocalNetworkAccess = True
maxNewswirePosts = 20
print('Server running: Bob')
runDaemon(allowLocalNetworkAccess,
runDaemon(maxNewswirePosts, allowLocalNetworkAccess,
2048, False, True, False, False, True, 10, False,
0, 100, 1024, 5, False, 0,
False, 1, False, False, False,
@@ -400,8 +402,9 @@ def createServerEve(path: str, domain: str, port: int, federationList: [],
onionDomain = None
i2pDomain = None
allowLocalNetworkAccess = True
maxNewswirePosts = 20
print('Server running: Eve')
runDaemon(allowLocalNetworkAccess,
runDaemon(maxNewswirePosts, allowLocalNetworkAccess,
2048, False, True, False, False, True, 10, False,
0, 100, 1024, 5, False, 0,
False, 1, False, False, False,