app.py 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  1. # -*- coding: utf-8 -*-
  2. import gzip
  3. from flask import Flask, render_template, json, request
  4. from flask_cors import CORS
  5. from library.functions import pathDB, Settings, work_with_backup, get_fun
  6. from multiprocessing import process
  7. import os
  8. import re
  9. import time
  10. app = Flask(__name__, template_folder='templates')
  11. CORS(app, resources={r"/*": {"origins": "*"}})
  12. pdb = pathDB(r"D:\backup")
  13. @app.route("/getTables/<string:name_backup>/<string:item>/")
  14. def getTables(name_backup, item):
  15. print(name_backup, item)
  16. tablr = []
  17. selected_backup = pdb.path + "\\" + name_backup
  18. if item == 'tables':
  19. pattern = r"-- Table structure for table\ \`([\w\d_-]*)\`"
  20. elif item == 'views':
  21. pattern = r"-- Temporary table structure for view\ \`([\w\d_-]*)\`"
  22. else:
  23. return app.response_class(
  24. response=json.dumps({'text': "Не правильнный параметр"}),
  25. status=200,
  26. mimetype='application/json'
  27. )
  28. with gzip.open(selected_backup, 'rt', encoding='utf-8', errors='ignore') as f:
  29. for line in f:
  30. if len(re.findall(pattern, line)) != 0:
  31. tablr.append(re.findall(pattern, line)[0])
  32. if len(tablr) == 0:
  33. return app.response_class(
  34. response=json.dumps({'text': "Пусто"}),
  35. status=200,
  36. mimetype='application/json'
  37. )
  38. else:
  39. return app.response_class(
  40. response=json.dumps(tablr),
  41. status=200,
  42. mimetype='application/json'
  43. )
  44. @app.route("/get_date_exists_backup")
  45. def get_data_exists_backup():
  46. response = app.response_class(
  47. response=json.dumps(pdb.get_json_by_date()),
  48. status=200,
  49. mimetype='application/json'
  50. )
  51. return response
  52. # main
  53. if __name__ == "__main__":
  54. # f = pathDB(r"D:\backup")
  55. # print(f.getFileInDirectory())
  56. app.run(debug=True)