Skip to content

Commit

Permalink
Remove shadowing of file builtin in server.py. PEP8 formatting
Browse files Browse the repository at this point in the history
  • Loading branch information
akabraham committed May 10, 2016
1 parent 2be1a2d commit 82424fa
Showing 1 changed file with 18 additions and 10 deletions.
28 changes: 18 additions & 10 deletions server.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,21 +16,29 @@
app = Flask(__name__, static_url_path='', static_folder='public')
app.add_url_rule('/', 'root', lambda: app.send_static_file('index.html'))


@app.route('/api/comments', methods=['GET', 'POST'])
def comments_handler():

with open('comments.json', 'r') as file:
comments = json.loads(file.read())
with open('comments.json', 'r') as f:
comments = json.loads(f.read())

if request.method == 'POST':
newComment = request.form.to_dict()
newComment['id'] = int(time.time() * 1000)
comments.append(newComment)
new_comment = request.form.to_dict()
new_comment['id'] = int(time.time() * 1000)
comments.append(new_comment)

with open('comments.json', 'w') as f:
f.write(json.dumps(comments, indent=4, separators=(',', ': ')))

with open('comments.json', 'w') as file:
file.write(json.dumps(comments, indent=4, separators=(',', ': ')))
return Response(
json.dumps(comments),
mimetype='application/json',
headers={
'Cache-Control': 'no-cache',
'Access-Control-Allow-Origin': '*'
}
)

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

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

0 comments on commit 82424fa

Please sign in to comment.