Commit b184f1ffddac82f9c31e5c92916b702d6d6080ad
PEP8 related fixes. Python follows indentation of mulitples of 4 not 2, so set your editors properly.
- fetch.py 124 ---------------------------------------------------------------+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
| | | | 11 | | 11 | |
---|
12 | app = Flask(__name__) | 12 | app = Flask(__name__) |
---|
13 | | 13 | |
---|
14 | @app.route('/',methods=['GET']) | | @app.route('/',methods=['GET']) |
---|
| | 14 | @app.route('/', methods=['GET']) | 15 | def index(): | 15 | def index(): |
---|
16 | if request.args.has_key('json'): | | if request.args.has_key('json'): |
---|
17 | return render_template('index.html',json=request.args['json']) | | return render_template('index.html',json=request.args['json']) |
---|
18 | else: | | else: |
---|
19 | return render_template('index.html') | | return render_template('index.html') |
---|
| | 16 | if request.args.has_key('json'): | | | 17 | return render_template('index.html', json=request.args['json']) |
---|
| | 18 | else: |
---|
| | 19 | return render_template('index.html') |
---|
20 | | 20 | |
---|
21 | #fil = FileHandler(os.path.join(os.path.dirname(__file__),'logme'),mode='a') | | #fil = FileHandler(os.path.join(os.path.dirname(__file__),'logme'),mode='a') |
---|
22 | | | |
---|
23 | @app.route('/editor', methods=['GET']) | 21 | @app.route('/editor', methods=['GET']) |
---|
24 | def editor(): | 22 | def editor(): |
---|
25 | if request.args.has_key('json'): | | if request.args.has_key('json'): |
---|
26 | filename = request.args['json'] | | filename = request.args['json'] |
---|
27 | else: | | else: |
---|
28 | filename = 'test.json' | | filename = 'test.json' |
---|
29 | filename = os.path.join(os.path.join(os.path.dirname(__file__),'static'), filename) | | filename = os.path.join(os.path.join(os.path.dirname(__file__),'static'), filename) |
---|
30 | try: | | try: |
---|
31 | f = open(filename, 'r') | | f = open(filename, 'r') |
---|
32 | except: | | except: |
---|
33 | f = open(os.path.join(os.path.join(os.path.dirname(__file__), 'static'), 'test.json'), 'r') | | f = open(os.path.join(os.path.join(os.path.dirname(__file__), 'static'), 'test.json'), 'r') |
---|
34 | buf = f.read() | | buf = f.read() |
---|
35 | f.close() | | f.close() |
---|
36 | return render_template('editor.html', json = buf) | | return render_template('editor.html', json = buf) |
---|
| | 23 | if request.args.has_key('json'): | | | 24 | filename = request.args['json'] |
---|
| | 25 | else: |
---|
| | 26 | filename = 'test.json' |
---|
| | 27 | filename = os.path.join(os.path.join(os.path.dirname(__file__), 'static'), filename) |
---|
| | 28 | try: |
---|
| | 29 | f = open(filename, 'r') |
---|
| | 30 | except: |
---|
| | 31 | f = open(os.path.join(os.path.join(os.path.dirname(__file__), 'static'), 'test.json'), 'r') |
---|
| | 32 | buf = f.read() |
---|
| | 33 | f.close() |
---|
| | 34 | return render_template('editor.html', json = buf) |
---|
37 | | 35 | |
---|
38 | @app.route('/saveJSON', methods=['POST']) | 36 | @app.route('/saveJSON', methods=['POST']) |
---|
39 | def saveJSON(): | 37 | def saveJSON(): |
---|
40 | if request.method == 'POST': | | if request.method == 'POST': |
---|
41 | response = make_response() | | response = make_response() |
---|
42 | JSON = request.form['json'] | | JSON = request.form['json'] |
---|
43 | filename = os.path.join('static', request.form['filename']) | | filename = os.path.join('static', request.form['filename']) |
---|
44 | ls = glob.glob(filename) | | ls = glob.glob(filename) |
---|
45 | if len(ls) > 0: | | if len(ls) > 0: |
---|
46 | response.status_code = 409 | | response.status_code = 409 |
---|
47 | response.status ="409 Conflict" | | response.status ="409 Conflict" |
---|
48 | response.data = "The file that you were trying to save already exits, please try a different name." | | response.data = "The file that you were trying to save already exits, please try a different name." |
---|
49 | return response | | return response |
---|
50 | f = open(filename, 'w') | | f = open(filename, 'w') |
---|
51 | f.write(JSON) | | f.write(JSON) |
---|
52 | f.close() | | f.close() |
---|
53 | return response | | return response |
---|
54 | else: | | else: |
---|
55 | response = make_response() | | response = make_response() |
---|
56 | response.code = 400 | | response.code = 400 |
---|
57 | return reponse | | return reponse |
---|
| | 38 | if request.method == 'POST': | | | 39 | response = make_response() |
---|
| | 40 | JSON = request.form['json'] |
---|
| | 41 | filename = os.path.join(os.path.join(os.path.dirname(__file__), 'static'), request.form['filename']) |
---|
| | 42 | ls = glob.glob(filename) |
---|
| | 43 | if len(ls) > 0: |
---|
| | 44 | response.status_code = 409 |
---|
| | 45 | response.status ="409 Conflict" |
---|
| | 46 | response.data = "The file that you were trying to save already exits, please try a different name." |
---|
| | 47 | return response |
---|
| | 48 | f = open(filename, 'w') |
---|
| | 49 | f.write(JSON) |
---|
| | 50 | f.close() |
---|
| | 51 | return response |
---|
| | 52 | else: |
---|
| | 53 | response = make_response() |
---|
| | 54 | response.code = 400 |
---|
| | 55 | return reponse |
---|
58 | | 56 | |
---|
59 | @app.route('/history', methods=['GET']) | 57 | @app.route('/history', methods=['GET']) |
---|
60 | def listJSON(): | 58 | def listJSON(): |
---|
61 | path = os.path.join('static', '*.json') | | path = os.path.join('static', '*.json') |
---|
62 | ls = glob.glob(path) | | ls = glob.glob(path) |
---|
63 | def sanitize(i): | | def sanitize(i): |
---|
64 | return i.split('/')[-1] | | return i.split('/')[-1] |
---|
65 | ls = map(sanitize, ls) | | ls = map(sanitize, ls) |
---|
66 | return render_template('history.html', ls=ls) | | return render_template('history.html', ls=ls) |
---|
| | 59 | path = os.path.join(os.path.join(os.path.dirname(__file__), 'static'), '*.json') | | | 60 | ls = glob.glob(path) |
---|
| | 61 | def sanitize(i): |
---|
| | 62 | return i.split('/')[-1] |
---|
| | 63 | ls = map(sanitize, ls) |
---|
| | 64 | return render_template('history.html', ls=ls) |
---|
67 | | 65 | |
---|
68 | #Log the errors, don't depend on apache to log it for you. | 66 | #Log the errors, don't depend on apache to log it for you. |
---|
69 | fil = FileHandler(os.path.join(os.path.dirname(__file__),'logme'),mode='a') | | fil = FileHandler(os.path.join(os.path.dirname(__file__),'logme'),mode='a') |
---|
70 | fil.setLevel(logging.ERROR) | | fil.setLevel(logging.ERROR) |
---|
71 | app.logger.addHandler(fil) | | app.logger.addHandler(fil) |
---|
| | 67 | fil = FileHandler(os.path.join(os.path.dirname(__file__), 'logme'),mode='a') | | | 68 | fil.setLevel(logging.ERROR) |
---|
| | 69 | app.logger.addHandler(fil) |
---|
72 | | 70 | |
---|
73 | | 71 | |
---|
74 | if __name__ == "__main__": | 72 | if __name__ == "__main__": |
---|
75 | app.run(debug=True, host='0.0.0.0') | | app.run(debug=True, host='0.0.0.0') |
---|
| | 73 | app.run(debug=True, host='0.0.0.0') | 76 | | 74 | |
---|
77 | # #from bson.code import * | 75 | # #from bson.code import * |
---|
78 | # #from urllib import unquote_plus | | # #from urllib import unquote_plus |
---|
79 | # def application(environ, start_response): | | # def application(environ, start_response): |
---|
80 | # status = '200 OK' | | # status = '200 OK' |
---|
81 | # response_headers = [('Content-type', 'application/json'),('Access-Control-Allow-Origin', '*')] | | # response_headers = [('Content-type', 'application/json'),('Access-Control-Allow-Origin', '*')] |
---|
82 | # start_response(status, response_headers) | | # start_response(status, response_headers) |
---|
83 | # c = pymongo.Connection() | | # c = pymongo.Connection() |
---|
84 | # db = c['mural'] | | # db = c['mural'] |
---|
85 | # coll = db['data'] | | # coll = db['data'] |
---|
86 | # ret = {} | | # ret = {} |
---|
87 | # x = 0 | | # x = 0 |
---|
88 | # for i in coll.find(): | | # for i in coll.find(): |
---|
89 | # del(i['_id']) | | # del(i['_id']) |
---|
90 | # ret[x] = i | | # ret[x] = i |
---|
91 | # x = x + 1 | | # x = x + 1 |
---|
92 | # #return repr(recieved) | | # #return repr(recieved) |
---|
93 | # return json.dumps(ret) | | # return json.dumps(ret) |
---|
| | 76 | # #from urllib import unquote_plus | | | 77 | # def application(environ, start_response): |
---|
| | 78 | # status = '200 OK' |
---|
| | 79 | # response_headers = [('Content-type', 'application/json'),('Access-Control-Allow-Origin', '*')] |
---|
| | 80 | # start_response(status, response_headers) |
---|
| | 81 | # c = pymongo.Connection() |
---|
| | 82 | # db = c['mural'] |
---|
| | 83 | # coll = db['data'] |
---|
| | 84 | # ret = {} |
---|
| | 85 | # x = 0 |
---|
| | 86 | # for i in coll.find(): |
---|
| | 87 | # del(i['_id']) |
---|
| | 88 | # ret[x] = i |
---|
| | 89 | # x = x + 1 |
---|
| | 90 | # #return repr(recieved) |
---|
| | 91 | # return json.dumps(ret) |
---|