Skip to content

Instantly share code, notes, and snippets.

@brianherman
Created July 17, 2013 01:53
Show Gist options
  • Save brianherman/6017054 to your computer and use it in GitHub Desktop.
Save brianherman/6017054 to your computer and use it in GitHub Desktop.
from flask import Flask
import cStringIO
app = Flask(__name__)
import string
@app.route('/k/', methods=['POST'])
def work_with_data():
print request.form # here's post data in a dict - do what you will...
f = open(name, 'w')
output = cStringIO.StringIO()
output.write('First line.\n')
output.write(f.getvalue());
import subprocess
process = subprocess.Popen(["emcc", name], stdout=subprocess.PIPE)
result = process.communicate()[0]
return result
@app.route('/run/', methods=['GET'])
def run_with_data():
print request.form # here's post data in a dict - do what you will...
f = open('workfile', 'r')
output = cStringIO.StringIO()
output.write('<html>\n<script>')
output.write(f.getvalue());
# Retrieve file contents -- this will be
# 'First line.\nSecond line.\n'
contents = output.getvalue()
# Close object and discard memory buffer --
# .getvalue() will now raise an exception.
output.write("</script></html>")
output.close()
return contents
if __name__ == '__main__':
app.run()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment