-
Notifications
You must be signed in to change notification settings - Fork 0
/
ubica_brython.html
195 lines (167 loc) · 7.41 KB
/
ubica_brython.html
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
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
<meta name="description" content="">
<meta name="author" content="">
<title>Ubica - Busqueda de establecimientos</title>
<!-- Bootstrap core CSS -->
<link href="vendor/bootstrap/css/bootstrap.min.css" rel="stylesheet">
<meta name="viewport" content="width=device-width, initial-scale=1">
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/4.7.0/css/font-awesome.min.css">
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.4.1/css/bootstrap.min.css">
<!-- Favicons -->
<link href="assets/img/favicon.png" rel="icon">
<link href="aseets/img/apple-touch-icon.png" rel="apple-touch-icon">
<style>
.tarjeta {
margin: 3rem 12rem;
border: #ccc 1px solid;
padding: 20px;
font-family: 'IBM Plex Sans', serif;
}
img {
display: block;
margin-left: auto;
margin-right: auto;
}
</style>
<!-- Bootstrap core JavaScript -->
<script src="vendor/jquery/jquery.slim.min.js"></script>
<script src="vendor/bootstrap/js/bootstrap.bundle.min.js"></script>
<!-- Brython files -->
<script src="brython.js"></script>
<script src="brython_stdlib.js"></script>
</head>
<body onload="brython()">
<!-- Load a simple script to see if brython is enabled-->
<script type="text/python">
from browser import *
alert("Brython is ready!")
</script>
<!-- Navegación de la página -->
<nav class="navbar navbar-expand-lg navbar-dark bg-dark static-top">
<div class="container">
<a class="navbar-brand" href="index.html">Ubica</a>
<button class="navbar-toggler" type="button" data-toggle="collapse" data-target="#navbarResponsive" aria-controls="navbarResponsive" aria-expanded="false" aria-label="Toggle navigation">
<span class="navbar-toggler-icon"></span>
</button>
<div class="collapse navbar-collapse" id="navbarResponsive">
<ul class="navbar-nav ml-auto">
<li class="nav-item active">
<a class="nav-link" href="index.html">Ir a Inicio
<span class="sr-only">(current)</span>
</a>
</li>
<li class="nav-item">
<a class="nav-link" href="ubica_ejercicio.html">Versión JS
</a>
</li>
</ul>
</div>
</div>
</nav>
<!-- Contenido de la página -->
<div class="container">
<div class="row">
<div class="col-lg-12 text-center">
<h1 class="mt-5">Busqueda de establecimientos en México usando datos del INEGI</h1>
<h2 class="mt-10">Powered by:</h2>
</div>
</div>
</div>
<img src="assets/img/brython.png" alt="Brython" style="width:10%;">
<br><br>
<div class="container">
<div class="row">
<div class="col-lg-12 text-center">
<i class="fa fa-thumb-tack" aria-hidden="true"></i> <label for="condi">Condición: </label><input class="ingreso" type="text" id="condi" aria-label="Condición"
value="restaurantes" tabindex="515" />
<br><br>
<i class="fa fa-compass"></i> <label for="lat">Latitud: </label><input class="ingreso" type="text" id="lat" aria-label="Latitud"
value="21.85717833" tabindex="516" />
<i class="fa fa-compass"></i> <label for="lon">Longitud: </label><input class="ingreso" type="text" id="lon" aria-label="Longitud"
value="-102.28487238" tabindex="517" />
<br><br>
<i class="fa fa-arrows"></i> <label for="mts">Metros: </label><input class="ingreso" type="text" id="mts" aria-label="Metros"
value="200" tabindex="518" />
<br><br>
<input type="button" class="btn btn-success"
id="boton-ajax" onclick="saveValues();" value="Obtener datos del INEGI">
<button type="button" id="reload_page" class="btn btn-warning">Volver a buscar!</button>
<button type="button" onclick="loadValues();" class="btn btn-info">
<i class="fa fa-history" aria-hidden="true"></i>
Historial de busqueda</button>
</div>
</div>
</div>
<div id="caja" class="tarjeta" style="text-align: center;">
<p>Busca un establecimiento en México con datos del INEGI</p>
</div>
<!-- ====== Reload page ====== -->
<script type="text/javascript">
$(document).ready(function() {
// RELOAD PAGE ON BUTTON CLICK EVENT.
$('#reload_page').click(function () {
location.reload(true);
});
});
</script>
<!-- ==== LocalStorage ==== -->
<script type="text/javascript">
function saveValues(){
localStorage._condicion = document.getElementById("condi").value;
/*Limpiando los campos o inputs*/
document.getElementById("condi").value = "";
}
function loadValues(){
var Text;
Text = document.getElementById("condi").value = localStorage._condicion
alert("Tu historial es: " + Text);
}
</script>
<!-- Brython implementation -->
<script type="text/python">
#---------------------------------------|
# Desarrollado por: Sebastián Marroquín |
#---------------------------------------|
from browser import document, ajax, html
token = "adf48de4-366a-40e4-a483-9cf62bf1a3c1"
def al_completar(req):
import json
datos = json.loads(req.responseText)
document['caja'].clear()
ordenar(datos)
def solicitar_api(e):
obtenerDatos_Campos()
url = f"https://www.inegi.org.mx/app/api/denue/v1/consulta/buscar/{condicion}/{latitud},{longitud}/{metros}/{token}"
document['caja'].text = 'Cargando...'
req = ajax.ajax()
req.open('GET', url, False)
req.bind('complete', al_completar)
req.send()
def obtenerDatos_Campos():
global condicion, latitud, longitud, metros
condicion = document['condi'].value
latitud = document['lat'].value
longitud = document['lon'].value
metros = document['mts'].value
def ordenar(lista):
cant_locales = len(lista)
lista = list(lista)
print(type(lista))
print(cant_locales)
locales = [' '.join([local['Nombre'], local['Clase_actividad'], local['Telefono']]) for local in lista]
document['caja'] <= html.P(f"Hay {cant_locales} locales a {metros} metros de esta ubicación ({latitud}, {longitud})\
Que se encuentra en {lista[0]['Ubicacion']}") + html.BR()
for local in locales:
document['caja'] <= html.P(local) + html.BR()
condicion = ''
metros = ''
longitud = ''
latitud = ''
document['boton-ajax'].bind('click', solicitar_api)
</script>
</body>
</html>