Skip to content

Instantly share code, notes, and snippets.

@salrashid123
Created September 1, 2017 22:47
Show Gist options
  • Save salrashid123/aa3ccce2d97a58cc5bec066758358c09 to your computer and use it in GitHub Desktop.
Save salrashid123/aa3ccce2d97a58cc5bec066758358c09 to your computer and use it in GitHub Desktop.
#!/usr/bin/python
from flask import Flask
from flask import Response
import logging
import socket
import time
import requests
import os
from os import listdir
from os.path import isfile, join
app = Flask(__name__)
@app.route('/')
@app.route('/_ah/health')
def default():
return 'ok'
@app.route('/write')
def write_file():
r = ''
f_name = str(socket.gethostname()) + '-' + time.strftime('%d_%b_%Y_%H_%M_%S') + '.html'
mypath='/apps/data/'
file = open(mypath + f_name,'w')
file.write('Hello World')
file.close()
return Response('File ' + mypath+ f_name + ' written\n', mimetype='text/plain')
@app.route('/read')
def read_files():
r = ''
mypath='/apps/data'
onlyfiles = [f for f in listdir(mypath) if isfile(join(mypath, f))]
for a in onlyfiles:
r = r + '\n' + a
return Response(r, mimetype='text/plain')
if __name__ == '__main__':
app.run(host='0.0.0.0', port=8080, debug=True)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment