2021-02-24 00:53:05 +01:00
|
|
|
import re
|
|
|
|
|
|
|
|
|
|
|
|
def data_parser(data: str) -> dict:
|
|
|
|
output = {
|
2021-03-31 18:08:41 +02:00
|
|
|
"message": "",
|
|
|
|
"compressed": False,
|
|
|
|
"graphical": False,
|
|
|
|
"chars": tuple(),
|
2021-02-24 00:53:05 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
if not data:
|
|
|
|
return output
|
|
|
|
|
|
|
|
if "--compressed" in data:
|
|
|
|
output["compressed"] = True
|
|
|
|
data = "".join(data.rsplit("--compressed", 1))
|
|
|
|
|
|
|
|
if "--graphical" in data:
|
|
|
|
output["graphical"] = True
|
|
|
|
data = "".join(data.rsplit("--graphical", 1))
|
|
|
|
|
|
|
|
if "compressed" in output.keys():
|
|
|
|
del output["compressed"]
|
|
|
|
|
|
|
|
if "--chars" in data:
|
|
|
|
regex = r"--chars=(\S\S)"
|
|
|
|
|
2021-03-31 18:08:41 +02:00
|
|
|
if match := re.search(regex, data):
|
|
|
|
output["chars"] = tuple(match.group()[-2:])
|
|
|
|
data = "".join(data.rsplit(match.group(), 1))
|
2021-02-24 00:53:05 +01:00
|
|
|
|
|
|
|
output["message"] = data.strip()
|
|
|
|
|
|
|
|
return output
|