2023-10-27 14:18:51 +02:00
|
|
|
#!/usr/bin/env python3
|
|
|
|
|
2024-03-14 10:15:53 +01:00
|
|
|
from . import parse_numberdealers
|
2023-10-27 14:18:51 +02:00
|
|
|
|
2023-11-08 20:48:58 +01:00
|
|
|
|
2024-03-11 14:47:46 +01:00
|
|
|
def link(link_text: str, message_obj: parse_numberdealers.Message):
|
|
|
|
return f"[{link_text}]({parse_numberdealers.URL_PREFIX}{message_obj.id})"
|
2023-11-08 20:48:58 +01:00
|
|
|
|
2024-03-11 14:47:46 +01:00
|
|
|
def mention(message: parse_numberdealers.Message):
|
|
|
|
if message.username is not None:
|
|
|
|
return f" (@{message.username})"
|
2023-10-27 14:18:51 +02:00
|
|
|
else:
|
2024-03-11 14:47:46 +01:00
|
|
|
return ""
|
|
|
|
|
|
|
|
def str_from_error(err):
|
|
|
|
if isinstance(err, parse_numberdealers.UnrecognizedNumber):
|
2024-05-20 20:33:24 +02:00
|
|
|
msg = f"🚨 Unrecognized post {link(err.message.message, err.message)}"
|
2024-03-11 14:47:46 +01:00
|
|
|
elif isinstance(err, parse_numberdealers.EditedMessage):
|
2024-05-20 20:33:24 +02:00
|
|
|
msg = f"🚨 Edited post {link(err.message.message, err.message)}"
|
2024-03-11 14:47:46 +01:00
|
|
|
elif isinstance(err, parse_numberdealers.NonNumberMessage):
|
2024-05-20 20:33:24 +02:00
|
|
|
msg = f"🚨 Non-number message {link(err.message.message, err.message)}"
|
2024-03-11 14:47:46 +01:00
|
|
|
elif isinstance(err, parse_numberdealers.ShouldHaveBeen):
|
2024-05-20 20:33:24 +02:00
|
|
|
msg = f"🚨 {link(err.message.recognized_number, err.message)} should have been {err.expected_number}"
|
2024-03-11 14:47:46 +01:00
|
|
|
elif isinstance(err, parse_numberdealers.Duplicate):
|
2024-05-20 20:33:24 +02:00
|
|
|
msg = f"🚨 Duplicate {link(err.message.recognized_number, err.message)}"
|
2024-03-11 14:47:46 +01:00
|
|
|
elif isinstance(err, parse_numberdealers.Stray):
|
2024-05-20 20:33:24 +02:00
|
|
|
msg = f"🚨 Stray {link(err.message.recognized_number, err.message)}"
|
2024-03-11 14:47:46 +01:00
|
|
|
elif isinstance(err, parse_numberdealers.Skipped):
|
2024-05-20 20:33:24 +02:00
|
|
|
msg = f"🚨 {link('Skipped', err.message)} {err.expected_number}"
|
2024-03-11 14:47:46 +01:00
|
|
|
elif isinstance(err, parse_numberdealers.Jump):
|
2024-05-20 20:33:24 +02:00
|
|
|
msg = f"🚨 Going from {link(err.previous_message.recognized_number, err.previous_message)}" \
|
2024-03-11 14:47:46 +01:00
|
|
|
f" to {link(err.message.recognized_number, err.message)}"
|
|
|
|
|
|
|
|
return msg + mention(err.message)
|
|
|
|
|
2024-03-14 10:15:53 +01:00
|
|
|
|
|
|
|
def report_errors(errors):
|
|
|
|
if errors:
|
2024-05-20 20:33:24 +02:00
|
|
|
return list(map(str_from_error, errors))
|
2024-03-14 10:15:53 +01:00
|
|
|
else:
|
2024-05-20 20:33:24 +02:00
|
|
|
return []
|
2024-03-14 10:15:53 +01:00
|
|
|
|
|
|
|
|
2024-03-11 14:47:46 +01:00
|
|
|
def main():
|
|
|
|
import sys
|
2024-05-20 20:33:24 +02:00
|
|
|
|
|
|
|
error_style = {
|
|
|
|
"--numberdealers": parse_numberdealers.ErrorStyle.NUMBERDEALERS,
|
|
|
|
"--numberdealers-ng": parse_numberdealers.ErrorStyle.NUMBERDEALERS_NG
|
|
|
|
}[sys.argv[1]]
|
|
|
|
|
|
|
|
numbers, errors = parse_numberdealers.parse(sys.stdin, error_style)
|
2024-03-14 10:15:53 +01:00
|
|
|
|
2024-03-11 14:47:46 +01:00
|
|
|
if numbers == [] and errors == []:
|
|
|
|
print("No input data")
|
2023-10-27 14:18:51 +02:00
|
|
|
else:
|
2024-03-11 14:47:46 +01:00
|
|
|
if numbers == []:
|
|
|
|
print("No valid number messages!")
|
|
|
|
else:
|
|
|
|
print(f"Checked from {numbers[0].recognized_number} up to {numbers[-1].recognized_number}")
|
2024-05-20 20:33:24 +02:00
|
|
|
if not errors:
|
|
|
|
print("No errors! 🎉")
|
|
|
|
else:
|
|
|
|
print("\n".join(report_errors(errors)))
|
2024-03-11 14:47:46 +01:00
|
|
|
|
|
|
|
|
|
|
|
if __name__ == "__main__":
|
|
|
|
main()
|