Skip to content
This repository was archived by the owner on Jul 19, 2019. It is now read-only.

Remove shadowing of file builtin in server.py. PEP8 formatting #133

Merged
merged 1 commit into from
May 10, 2016
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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)))