Advertisement
Guest User

Untitled

a guest
Jun 24th, 2019
100
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.76 KB | None | 0 0
  1. from flask import Flask
  2. from flask import request
  3. from flask import Response
  4.  
  5.  
  6. app = Flask(__name__)
  7.  
  8.  
  9. def tail(file, n=1, bs=1024):
  10. f = open(file)
  11. f.seek(0,2)
  12. l = 1-f.read(1).count('n')
  13. B = f.tell()
  14. while n >= l and B > 0:
  15. block = min(bs, B)
  16. B -= block
  17. f.seek(B, 0)
  18. l += f.read(block).count('n')
  19. f.seek(B, 0)
  20. l = min(l,n)
  21. lines = f.readlines()[-l:]
  22. f.close()
  23. return lines
  24.  
  25. @app.route('/logs', methods = ['GET'])
  26. def print_logs():
  27. if request.method == 'GET':
  28. file_path = "Logs.txt"
  29. data = tail(file_path, 100)
  30. return Response(data, mimetype='text/plain')
  31.  
  32.  
  33. if __name__ == "__main__":
  34. app.run(host="localhost", port=80, debug=True, threaded=True)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement