unibrementypo3auto/bib/shorten_authorname.py

19 lines
532 B
Python
Raw Permalink Normal View History

2023-05-15 20:08:48 +02:00
import html
def filter_string(input):
return str(html.escape(input).encode("ascii", "xmlcharrefreplace").decode())
2023-05-15 19:20:33 +02:00
def shorten_authorname(input: str) -> str:
2023-05-15 20:08:48 +02:00
input = filter_string(input)
2023-05-15 19:20:33 +02:00
temp = input.split(",")
name: str = temp[0].lstrip().rstrip() + str(",")
temp = temp[1].lstrip().rstrip().split(" ")
for i in temp:
if len(i) > 0:
first_letter = i.upper()[0]
if first_letter.isalpha() is True:
name += str(" ") + first_letter + str(".")
return name