Spaces:
Runtime error
Runtime error
Commit
·
5341bb3
1
Parent(s):
f151f9d
graph
Browse files
graph.py
ADDED
@@ -0,0 +1,19 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import csv
|
2 |
+
import json
|
3 |
+
|
4 |
+
def buscar_en_csv_y_generar_json(archivo_csv, valor_busqueda):
|
5 |
+
resultados = []
|
6 |
+
|
7 |
+
with open(archivo_csv, mode='r', encoding='utf-8') as file:
|
8 |
+
reader = csv.reader(file)
|
9 |
+
|
10 |
+
for fila in reader:
|
11 |
+
linea_completa = ','.join(fila)
|
12 |
+
if valor_busqueda in linea_completa:
|
13 |
+
resultados.append(fila)
|
14 |
+
|
15 |
+
if resultados:
|
16 |
+
return json.dumps(resultados, indent=4, ensure_ascii=False)
|
17 |
+
else:
|
18 |
+
return json.dumps({"mensaje": "No se encontraron coincidencias."}, indent=4, ensure_ascii=False)
|
19 |
+
|