main
Bob Mottram 2020-06-29 20:35:14 +01:00
parent 9d5e5d0810
commit 63f1654ba4
1 changed files with 9 additions and 1 deletions

View File

@ -91,10 +91,14 @@ def getPetNameHandle(baseDir: str, nickname: str, domain: str,
with open(petnamesFilename, 'r') as petnamesFile:
petnamesStr = petnamesFile.read()
if petname + ' ' in petnamesStr:
print('resolvePetnames: petname exists')
petnamesList = petnamesStr.split('\n')
for pet in petnamesList:
if pet.startswith(petname + ' '):
return pet.replace(petname + ' ', '').strip()
handle = pet.replace(petname + ' ', '').strip()
print('resolvePetnames: handle found ' + handle)
return handle
print('resolvePetnames: no petname found for ' + petname)
return ''
@ -106,15 +110,19 @@ def resolvePetnames(baseDir: str, nickname: str, domain: str,
return content
if ' ' not in content:
return content
print('resolvePetnames: ' + content)
words = content.strip().split(' ')
for wrd in words:
# check initial words beginning with @
if not wrd.startswith('@'):
break
print('resolvePetnames: ' + wrd)
# does a petname handle exist for this?
handle = getPetNameHandle(baseDir, nickname, domain, wrd)
if not handle:
print('resolvePetnames: not a petname - ' + wrd)
continue
# replace the petname with the handle
content = content.replace(wrd + ' ', handle + ' ')
print('resolvePetnames: ' + content)
return content