From 0e5753147e65a8574586cc10ae5b151f981301f4 Mon Sep 17 00:00:00 2001 From: Bob Mottram Date: Sun, 25 Jul 2021 10:56:57 +0100 Subject: [PATCH] Option to show shared for today --- shares.py | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) diff --git a/shares.py b/shares.py index e99017b3d..fa965877f 100644 --- a/shares.py +++ b/shares.py @@ -725,7 +725,7 @@ def outboxUndoShareUpload(baseDir: str, httpPrefix: str, def sharesCatalogAccountEndpoint(baseDir: str, httpPrefix: str, nickname: str, domain: str, domainFull: str, - path: str) -> {}: + path: str, today: bool) -> {}: """Returns the endpoint for the shares catalog of a particular account See https://github.com/datafoodconsortium/ontology """ @@ -746,6 +746,9 @@ def sharesCatalogAccountEndpoint(baseDir: str, httpPrefix: str, "DFC:supplies": [] } + currDate = datetime.datetime.utcnow() + currDateStr = currDate.strftime("%Y-%m-%d") + sharesFilename = acctDir(baseDir, nickname, domain) + '/shares.json' if not os.path.isfile(sharesFilename): return endpoint @@ -758,6 +761,9 @@ def sharesCatalogAccountEndpoint(baseDir: str, httpPrefix: str, continue if '#' not in item['dfcId']: continue + if today: + if not item['published'].startswith(currDateStr): + continue expireDate = datetime.datetime.fromtimestamp(item['durationSec']) expireDateStr = expireDate.strftime("%Y-%m-%dT%H:%M:%SZ") @@ -783,7 +789,7 @@ def sharesCatalogAccountEndpoint(baseDir: str, httpPrefix: str, def sharesCatalogEndpoint(baseDir: str, httpPrefix: str, domainFull: str, - path: str) -> {}: + path: str, today: bool) -> {}: """Returns the endpoint for the shares catalog for the instance See https://github.com/datafoodconsortium/ontology """ @@ -803,6 +809,9 @@ def sharesCatalogEndpoint(baseDir: str, httpPrefix: str, "DFC:supplies": [] } + currDate = datetime.datetime.utcnow() + currDateStr = currDate.strftime("%Y-%m-%d") + for subdir, dirs, files in os.walk(baseDir + '/accounts'): for acct in dirs: if not isAccountDir(acct): @@ -824,6 +833,9 @@ def sharesCatalogEndpoint(baseDir: str, httpPrefix: str, continue if '#' not in item['dfcId']: continue + if today: + if not item['published'].startswith(currDateStr): + continue expireDate = \ datetime.datetime.fromtimestamp(item['durationSec'])