暂无描述

routes.py 1.8KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
  1. # -*- encoding: utf-8 -*-
  2. """
  3. License: MIT
  4. Copyright (c) 2019 - present AppSeed.us
  5. """
  6. from app.home import blueprint
  7. from flask import render_template, redirect, url_for
  8. from flask_login import login_required, current_user
  9. from app import login_manager
  10. from jinja2 import TemplateNotFound
  11. import json
  12. import requests
  13. import random
  14. import datetime
  15. aPythonVar = "doraemon"
  16. @blueprint.route('/index')
  17. # @login_required
  18. def index():
  19. #if not current_user.is_authenticated:
  20. # return redirect(url_for('base_blueprint.login'))
  21. fromDate = "2020-01-01"
  22. page = requests.get("https://earthquake.usgs.gov/fdsnws/event/1/query?format=geojson&starttime=%s&minlatitude=17&maxlatitude=19&minlongitude=-68&maxlongitude=-64" % (fromDate))
  23. x = []
  24. y = []
  25. print(page.content)
  26. parsed_json = (json.loads(page.content.decode("utf-8")))
  27. for f in parsed_json["features"]:
  28. p = f['properties']
  29. if p['mag'] >= 3.5:
  30. x.append(datetime.datetime.fromtimestamp(p['time']/1000.0 ))
  31. y.append(p['mag'])
  32. x.reverse()
  33. y.reverse()
  34. # x = x[:10]
  35. # y = y[:10]
  36. shortx = []
  37. for i in x:
  38. shortx.append(i.strftime("%m-%d %H:%M"))
  39. print(x)
  40. # return render_template('index.html', animal='perro',barData =json.dumps ({ 'x': [1,2,3,4,5,6,7,8], 'y': [23, 45, 55, 20, 10, 80, 100, 45]} ) )
  41. return render_template('index.html', animal='perro',barData =json.dumps ({ 'x': shortx, 'y': y} ) )
  42. @blueprint.route('/<template>')
  43. def route_template(template):
  44. if not current_user.is_authenticated:
  45. return redirect(url_for('base_blueprint.login'))
  46. try:
  47. return render_template(template + '.html')
  48. except TemplateNotFound:
  49. return render_template('page-404.html'), 404
  50. except:
  51. return render_template('page-500.html'), 500