-
Notifications
You must be signed in to change notification settings - Fork 0
/
baudelaire-whitespace.py
31 lines (25 loc) · 1.04 KB
/
baudelaire-whitespace.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
import subprocess
def lambda_handler(event, context):
"""
Run the Whitespace program baudelaire.ws with the provided input and return
a response containing the resulting output, in a format suitable for
API Gateway integration.
Input is taken from the query string parameter "input". It must be
a sequence of ASCII characters terminated with a newline.
The EsCo (Esoteric Combine) interpreter is used to run the program.
"""
input = event["queryStringParameters"]["input"]
completed_interpretation = subprocess.run(
["./esco", "--quiet", "--type", "ws", "baudelaire.ws"],
text=True,
encoding="ascii",
input=input,
stdout=subprocess.PIPE)
# Discard the first two lines of the output (they contain the message
# "Enter a word and press Enter:" and then an empty line).
trimmed_output = completed_interpretation.stdout.split("\n", 2)[2]
return {
"statusCode": 200,
"headers": {"Access-Control-Allow-Origin": "*"},
"body": trimmed_output,
}