metiendo archivos

This commit is contained in:
David Itehua Xalamihua 2024-08-20 15:25:10 -06:00
parent 5038b2433e
commit 4ac7d834f0
17 changed files with 11306 additions and 0 deletions

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

View File

@ -0,0 +1,150 @@
{
"cells": [
{
"cell_type": "code",
"execution_count": 1,
"metadata": {},
"outputs": [
{
"name": "stderr",
"output_type": "stream",
"text": [
"100%|██████████| 192244/192244 [20:23<00:00, 157.09it/s]"
]
},
{
"name": "stdout",
"output_type": "stream",
"text": [
"Servidor 192.168.1.81 actualizado en coordenadas de mexico (pais)\n"
]
},
{
"name": "stderr",
"output_type": "stream",
"text": [
"\n"
]
}
],
"source": [
"import psycopg2\n",
"import json\n",
"from lst_servers import *\n",
"from tqdm import tqdm\n",
"\n",
"# Parámetros de conexión a la base de datos\n",
"\n",
"json_file_path = \"./GeoJSON - Censo 2010 (Localidad) ITER.json\"\n",
"\n",
"with open(json_file_path, 'r', encoding='utf-8-sig') as f:\n",
" json_content = json.load(f)\n",
"\n",
"# Divide los datos en bloques más pequeños\n",
"chunk_size = 100 # Ajusta el tamaño del bloque según tus necesidades\n",
"json_features = json_content['features']\n",
"\n",
"chunks = [json_features[i:i + chunk_size] for i in range(0, len(json_features), chunk_size)]\n",
"\n",
"# Itera sobre los servidores e inserta los bloques de datos en la base de datos\n",
"for ip in l_ips:\n",
" conn = psycopg2.connect(\n",
" host=ip,\n",
" port=5432,\n",
" database=\"coordenadas_mx\",\n",
" user=\"postgres\",\n",
" password=\"Shala55951254\"\n",
" )\n",
" \n",
" cursor = conn.cursor()\n",
" cursor.execute(\"DROP TABLE IF EXISTS coordenadas_loc;\")\n",
"\n",
" create_table_query = \"\"\"\n",
" CREATE TABLE coordenadas_loc (\n",
" key_edomunloc CHARACTER VARYING,\n",
" id_edo CHARACTER VARYING,\n",
" edo CHARACTER VARYING,\n",
" id_mun CHARACTER VARYING, \n",
" mun CHARACTER VARYING,\n",
" id_loc CHARACTER VARYING,\n",
" loc CHARACTER VARYING,\n",
" json_data JSONB\n",
" );\"\"\"\n",
" \n",
" cursor.execute(create_table_query)\n",
" \n",
" # for i in tqdm(range(len(json_content['features']))):\n",
" # key_edomunloc = f\"{json_content['features'][i]['properties']['entidad']}_{json_content['features'][i]['properties']['mun']}_{json_content['features'][i]['properties']['loc']}\"\n",
" # id_edo = json_content['features'][i]['properties']['entidad']\n",
" # edo = json_content['features'][i]['properties']['nom_ent']\n",
" # id_mun = json_content['features'][i]['properties']['mun']\n",
" # mun = json_content['features'][i]['properties']['nom_mun']\n",
" # id_loc = json_content['features'][i]['properties']['loc']\n",
" # loc = json_content['features'][i]['properties']['nom_loc']\n",
" # geometry = json.dumps({'feactures': json_content['features'][i]['geometry']})\n",
" for i in tqdm(range(len(json_content['features']))):\n",
" key_edomunloc = f\"{json_content['features'][i]['properties']['entidad']}_{json_content['features'][i]['properties']['mun']}_{json_content['features'][i]['properties']['loc']}\"\n",
" id_edo = json_content['features'][i]['properties']['entidad']\n",
" edo = json_content['features'][i]['properties']['nom_ent']\n",
" id_mun = json_content['features'][i]['properties']['mun']\n",
" mun = json_content['features'][i]['properties']['nom_mun']\n",
" id_loc = json_content['features'][i]['properties']['loc']\n",
" loc = json_content['features'][i]['properties']['nom_loc']\n",
" geometry = json.dumps(json_content['features'][i]['geometry']) # Remove redundant dictionary\n",
"\n",
" insert_query = \"INSERT INTO coordenadas_loc (key_edomunloc, id_edo, edo, id_mun, mun, id_loc, loc, json_data) VALUES (%s, %s, %s, %s, %s, %s, %s, %s);\"\n",
"\n",
" cursor.execute(insert_query, (key_edomunloc, id_edo, edo, id_mun, mun, id_loc, loc, geometry))\n",
" conn.commit()\n",
"\n",
" # -------\n",
"\n",
"\n",
" # Guardar cambios\n",
" \n",
" # Cerrar la conexión\n",
" cursor.close()\n",
" conn.close()\n",
" print(f'Servidor {ip} actualizado en coordenadas de mexico (pais)')\n"
]
},
{
"cell_type": "code",
"execution_count": 2,
"metadata": {},
"outputs": [],
"source": [
"# dict_keys(['type', 'id', 'geometry', 'geometry_name', 'properties'])\n",
"\n",
"id_edo = json_content['features'][0]['properties']['entidad']\n",
"edo = json_content['features'][0]['properties']['nom_ent']\n",
"id_mun = json_content['features'][0]['properties']['mun']\n",
"mun = json_content['features'][0]['properties']['nom_mun']\n",
"id_loc = json_content['features'][0]['properties']['loc']\n",
"loc = json_content['features'][0]['properties']['nom_loc']\n",
"geometry = json_content['features'][0]['geometry']"
]
}
],
"metadata": {
"kernelspec": {
"display_name": "Python 3",
"language": "python",
"name": "python3"
},
"language_info": {
"codemirror_mode": {
"name": "ipython",
"version": 3
},
"file_extension": ".py",
"mimetype": "text/x-python",
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.10.6"
}
},
"nbformat": 4,
"nbformat_minor": 2
}

