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