From d1295a94f02fcd29a2a0d6221683cc3f0d2f2778 Mon Sep 17 00:00:00 2001 From: Bob Mottram Date: Sun, 22 Nov 2020 12:05:15 +0000 Subject: [PATCH] Remove extra newswire items --- newswire.py | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/newswire.py b/newswire.py index c5241582..b9b476b8 100644 --- a/newswire.py +++ b/newswire.py @@ -733,7 +733,13 @@ def getDictFromNewswire(session, baseDir: str, domain: str, # 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() + ctr = 0 + removals = [] + for dateStr, item in sortedResult.items(): + ctr += 1 + if ctr >= maxNewswirePosts: + removals.append(dateStr) + for r in removals: + sortedResult.pop(r) return sortedResult