View File

@ -0,0 +1,95 @@
{
"cells": [
{
"cell_type": "code",
"execution_count": 1,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"Servidor 192.168.1.81 actualizado en coordenadas de mexico (pais)\n"
]
}
],
"source": [
"import psycopg2\n",
"import json\n",
"from lst_servers import *\n",
"\n",
"# Parámetros de conexión a la base de datos\n",
"\n",
"json_file_path = \".\\GeoJSON - Censo 2010 (Municipal).json\"\n",
"with open(json_file_path, 'r', encoding='utf-8-sig') as f:\n",
" json_content = json.load(f)\n",
"\n",
"for ip in l_ips:\n",
" conn = psycopg2.connect(\n",
" host=ip,\n",
" port=5432,\n",
" database=\"coordenadas_mx\",\n",
" user=\"postgres\",\n",
" password=\"Shala55951254\")\n",
"\n",
" cursor = conn.cursor()\n",
" cursor.execute(\"DROP TABLE IF EXISTS coordenadas_mun;\")\n",
"\n",
" create_table_query = \"\"\"\n",
" CREATE TABLE coordenadas_mun (\n",
" id_edo INT,\n",
" edo CHARACTER VARYING,\n",
" id_mun INT,\n",
" mun CHARACTER VARYING,\n",
" key_edomun CHARACTER VARYING,\n",
" geojson_mun JSONB\n",
" );\"\"\"\n",
"\n",
" cursor.execute(create_table_query)\n",
"\n",
" # Insertar el contenido JSON en la tabla\n",
" \n",
" for index in enumerate(json_content['features']):\n",
" id_edo = int(json_content['features'][index[0]]['properties']['cve_ent'])\n",
" edo = json_content['features'][index[0]]['properties']['nom_ent']\n",
" id_mun = int(json_content['features'][index[0]]['properties']['cve_umun'][2:])\n",
" mun = json_content['features'][index[0]]['properties']['nom_mun']\n",
" key_edomun = f'{id_edo}_{id_mun}'\n",
" geometry = json_content['features'][index[0]]['geometry']\n",
" insert_query = \"INSERT INTO coordenadas_mun (id_edo, edo, id_mun, mun, key_edomun, geojson_mun ) VALUES (%s, %s, %s, %s, %s, %s);\"\n",
" cursor.execute(insert_query, (id_edo, edo, id_mun, mun, key_edomun, json.dumps(geometry),))\n",
" \n",
" # insert_query = \"INSERT INTO coordenadas_mun (json_data) VALUES (%s);\"\n",
" # cursor.execute(insert_query, (json.dumps(json_content),))\n",
"\n",
" # guardar cambios\n",
" conn.commit()\n",
" # Cerrar la conexión\n",
" cursor.close()\n",
" conn.close()\n",
" print(f'Servidor {ip} actualizado en coordenadas de mexico (pais)')\n"
]
}
],
"metadata": {
"kernelspec": {
"display_name": "Python 3",
"language": "python",
"name": "python3"
},
"language_info": {
"codemirror_mode": {
"name": "ipython",
"version": 3
},
"file_extension": ".py",
"mimetype": "text/x-python",
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.10.6"
}
},
"nbformat": 4,
"nbformat_minor": 2
}

