Function for valid item ID

main2
Bob Mottram 2019-11-02 10:24:25 +00:00
parent 544c8745ad
commit 00ba237ab9
1 changed files with 8 additions and 2 deletions

View File

@ -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