From 00ba237ab98866ab0ed095fea34ba1fb45348d81 Mon Sep 17 00:00:00 2001 From: Bob Mottram Date: Sat, 2 Nov 2019 10:24:25 +0000 Subject: [PATCH] Function for valid item ID --- shares.py | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/shares.py b/shares.py index 9cbeadcd7..587965a60 100644 --- a/shares.py +++ b/shares.py @@ -22,6 +22,12 @@ from utils import loadJson from utils import saveJson from media import removeMetaData +def getValidItemID(displayName: str) -> str: + """Removes any invalid characters from the display name to + produce an item ID + """ + return displayName.replace(' ','').replace('/','-').replace('\\','-').replace('.','_').replace('?','-').replace('\n','').replace("’","'") + def removeShare(baseDir: str,nickname: str,domain: str, \ displayName: str) -> None: """Removes a share for a person @@ -30,7 +36,7 @@ def removeShare(baseDir: str,nickname: str,domain: str, \ if os.path.isfile(sharesFilename): sharesJson=loadJson(sharesFilename) - itemID=displayName.replace(' ','') + itemID=getValidItemID(displayName) if sharesJson.get(itemID): # remove any image for the item itemIDfile=baseDir+'/sharefiles/'+itemID @@ -79,7 +85,7 @@ def addShare(baseDir: str, \ if 'year' in durationList[1]: durationSec=published+(int(durationList[0])*60*60*24*365) - itemID=displayName.replace(' ','').replace('/','-').replace('\\','-').replace('.','_').replace('?','-').replace('\n','').replace("’","'") + itemID=getValidItemID(displayName) # has an image for this share been uploaded? imageUrl=None