Guest User

Untitled

a guest
Mar 8th, 2020
123
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.53 KB | None | 0 0
  1. from flask import Flask, jsonify
  2.  
  3. app = Flask(__name__)
  4.  
  5. @app.route('/log/<int:id>')
  6. def find_log_record(id):
  7.     with open('log.txt', 'r') as f:
  8.         for line in f:
  9.             rec_id, time, event_type = line.strip('\n').split(' ')
  10.             rec_id = int(rec_id)
  11.  
  12.             if rec_id == id:
  13.                 return jsonify(
  14.                     id = rec_id,
  15.                     time = time,
  16.                     event_type = event_type
  17.                 )
  18.  
  19.     return 'No such record'
  20.  
  21. app.run(host='localhost', port=1010)
Advertisement
Add Comment
Please, Sign In to add comment