# ******* DEFINCICIONES ***************** import pyodide_js await pyodide_js.loadPackage('requests') await pyodide_js.loadPackage('pandas') from datetime import datetime import time import pandas as pd import shutil from pyscript import fetch import datetime as dt # ************** DIBUJOS ******************* import pyodide_js await pyodide_js.loadPackage('matplotlib') import matplotlib.pyplot as plt import numpy as np # from pyscript import display # ******* LLAMADAS DE API ***************** terremotos = await fetch("https://earthquake.usgs.gov/earthquakes/feed/v1.0/summary/4.5_month.geojson", method="GET").json() # ******* FECHA DE HOY ***************** print(" TABLA DE SISMOS MAYORES A 4.5 DEL ULTIMO MES") print(" FUENTE US GEOLOGICAL SURVEY EN TIEMPO REAL") print(" PROGRAMA: M.Sc.(TUM) Marcelo Moncayo Theurer, PsGr., Ing.") print() now = dt.datetime.now() now2 = str(now) dfecha2 = 19-len(now2) if len(now2)>19: now2 = now2[:dfecha2] print('\t FECHA DE HOY : ' + now2) print() # print(terremotos) # esto se activa para ver el formato Json cont=0 # contador # ******* TITULOS ***************** # print(" 1 2 3 4 5 6 7 ") # print("123456789012345678901234567890123456789012345678901234567890123456789012345678") print('NUM ' + ' MAGN ' + '\t FECHA ' + '\t\t\t LUGAR ' ) # ******* CONSTRUCCION DE TABLA ***************** for terremoto in terremotos ["features"]: # TOMA valores coordenadas = terremoto["geometry"]["coordinates"] lugar = terremoto["properties"]["place"] magnitude = terremoto["properties"]["mag"] fecha = terremoto["properties"]["time"] cont=cont+1 # CONTADOR fecha100 = datetime.fromtimestamp(fecha/1000) # TRANSFORMACION DE DATESTAMP A FECHA NORMAL fecha200 = str(fecha100) dfecha = 19-len(fecha200) if len(fecha200)>19: fecha200 = fecha200[:dfecha] cont2 = str(cont) cont3 = cont2.zfill(5) magnitude=round(magnitude,1) mag2 = str(magnitude) if len(mag2)==1: mag2 = mag2 +".0" lug2 = str(lugar) lug3 = lug2[0:42] # magnitude = "%.2f" % magnitude # redondea la magnitud a 2 decimales # ******* IMPRIME LA TABLA ***************** print(cont3 + ' '+ mag2 + ' ' + fecha200 + ' ' + lug3) # lugar = lugar.zfill(28) # LLENA DE EL LUGAR DE 28 CARACTERES # str(len(lugar[0:27])) str(len(cont3)) str(len(mag2)) str(lugar[0:28]) # esto nos da la longitud de l string # print(type(fecha100)) # esto es para saber que tipo de variable tengo, terremoto es dict, lugar es src, coordenadas es list y magnitude es float #3 separar en listas # Convertir las cadenas a listas # coordenadas2 = coordenadas.split() # magnitudes2 = magnitude.split() # Crear un DataFrame #df = pd.DataFrame({ # 'coordenadas': coordenadas2, # 'magnitude': magnitudes2 #}) # num = 3 # print("lugar (i)") # for i in range (11): # print(i, lugar[i]) # 4) FIN # Convertir el diccionario a un DataFrame # import pandas as pd # df = pd.DataFrame.from_dict(terremotos) # print(df) # 2) FIN # df = pd.DataFrame.from_dict(terremotos) # print(df) # ******* FIN ***************** print() print() print() # ******* LLAMADAS DE API 3 ***************** terremotos = await fetch("https://earthquake.usgs.gov/earthquakes/feed/v1.0/summary/significant_month.geojson", method="GET").json() # ******* FECHA DE HOY ***************** print(" TABLA DE SISMOS MAS SIGINIFICATIVOS DEL ULTIMO MES") print(" FUENTE US GEOLOGICAL SURVEY EN TIEMPO REAL") print(" PROGRAMA: M.Sc.(TUM) Marcelo Moncayo Theurer, PsGr., Ing.") print() now = dt.datetime.now() now2 = str(now) dfecha2 = 19-len(now2) if len(now2)>19: now2 = now2[:dfecha2] print('\t FECHA DE HOY : ' + now2) print() # print(terremotos) # esto se activa para ver el formato Json cont=0 # contador # ******* TITULOS ***************** print('NUM ' + ' MAGN ' + '\t FECHA ' + '\t\t\t LUGAR ' ) # ******* CONSTRUCCION DE TABLA ***************** for terremoto in terremotos ["features"]: # TOMA valores coordenadas = terremoto["geometry"]["coordinates"] lugar = terremoto["properties"]["place"] magnitude = terremoto["properties"]["mag"] fecha = terremoto["properties"]["time"] cont=cont+1 # CONTADOR fecha100 = datetime.fromtimestamp(fecha/1000) # TRANSFORMACION DE DATESTAMP A FECHA NORMAL fecha200 = str(fecha100) dfecha = 19-len(fecha200) if len(fecha200)>19: fecha200 = fecha200[:dfecha] cont2 = str(cont) cont3 = cont2.zfill(5) magnitude=round(magnitude,1) mag2 = str(magnitude) if len(mag2)==1: mag2 = mag2 +".0" lug2 = str(lugar) lug3 = lug2[0:42] # magnitude = "%.2f" % magnitude # redondea la magnitud a 2 decimales # ******* IMPRIME LA TABLA ***************** print(cont3 + ' '+ mag2 + ' ' + fecha200 + ' ' + lug3) # ******* FIN ***************** print(" SENO - COSENO - SENO + COSENO ") x= np.arange(0,30,0.1) y=np.sin(x) plt.plot (x,y) plt.show() x= np.arange(0,30,0.1) y=np.cos(x) plt.plot (x,y) plt.show() x= np.arange(0,30,0.1) y=np.cos(x) +np.sin(x) plt.plot (x,y) plt.show() # fig1 =plt.plot (x,y) # display(fig1, target="mpl")