View File

@ -0,0 +1,2 @@
l_ips = ["192.168.1.81"]
# l_ips = ["127.0.0.1"] # 192.168.1.82

File diff suppressed because it is too large Load Diff

View File

@ -0,0 +1,194 @@
[{
"idEdo": "1",
"Centro_SICT": "Aguascalientes",
"Nombre_Subdir": "Ing. Elia Cabanillas García",
"Cargo": "Subdirectora Centro S.I.C.T."
},
{
"idEdo": "2",
"Centro_SICT": "Baja California",
"Nombre_Subdir": "Ing. Ana Karina Pérez García",
"Cargo": "Subdirectora Centro S.I.C.T."
},
{
"idEdo": "3",
"Centro_SICT": "Baja California Sur",
"Nombre_Subdir": "Ing. Fernando Asaff López Pelaez",
"Cargo": "Subdirector Centro S.I.C.T."
},
{
"idEdo": "4",
"Centro_SICT": "Campeche",
"Nombre_Subdir": "Ing. Gilmer Sabido Ávila",
"Cargo": "Subdirector Centro S.I.C.T."
},
{
"idEdo": "5",
"Centro_SICT": "Coahuila",
"Nombre_Subdir": "Ing. Vito Alessio Álvarez Bujanos",
"Cargo": "Subdirector Centro S.I.C.T."
},
{
"idEdo": "6",
"Centro_SICT": "Colima",
"Nombre_Subdir": "Ing. José Luis Moya Rivera",
"Cargo": "Subdirector Centro S.I.C.T."
},
{
"idEdo": "7",
"Centro_SICT": "Chiapas",
"Nombre_Subdir": "Ing. José Luis Méndez Rovelo",
"Cargo": "Subdirector Centro S.I.C.T."
},
{
"idEdo": "8",
"Centro_SICT": "Chihuahua",
"Nombre_Subdir": "Mtro. Mario Alberto Quirino García",
"Cargo": "Encargado del despacho de la Subdirección de Comunicaciones Centro S.I.C.T."
},
{
"idEdo": "9",
"Centro_SICT": "Ciudad de México",
"Nombre_Subdir": "",
"Cargo": ""
},
{
"idEdo": "10",
"Centro_SICT": "Durango",
"Nombre_Subdir": "Ing. Alberto Bujanda Rentería",
"Cargo": "Subdirector Centro S.I.C.T."
},
{
"idEdo": "11",
"Centro_SICT": "Guanajuato",
"Nombre_Subdir": "Lic. Juan Enrique Ibáñez Solís",
"Cargo": "Subdirector Centro S.I.C.T."
},
{
"idEdo": "12",
"Centro_SICT": "Guerrero",
"Nombre_Subdir": "Ing. José Luis Álvarez Ríos",
"Cargo": "Subdirector Centro S.I.C.T."
},
{
"idEdo": "13",
"Centro_SICT": "Hidalgo",
"Nombre_Subdir": "Ing. José Luis Reyes Salas",
"Cargo": "Subdirector Centro S.I.C.T."
},
{
"idEdo": "14",
"Centro_SICT": "Jalisco",
"Nombre_Subdir": "Ing. José Alberto Sánchez Vázquez",
"Cargo": "Subdirector Centro S.I.C.T."
},
{
"idEdo": "15",
"Centro_SICT": "México",
"Nombre_Subdir": "Ing. Hermes Sánchez Guzmán",
"Cargo": "Subdirector Centro S.I.C.T."
},
{
"idEdo": "16",
"Centro_SICT": "Michoacán",
"Nombre_Subdir": "Ing. José Luis Reyes Gutiérrez",
"Cargo": "Subdirector Centro S.I.C.T."
},
{
"idEdo": "17",
"Centro_SICT": "Morelos",
"Nombre_Subdir": "Ing. Lino Amilpa Pichardo",
"Cargo": "Subdirector Centro S.I.C.T."
},
{
"idEdo": "18",
"Centro_SICT": "Nayarit",
"Nombre_Subdir": "Ing. César Carrillo Monteon",
"Cargo": "Subdirector Centro S.I.C.T."
},
{
"idEdo": "19",
"Centro_SICT": "Nuevo León",
"Nombre_Subdir": "Ing. Rosa María Elizondo Fernández",
"Cargo": "Subdirectora Centro S.I.C.T."
},
{
"idEdo": "20",
"Centro_SICT": "Oaxaca",
"Nombre_Subdir": "Ing. Antonio Muñoz Serrano",
"Cargo": "Subdirector Centro S.I.C.T."
},
{
"idEdo": "21",
"Centro_SICT": "Puebla",
"Nombre_Subdir": "Ing. Francisco Javier Grimaldo Robles",
"Cargo": "Subdirector Centro S.I.C.T."
},
{
"idEdo": "22",
"Centro_SICT": "Querétaro",
"Nombre_Subdir": "Ing. Raúl Quiñones Mota",
"Cargo": "Subdirector Centro S.I.C.T."
},
{
"idEdo": "23",
"Centro_SICT": "Quintana Roo",
"Nombre_Subdir": "Lic. Enrique Alejandro Garza Roa",
"Cargo": "Subdirector Centro S.I.C.T."
},
{
"idEdo": "24",
"Centro_SICT": "San Luis Potosí",
"Nombre_Subdir": "Ing. José Humberto Reyes Góngora",
"Cargo": "Subdirector Centro S.I.C.T."
},
{
"idEdo": "25",
"Centro_SICT": "Sinaloa",
"Nombre_Subdir": "Ing. César Santos Corrales Arechiga",
"Cargo": "Subdirector Centro S.I.C.T."
},
{
"idEdo": "26",
"Centro_SICT": "Sonora",
"Nombre_Subdir": "Ing. Miguel Darío Quiñones Mota",
"Cargo": "Subdirector Centro S.I.C.T."
},
{
"idEdo": "27",
"Centro_SICT": "Tabasco",
"Nombre_Subdir": "Ing. Williams Zapata Gómez",
"Cargo": "Encargado del despacho de la Subdirección de Comunicaciones Centro S.I.C.T."
},
{
"idEdo": "28",
"Centro_SICT": "Tamaulipas",
"Nombre_Subdir": "Ing. Ulises Enríquez Toledo",
"Cargo": "Subdirector Centro S.I.C.T."
},
{
"idEdo": "29",
"Centro_SICT": "Tlaxcala",
"Nombre_Subdir": "Ing. Ma. Del Pilar Guzmán Coeto",
"Cargo": "Subdirectora Centro S.I.C.T."
},
{
"idEdo": "30",
"Centro_SICT": "Veracruz",
"Nombre_Subdir": "Mtro. Denis Hailet Rios del Valle",
"Cargo": "Subdirector Centro S.I.C.T."
},
{
"idEdo": "31",
"Centro_SICT": "Yucatán",
"Nombre_Subdir": "Ing. Ignacio Beltrán Noz",
"Cargo": "Subdirector Centro S.I.C.T."
},
{
"idEdo": "32",
"Centro_SICT": "Zacatecas",
"Nombre_Subdir": "Ing. Roberto Saucedo Ballesteros",
"Cargo": "Subdirector Centro S.I.C.T."
}
]

File diff suppressed because it is too large Load Diff

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

View File

@ -0,0 +1,94 @@
{
"cells": [
{
"cell_type": "code",
"execution_count": 1,
"metadata": {},
"outputs": [],
"source": [
"import json"
]
},
{
"cell_type": "code",
"execution_count": 10,
"metadata": {},
"outputs": [],
"source": [
"with open(\"./coordenas_unicas.json\", mode=\"r\") as f:\n",
" data = json.load(f)\n",
" "
]
},
{
"cell_type": "code",
"execution_count": 13,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"dict_keys(['geometry', 'properties'])\n",
"dict_keys(['geometry', 'properties'])\n",
"dict_keys(['geometry', 'properties'])\n",
"dict_keys(['geometry', 'properties'])\n",
"dict_keys(['geometry', 'properties'])\n",
"dict_keys(['geometry', 'properties'])\n",
"dict_keys(['geometry', 'properties'])\n",
"dict_keys(['geometry', 'properties'])\n",
"dict_keys(['geometry', 'properties'])\n",
"dict_keys(['geometry', 'properties'])\n",
"dict_keys(['geometry', 'properties'])\n",
"dict_keys(['geometry', 'properties'])\n",
"dict_keys(['geometry', 'properties'])\n",
"dict_keys(['geometry', 'properties'])\n",
"dict_keys(['geometry', 'properties'])\n",
"dict_keys(['geometry', 'properties'])\n",
"dict_keys(['geometry', 'properties'])\n",
"dict_keys(['geometry', 'properties'])\n",
"dict_keys(['geometry', 'properties'])\n",
"dict_keys(['geometry', 'properties'])\n",
"dict_keys(['geometry', 'properties'])\n",
"dict_keys(['geometry', 'properties'])\n",
"dict_keys(['geometry', 'properties'])\n",
"dict_keys(['geometry', 'properties'])\n",
"dict_keys(['geometry', 'properties'])\n",
"dict_keys(['geometry', 'properties'])\n",
"dict_keys(['geometry', 'properties'])\n",
"dict_keys(['geometry', 'properties'])\n",
"dict_keys(['geometry', 'properties'])\n",
"dict_keys(['geometry', 'properties'])\n",
"dict_keys(['geometry', 'properties'])\n",
"dict_keys(['geometry', 'properties'])\n"
]
}
],
"source": [
"for ele in data:\n",
" print(ele)"
]
}
],
"metadata": {
"kernelspec": {
"display_name": "Python 3",
"language": "python",
"name": "python3"
},
"language_info": {
"codemirror_mode": {
"name": "ipython",
"version": 3
},
"file_extension": ".py",
"mimetype": "text/x-python",
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.11.3"
}
},
"nbformat": 4,
"nbformat_minor": 2
}

