-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathappbackup.py
56 lines (47 loc) · 1.49 KB
/
appbackup.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
from cgitb import html
from flask import Flask, jsonify, render_template
import sqlite3
import requests
from flask_sqlalchemy import SQLAlchemy
app = Flask(__name__)
db = SQLAlchemy(app)
# CREATE TABLE "precipitaciones" (
# "id" INTEGER NOT NULL,
# "fecha" TEXT NOT NULL,
# "mmh" REAL NOT NULL DEFAULT 0.0,
# PRIMARY KEY("id")
# );
def informacion_requerida():
# acá van las apis
url= 'https://hidroinformatica.itaipu.gov.py//services/precipitacionestacion/2016-11-01/2022-06-28/12/'
respuesta = requests.get(url)
respuesta_json = respuesta.json()
return respuesta_json
# acá se conecta con la ruta de la página.
@app.route('/inundaciones')
def inundaciones():
info = informacion_requerida()
print(type(info))
print(len(info))
print(info[0])
print(info[0]['fecha'])
print(info[0].get('fecha'))
###################################
con= sqlite3.connect('db.sqlite3')
repe =0
cur = con.cursor()
for medicion in info:
#print(medicion.get('fecha'), medicion.get('mmh'))
id = medicion.get('id')
fecha =medicion['fecha']
mmh = medicion['mmh']
#("id", "fecha", "mmh")
try:
cur.execute('INSERT INTO api_precipitaciones VALUES (?, ?, ?)', (int(id), fecha, mmh))
except Exception as e:
repe = repe+1
con.commit()
con.close()
##################################
canti = len(info)
return render_template ("inundaciones.html", cantidad=canti, repetidos = repe)