models: be even more defensive when parsing input
also we finally read the documentation for str.find() https://docs.python.org/3/library/stdtypes.html#str.find
This commit is contained in:
parent
0ae116afa9
commit
49a21ca9cf
1 changed files with 9 additions and 1 deletions
|
|
@ -37,12 +37,20 @@ async def make_teilchen_input(text: str) -> TeilchenCreate | None:
|
||||||
import re
|
import re
|
||||||
from natsort import natsorted
|
from natsort import natsorted
|
||||||
|
|
||||||
|
text = text.strip()
|
||||||
|
|
||||||
if not text:
|
if not text:
|
||||||
logger.error("Empty text.")
|
logger.error("Empty text.")
|
||||||
return None
|
return None
|
||||||
|
|
||||||
name_end = text.find(".")
|
name_end = text.find(".")
|
||||||
|
if name_end == -1: # "." not in text
|
||||||
|
logger.warning("Missing period '.' from text.")
|
||||||
|
logger.debug("Could not find period symbol in input: %s", text)
|
||||||
|
return None
|
||||||
|
else:
|
||||||
name = text[0:name_end]
|
name = text[0:name_end]
|
||||||
|
|
||||||
if not name:
|
if not name:
|
||||||
logger.error("Could not extract name.")
|
logger.error("Could not extract name.")
|
||||||
logger.debug("Could not extract name from input: %s", text)
|
logger.debug("Could not extract name from input: %s", text)
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue