conversione interi testi #1
2 changed files with 43 additions and 0 deletions
20
text2banana.py
Executable file
20
text2banana.py
Executable file
|
@ -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)
|
23
text2dec.py
Executable file
23
text2dec.py
Executable file
|
@ -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)
|
Loading…
Reference in a new issue