File diff suppressed because it is too large Load Diff

View File

@ -0,0 +1,39 @@
import psycopg2
import json
from lst_servers import *
# Parámetros de conexión a la base de datos
json_file_path = ".\json_files\coordenas_unicas.json"
with open(json_file_path, 'r', encoding='utf-8-sig') as f:
json_content = json.load(f)
for ip in l_ips:
conn = psycopg2.connect(
host=ip,
port=5432,
database="coordenadas_mx",
user="postgres",
password="Shala55951254")
cursor = conn.cursor()
cursor.execute("DROP TABLE IF EXISTS coordenadas_mexico;")
create_table_query = """
CREATE TABLE coordenadas_mexico (
id SERIAL PRIMARY KEY,
json_data JSONB
);"""
cursor.execute(create_table_query)
# Insertar el contenido JSON en la tabla
insert_query = "INSERT INTO coordenadas_mexico (json_data) VALUES (%s);"
cursor.execute(insert_query, (json.dumps(json_content),))
# guardar cambios
conn.commit()
# Cerrar la conexión
cursor.close()
conn.close()
print(f'Servidor {ip} actualizado en coordenadas de mexico (pais)')

View File

@ -0,0 +1,39 @@
import psycopg2
import json
from lst_servers import *
# Parámetros de conexión a la base de datos
json_file_path = ".\json_files\DirectorioCSICT.json"
with open(json_file_path, 'r', encoding='utf-8-sig') as f:
json_content = json.load(f)
for ip in l_ips:
conn = psycopg2.connect(
host=ip,
port=5432,
database="aldeas_inteligentes",
user="postgres",
password="Shala55951254")
cursor = conn.cursor()
cursor.execute("DROP TABLE IF EXISTS dir_csict;")
create_table_query = """
CREATE TABLE dir_csict (
id SERIAL PRIMARY KEY,
json_data JSONB
);"""
cursor.execute(create_table_query)
# Insertar el contenido JSON en la tabla
insert_query = "INSERT INTO dir_csict (json_data) VALUES (%s);"
cursor.execute(insert_query, (json.dumps(json_content),))
# guardar cambios
conn.commit()
# Cerrar la conexión
cursor.close()
conn.close()
print(f'Servidor {ip} actualizado en directorio centros sict')