From 50c01a071499a5228ff956b99503e7b4381489ad Mon Sep 17 00:00:00 2001 From: boyska Date: Thu, 24 Sep 2020 01:29:17 +0200 Subject: [PATCH] conversione interi testi --- text2banana.py | 20 ++++++++++++++++++++ text2dec.py | 23 +++++++++++++++++++++++ 2 files changed, 43 insertions(+) create mode 100755 text2banana.py create mode 100755 text2dec.py diff --git a/text2banana.py b/text2banana.py new file mode 100755 index 0000000..3fc3fe2 --- /dev/null +++ b/text2banana.py @@ -0,0 +1,20 @@ +#!/usr/bin/env python3 +import argparse +import re +import sys + +import banana + + +def callback(x): + return " %s " % banana.dec2banana(int(x[0], base=10)).upper() + + +if __name__ == "__main__": + parser = argparse.ArgumentParser( + description="Convert a text from dec to uppercase banana" + ) + args = parser.parse_args() + text = sys.stdin.read() + text = re.sub(r"[0-9][0-9]*", callback, text) + sys.stdout.write(text) diff --git a/text2dec.py b/text2dec.py new file mode 100755 index 0000000..821b144 --- /dev/null +++ b/text2dec.py @@ -0,0 +1,23 @@ +#!/usr/bin/env python3 +import argparse +import re +import sys + +import banana + + +def callback(x): + b = x[0].strip().lower() + if banana.isbanana(b): + return "%s" % banana.banana2dec(b) + else: + return x[0] + + +if __name__ == "__main__": + parser = argparse.ArgumentParser(description="Convert a text from banana to dec") + args = parser.parse_args() + + text = sys.stdin.read() + text = re.sub(r"[A-Z][A-Z]*", callback, text) + sys.stdout.write(text) -- 2.39.5