Skip to content

Commit

Permalink
Update to include weather results
Browse files Browse the repository at this point in the history
  • Loading branch information
khorwood-openai committed Sep 30, 2024
1 parent e6c23bf commit 4d880a5
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 1 deletion.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
"build": "react-scripts build",
"test": "react-scripts test",
"eject": "react-scripts eject",
"zip": "zip -r realtime-api-console.zip . -x 'node_modules' 'node_modules/*' 'node_modules/**' '.git' '.git/*' '.git/**' '.DS_Store' '*/.DS_Store' 'package-lock.json' '*.zip' '*.tar.gz' '*.tar'",
"zip": "zip -r realtime-api-console.zip . -x 'node_modules' 'node_modules/*' 'node_modules/**' '.git' '.git/*' '.git/**' '.DS_Store' '*/.DS_Store' 'package-lock.json' '*.zip' '*.tar.gz' '*.tar' '.env'",
"relay": "nodemon ./relay-server/index.js"
},
"eslintConfig": {
Expand Down
22 changes: 22 additions & 0 deletions src/pages/ConsolePage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ import { Toggle } from '../components/toggle/Toggle';
import { Map } from '../components/Map';

import './ConsolePage.scss';
import { isJsxOpeningLikeElement } from 'typescript';

/**
* Type for result from get_weather() function call
Expand All @@ -30,6 +31,14 @@ interface Coordinates {
lat: number;
lng: number;
location?: string;
temperature?: {
value: number;
units: string;
};
wind_speed?: {
value: number;
units: string;
};
}

/**
Expand Down Expand Up @@ -430,6 +439,15 @@ export function ConsolePage() {
`https://api.open-meteo.com/v1/forecast?latitude=${lat}&longitude=${lng}&current=temperature_2m,wind_speed_10m`
);
const json = await result.json();
const temperature = {
value: json.current.temperature_2m as number,
units: json.current_units.temperature_2m as string,
};
const wind_speed = {
value: json.current.wind_speed_10m as number,
units: json.current_units.wind_speed_10m as string,
};
setMarker({ lat, lng, location, temperature, wind_speed });
return json;
}
);
Expand Down Expand Up @@ -675,6 +693,10 @@ export function ConsolePage() {
<div className="content-block-title">get_weather()</div>
<div className="content-block-title bottom">
{marker?.location || 'not yet retrieved'}
{!!marker?.temperature &&
` 🌡️ ${marker.temperature.value} ${marker.temperature.units}`}
{!!marker?.wind_speed &&
` 🍃 ${marker.wind_speed.value} ${marker.wind_speed.units}`}
</div>
<div className="content-block-body full">
{coords && (
Expand Down

0 comments on commit 4d880a5

Please sign in to comment.