oshix
This commit is contained in:
@@ -1,8 +1,9 @@
|
||||
import { weatherApiKey, weatherUrl } from "./index.js";
|
||||
import { log } from "./logger.js";
|
||||
import { ErrorResponse, GeoResponse } from "./types.js";
|
||||
|
||||
export async function ubicacion(lugar: string, limit = '1'): Promise<ErrorResponse | GeoResponse> {
|
||||
const response = await fetch(`${process.env.WEATHER_URL}/geo/1.0/direct?q=${lugar}&limit=${limit}&appid=${process.env.WEATHER_API_KEY}`);
|
||||
export async function ubicacion(lugar: string, limit = 1): Promise<GeoResponse | ErrorResponse> {
|
||||
const response = await fetch(`${weatherUrl}/geo/1.0/direct?q=${lugar}&limit=${limit}&appid=${weatherApiKey}`);
|
||||
log('GET', response);
|
||||
if (!response.ok) {
|
||||
return {
|
||||
|
||||
18
src/index.ts
18
src/index.ts
@@ -1,13 +1,17 @@
|
||||
import { ubicacion } from "./clima.js";
|
||||
|
||||
if (typeof process.env.WEATHER_URL === 'undefined' || typeof process.env.WEATHER_API_KEY === 'undefined' || typeof process.argv[2] === 'undefined') {
|
||||
console.error('WEATHER_URL', typeof process.env.WEATHER_URL);
|
||||
console.error('WEATHER_API_KEY', typeof process.env.WEATHER_API_KEY);
|
||||
console.error('Ciudad', typeof process.argv[2]);
|
||||
process.exit(0);
|
||||
export const weatherUrl = process.env.WEATHER_URL || '' as const,
|
||||
weatherApiKey = process.env.WEATHER_API_KEY || '' as const,
|
||||
commandInput = process.argv[2] || '' as const;
|
||||
|
||||
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);
|
||||
|
||||
Reference in New Issue
Block a user