oshix
This commit is contained in:
2
.gitignore
vendored
2
.gitignore
vendored
@@ -1,6 +1,6 @@
|
|||||||
# ---> Node
|
# ---> Node
|
||||||
# Logs
|
# Logs
|
||||||
logs.csv
|
*.csv
|
||||||
*.log
|
*.log
|
||||||
npm-debug.log*
|
npm-debug.log*
|
||||||
yarn-debug.log*
|
yarn-debug.log*
|
||||||
|
|||||||
58
oso.js
Normal file
58
oso.js
Normal file
@@ -0,0 +1,58 @@
|
|||||||
|
const saludo = "Hola, mi nombre es Luciano Alegre y soy el presentador del Clima.",
|
||||||
|
dias = ['Lunes', 'Martes', 'Miercoles', 'Jueves', 'Viernes', 'Sabado', 'Domingo'],
|
||||||
|
consejos = {
|
||||||
|
Invierno: 'No te olvides de salir bien abrigado!',
|
||||||
|
Otoño: 'Acordate de salir con paraguas o piloto, por si llueve!',
|
||||||
|
Primavera: 'Nunca olvides, disfrutar mucho de las flores y los climas calidos!',
|
||||||
|
Verano: 'Seguro estas aprovechando de la playa!'
|
||||||
|
},
|
||||||
|
temperaturaRandom = Math.floor(Math.random() * 34) + 1,
|
||||||
|
diaRandom = Math.floor(Math.random() * 6),
|
||||||
|
hoy = dias[diaRandom];
|
||||||
|
|
||||||
|
let estacion = '';
|
||||||
|
|
||||||
|
if (temperaturaRandom <= 10) estacion = 'Invierno';
|
||||||
|
else if (temperaturaRandom > 10 && temperaturaRandom <= 15) estacion = 'Otoño';
|
||||||
|
else if (temperaturaRandom > 15 && temperaturaRandom <= 24) estacion = 'Primavera';
|
||||||
|
else estacion = 'Verano';
|
||||||
|
|
||||||
|
const mensaje = `
|
||||||
|
${saludo}
|
||||||
|
Hoy ${hoy} de ${estacion}, tenemos una temperatura de ${temperaturaRandom}°.
|
||||||
|
${consejos[estacion]}
|
||||||
|
`;
|
||||||
|
|
||||||
|
const nombre = 'Luciano';
|
||||||
|
const temperatura = 12;
|
||||||
|
const otro = 'Caca';
|
||||||
|
const otro2 = 'Cacas muy largas';
|
||||||
|
|
||||||
|
const objetivo = `Hola, mi nombre es ${nombre} y soy el presentador del Clima. Hoy Sabado de ${otro}, tenemos una temperatura de ${temperatura}°. ${otro2}`;
|
||||||
|
|
||||||
|
console.log(objetivo);
|
||||||
|
|
||||||
|
/*
|
||||||
|
let diasDeLaSemana = {
|
||||||
|
"Primer dia": "Lunes",
|
||||||
|
"Segundo dia": "Martes",
|
||||||
|
"Tercer dia": "Miercoles",
|
||||||
|
"Cuarto dia": "Jueves",
|
||||||
|
"Quinto dia": "Viernes",
|
||||||
|
"Sexto dia": "Sabado",
|
||||||
|
"Septimo dia": "Domingo"
|
||||||
|
};
|
||||||
|
|
||||||
|
console.log(temperaturaRandom <= estacionesDelAño["Invierno"]);
|
||||||
|
if (temperaturaRandom <= estacionesDelAño.Invierno) {
|
||||||
|
console.log(`${saludo}. Hoy, ${diasDeLaSemana["Primer dia"]} tenemos una temperaturaRandom de ${temperaturaRandom}°, en este invierno no te olvides de salir bien abrigado`);
|
||||||
|
} else if (temperaturaRandom <= estacionesDelAño["Otoño"]) {
|
||||||
|
console.log(`${saludo}. Hoy, ${diasDeLaSemana["Cuarto dia"]} tenemos una temperaturaRandom de ${temperaturaRandom}°, en este otoño y con tanta lluvia acordate de salir con paraguas o piloto`);
|
||||||
|
}
|
||||||
|
else if (temperaturaRandom <= estacionesDelAño["Primavera"]) {
|
||||||
|
console.log(`${saludo}. Hoy, ${diasDeLaSemana["Tercer dia"]} tenemos una temperaturaRandom de ${temperaturaRandom}°. En esta primavera disfruta mucho de las flores y los climas calidos`);
|
||||||
|
} else {
|
||||||
|
console.log(`${saludo}. Hoy, ${diasDeLaSemana["Septimo dia"]} tenemos una temperaturaRandom de ${temperaturaRandom}°. Seguro estas aprovechando de la playa`);
|
||||||
|
}
|
||||||
|
|
||||||
|
*/
|
||||||
@@ -1,8 +1,9 @@
|
|||||||
|
import { weatherApiKey, weatherUrl } from "./index.js";
|
||||||
import { log } from "./logger.js";
|
import { log } from "./logger.js";
|
||||||
import { ErrorResponse, GeoResponse } from "./types.js";
|
import { ErrorResponse, GeoResponse } from "./types.js";
|
||||||
|
|
||||||
export async function ubicacion(lugar: string, limit = '1'): Promise<ErrorResponse | GeoResponse> {
|
export async function ubicacion(lugar: string, limit = 1): Promise<GeoResponse | ErrorResponse> {
|
||||||
const response = await fetch(`${process.env.WEATHER_URL}/geo/1.0/direct?q=${lugar}&limit=${limit}&appid=${process.env.WEATHER_API_KEY}`);
|
const response = await fetch(`${weatherUrl}/geo/1.0/direct?q=${lugar}&limit=${limit}&appid=${weatherApiKey}`);
|
||||||
log('GET', response);
|
log('GET', response);
|
||||||
if (!response.ok) {
|
if (!response.ok) {
|
||||||
return {
|
return {
|
||||||
|
|||||||
18
src/index.ts
18
src/index.ts
@@ -1,13 +1,17 @@
|
|||||||
import { ubicacion } from "./clima.js";
|
import { ubicacion } from "./clima.js";
|
||||||
|
|
||||||
if (typeof process.env.WEATHER_URL === 'undefined' || typeof process.env.WEATHER_API_KEY === 'undefined' || typeof process.argv[2] === 'undefined') {
|
export const weatherUrl = process.env.WEATHER_URL || '' as const,
|
||||||
console.error('WEATHER_URL', typeof process.env.WEATHER_URL);
|
weatherApiKey = process.env.WEATHER_API_KEY || '' as const,
|
||||||
console.error('WEATHER_API_KEY', typeof process.env.WEATHER_API_KEY);
|
commandInput = process.argv[2] || '' as const;
|
||||||
console.error('Ciudad', typeof process.argv[2]);
|
|
||||||
process.exit(0);
|
|
||||||
|
|
||||||
|
if (weatherUrl === '' || weatherApiKey === '' || commandInput === '') {
|
||||||
|
console.error('WEATHER_URL', weatherUrl);
|
||||||
|
console.error('WEATHER_API_KEY', weatherApiKey);
|
||||||
|
console.error('Ciudad', commandInput);
|
||||||
|
process.exit(0);
|
||||||
}
|
}
|
||||||
|
|
||||||
const busqueda = await ubicacion(process.argv[2]);
|
const busqueda = await ubicacion(commandInput, 3);
|
||||||
|
|
||||||
|
console.log('busqueda', busqueda);
|
||||||
|
|
||||||
console.log('Busqueda', busqueda);
|
|
||||||
|
|||||||
54
test.js
Normal file
54
test.js
Normal file
@@ -0,0 +1,54 @@
|
|||||||
|
const numeroEntero = 60;
|
||||||
|
const numeroDecimal = 10.5;
|
||||||
|
const numeroNegativo = -1;
|
||||||
|
|
||||||
|
console.log("numeroEntero", numeroEntero);
|
||||||
|
console.log("numeroDecimal", numeroDecimal);
|
||||||
|
console.log("numeroNegativo", numeroNegativo);
|
||||||
|
|
||||||
|
console.log('string / 2', "string" / 2);
|
||||||
|
|
||||||
|
|
||||||
|
const nanEsNumber = "" / 2;
|
||||||
|
const numInfinito = numeroEntero / 0;
|
||||||
|
const operacionesConString = "20";
|
||||||
|
const resultado = 10 + 5 * 2 - 8 / 4;
|
||||||
|
const numeroBooleanoTrue = true;
|
||||||
|
const numeroBooleanoFalse = false;
|
||||||
|
const numeroNull = null;
|
||||||
|
const numeroUndefined = undefined;
|
||||||
|
const precedenciaOperadorMulti = 2 + 3 * 4;
|
||||||
|
const precedenciaOperadorDiv = 2 + 3 / 4;
|
||||||
|
const preferenciaDeEjecucion = (2 + 3) * 4;
|
||||||
|
const asociatividadSumyRes = 4 + 5 - 6;
|
||||||
|
let operadorAsignacionA, operadorAsignacionB;
|
||||||
|
operadorAsignacionA = operadorAsignacionB = 5;
|
||||||
|
const operadorExponente = 2 ** 3 ** 2;
|
||||||
|
|
||||||
|
/* console.log("Tipo de dato Number", typeof numeroEntero, typeof numeroDecimal, typeof numeroNegativo);
|
||||||
|
console.log("Infinito", numInfinito);
|
||||||
|
console.log(typeof nanEsNumber);
|
||||||
|
console.log("operador +", numeroEntero + numeroDecimal);
|
||||||
|
console.log("operador -", numeroEntero - numeroDecimal);
|
||||||
|
console.log("operador *", numeroDecimal * numeroEntero);
|
||||||
|
console.log("operador /", numeroEntero / numeroDecimal);
|
||||||
|
console.log("operador %", numeroEntero % numeroDecimal);
|
||||||
|
console.log("operador ", numeroEntero ** numeroDecimal);
|
||||||
|
console.log("mezcla operadores", resultado);
|
||||||
|
console.log("suma con string", numeroEntero + operacionesConString);
|
||||||
|
console.log("resta con string", numeroEntero - operacionesConString);
|
||||||
|
console.log("multiplicacion con string", numeroEntero * operacionesConString);
|
||||||
|
console.log("division con string", numeroEntero / operacionesConString);
|
||||||
|
console.log("operacion con booleano true", numeroEntero + numeroBooleanoTrue);
|
||||||
|
console.log("operacion con booleano false", numeroEntero + numeroBooleanoFalse);
|
||||||
|
console.log("operacion booleano con string", operacionesConString + numeroBooleanoTrue);
|
||||||
|
console.log("operacion con null", numeroEntero * numeroNull);
|
||||||
|
console.log("operacion con undefined", numeroEntero * numeroUndefined);
|
||||||
|
console.log("operador de mayor precedencia multiplicacion", precedenciaOperadorMulti);
|
||||||
|
console.log("operador de mayor precedencia division", precedenciaOperadorDiv);
|
||||||
|
console.log("preferencia de ejecucion", preferenciaDeEjecucion);
|
||||||
|
console.log("asociatividad de izquierda a derecha", asociatividadSumyRes);
|
||||||
|
console.log("asociatividad de derecha a izquierda (=)", operadorAsignacionA, operadorAsignacionB);
|
||||||
|
console.log("asociatividad de derecha a izquierda ()", operadorExponente);
|
||||||
|
console.log("operador de incremento prefijo", ++operadorAsignacionA);
|
||||||
|
console.log("operador de incremento postfijo", operadorAsignacionA++); */
|
||||||
Reference in New Issue
Block a user