-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathpywtf.py
50 lines (40 loc) · 1.69 KB
/
pywtf.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
import sys
import csv
import argparse
def load_csv(filename):
with open(f'data/{filename}.csv', 'r') as file:
return {row[0]: row[1] for row in csv.reader(file) if len(row) == 2}
def map_characters(input_str, mappings):
return '+'.join(mappings.get(str(ord(char)), f'<COULDNT FIND {ord(char)}>') for char in input_str)
def main():
parser = argparse.ArgumentParser(description='Translate input using character mappings.')
parser.add_argument('input', help='Input string or file path')
parser.add_argument('-f', '--file', action='store_true', help='Treat input as a file path')
parser.add_argument('-p', '--period', action='store_true', help='Use period mappings')
parser.add_argument('-a', '--astrix', action='store_true', help='Use astrix mappings')
parser.add_argument('-n', '--newer-python', action='store_true', help='Use newer Python mappings')
parser.add_argument('-e', '--eval', action='store_true', help='Wrap output in exec()')
args = parser.parse_args()
# Load mappings
original_mappings = load_csv('originalMappings')
mappings = original_mappings.copy()
if args.period:
mappings.update(load_csv('periodMappings'))
if args.astrix:
mappings.update(load_csv('astrixMappings'))
if args.newer_python:
mappings.update(load_csv('newerPythonMappings'))
# Get input
if args.file:
with open(args.input, 'r') as file:
input_text = file.read()
else:
input_text = args.input
# Process input
output = map_characters(input_text, mappings)
# Apply eval if requested
if args.eval:
output = f'exec({output})'
print(output)
if __name__ == '__main__':
main()