Skip to content

Commit 81bbc6f

Browse files
committed
Merge pull request reactjs#133 from akabraham/master
Remove shadowing of file builtin in server.py. PEP8 formatting
2 parents 2be1a2d + 82424fa commit 81bbc6f

File tree

1 file changed

+18
-10
lines changed

1 file changed

+18
-10
lines changed

server.py

+18-10
Original file line numberDiff line numberDiff line change
@@ -16,21 +16,29 @@
1616
app = Flask(__name__, static_url_path='', static_folder='public')
1717
app.add_url_rule('/', 'root', lambda: app.send_static_file('index.html'))
1818

19+
1920
@app.route('/api/comments', methods=['GET', 'POST'])
2021
def comments_handler():
21-
22-
with open('comments.json', 'r') as file:
23-
comments = json.loads(file.read())
22+
with open('comments.json', 'r') as f:
23+
comments = json.loads(f.read())
2424

2525
if request.method == 'POST':
26-
newComment = request.form.to_dict()
27-
newComment['id'] = int(time.time() * 1000)
28-
comments.append(newComment)
26+
new_comment = request.form.to_dict()
27+
new_comment['id'] = int(time.time() * 1000)
28+
comments.append(new_comment)
29+
30+
with open('comments.json', 'w') as f:
31+
f.write(json.dumps(comments, indent=4, separators=(',', ': ')))
2932

30-
with open('comments.json', 'w') as file:
31-
file.write(json.dumps(comments, indent=4, separators=(',', ': ')))
33+
return Response(
34+
json.dumps(comments),
35+
mimetype='application/json',
36+
headers={
37+
'Cache-Control': 'no-cache',
38+
'Access-Control-Allow-Origin': '*'
39+
}
40+
)
3241

33-
return Response(json.dumps(comments), mimetype='application/json', headers={'Cache-Control': 'no-cache', 'Access-Control-Allow-Origin': '*'})
3442

3543
if __name__ == '__main__':
36-
app.run(port=int(os.environ.get("PORT",3000)))
44+
app.run(port=int(os.environ.get("PORT", 3000)))

0 commit comments

Comments
 (0)