Skip to content

Commit

Permalink
add thunder alerts and local provider information
Browse files Browse the repository at this point in the history
  • Loading branch information
seguinleo authored Jul 11, 2023
1 parent aa488dc commit 9972b57
Show file tree
Hide file tree
Showing 5 changed files with 220 additions and 220 deletions.
68 changes: 34 additions & 34 deletions src/pages/_document.jsx
Original file line number Diff line number Diff line change
@@ -1,34 +1,34 @@
import React from 'react';
import {
Html, Head, Main, NextScript,
} from 'next/document';

export default function Document() {
return (
<Html lang="fr-FR">
<Head>
<meta name="theme-color" className="themecolor" content="#1c95ec" />
<meta name="apple-mobile-web-app-capable" content="yes" />
<meta name="apple-mobile-web-app-status-bar-style" className="themecolor" content="#1c95ec" />
<meta name="description" content="Météo en temps réel, précise et fiable pour n'importe quelle ville du monde avec prévisions." />
<meta name="twitter:card" content="summary" />
<meta name="twitter:title" content="Météo &#8211; Léo SEGUIN" />
<meta name="twitter:description" content="Météo en temps réel, précise et fiable pour n'importe quelle ville du monde avec prévisions." />
<meta property="og:type" content="website" />
<meta property="og:title" content="Météo &#8211; Léo SEGUIN" />
<meta property="og:description" content="Météo en temps réel, précise et fiable pour n'importe quelle ville du monde avec prévisions." />
<meta property="og:site_name" content="Météo &#8211; Léo SEGUIN" />
<meta property="og:url" content="https://meteo-leoseguin.vercel.app/" />
<meta property="og:locale" content="fr-FR" />
<link rel="canonical" href="https://meteo-leoseguin.vercel.app/" />
<link rel="shortcut icon" href="/favicon.ico" type="image/x-icon" />
<link rel="apple-touch-icon" href="/assets/icons/apple-touch-icon.png" />
<link rel="manifest" href="/manifest.json" />
</Head>
<body>
<Main />
<NextScript />
</body>
</Html>
);
}
import React from 'react';
import {
Html, Head, Main, NextScript,
} from 'next/document';

export default function Document() {
return (
<Html lang="fr-FR">
<Head>
<meta name="theme-color" className="themecolor" content="#1c95ec" />
<meta name="apple-mobile-web-app-capable" content="yes" />
<meta name="apple-mobile-web-app-status-bar-style" className="themecolor" content="#1c95ec" />
<meta name="description" content="Météo en temps réel, précise et fiable pour n'importe quelle ville du monde avec prévisions." />
<meta name="twitter:card" content="summary" />
<meta name="twitter:title" content="Météo &#8211; Léo SEGUIN" />
<meta name="twitter:description" content="Météo en temps réel, précise et fiable pour n'importe quelle ville du monde avec prévisions." />
<meta property="og:type" content="website" />
<meta property="og:title" content="Météo &#8211; Léo SEGUIN" />
<meta property="og:description" content="Météo en temps réel, précise et fiable pour n'importe quelle ville du monde avec prévisions." />
<meta property="og:site_name" content="Météo &#8211; Léo SEGUIN" />
<meta property="og:url" content="https://meteo-leoseguin.vercel.app/" />
<meta property="og:locale" content="fr-FR" />
<link rel="canonical" href="https://meteo-leoseguin.vercel.app/" />
<link rel="shortcut icon" href="/favicon.ico" type="image/x-icon" />
<link rel="apple-touch-icon" href="/assets/icons/apple-touch-icon.png" />
<link rel="manifest" href="/manifest.json" />
</Head>
<body>
<Main />
<NextScript />
</body>
</Html>
);
}
78 changes: 39 additions & 39 deletions src/pages/api/geolocation.js
Original file line number Diff line number Diff line change
@@ -1,39 +1,39 @@
const fetchWeatherData = async (latitude, longitude) => {
const key = process.env.API_KEY;
const geocodingResponse = await fetch(`https://api.openweathermap.org/geo/1.0/reverse?lat=${latitude}&lon=${longitude}&limit=1&appid=${key}`);
if (geocodingResponse.status === 404) {
throw new Error('Geocoding API returned 404');
}
const [geocodingData] = await geocodingResponse.json();
const [oneCallResponse, airPollutionResponse] = await Promise.all([
fetch(`https://api.openweathermap.org/data/2.5/onecall?lat=${latitude}&lon=${longitude}&appid=${key}&units=metric&exclude=minutely`),
fetch(`https://api.openweathermap.org/data/2.5/air_pollution?lat=${latitude}&lon=${longitude}&appid=${key}`),
]);
if (oneCallResponse.status !== 200) {
throw new Error('Unexpected error');
}
const [oneCallData, airPollutionData] = await Promise.all([
oneCallResponse.json(),
airPollutionResponse.json(),
]);

return {
city: `${geocodingData.name}, ${geocodingData.country}`,
oneCallData,
airPollutionData,
};
};

export default async function handler(req, res) {
if (req.method === 'POST') {
const { latitude, longitude } = req.body;
try {
const { city, oneCallData, airPollutionData } = await fetchWeatherData(latitude, longitude);
res.status(200).json({ city, oneCallData, airPollutionData });
} catch (error) {
res.status(400).json({ error: error.message });
}
} else {
res.status(404).send('');
}
}
const fetchWeatherData = async (latitude, longitude) => {
const key = process.env.API_KEY;
const geocodingResponse = await fetch(`https://api.openweathermap.org/geo/1.0/reverse?lat=${latitude}&lon=${longitude}&limit=1&appid=${key}`);
if (geocodingResponse.status === 404) {
throw new Error('Geocoding API returned 404');
}
const [geocodingData] = await geocodingResponse.json();
const [oneCallResponse, airPollutionResponse] = await Promise.all([
fetch(`https://api.openweathermap.org/data/2.5/onecall?lat=${latitude}&lon=${longitude}&appid=${key}&units=metric&exclude=minutely`),
fetch(`https://api.openweathermap.org/data/2.5/air_pollution?lat=${latitude}&lon=${longitude}&appid=${key}`),
]);
if (oneCallResponse.status !== 200) {
throw new Error('Unexpected error');
}
const [oneCallData, airPollutionData] = await Promise.all([
oneCallResponse.json(),
airPollutionResponse.json(),
]);

return {
city: `${geocodingData.name}, ${geocodingData.country}`,
oneCallData,
airPollutionData,
};
};

export default async function handler(req, res) {
if (req.method === 'POST') {
const { latitude, longitude } = req.body;
try {
const { city, oneCallData, airPollutionData } = await fetchWeatherData(latitude, longitude);
res.status(200).json({ city, oneCallData, airPollutionData });
} catch (error) {
res.status(400).json({ error: error.message });
}
} else {
res.status(404).send('');
}
}
82 changes: 41 additions & 41 deletions src/pages/api/search.js
Original file line number Diff line number Diff line change
@@ -1,41 +1,41 @@
const fetchWeatherData = async (ville) => {
const key = process.env.API_KEY;
const geocodingResponse = await fetch(`https://api.openweathermap.org/geo/1.0/direct?q=${ville}&limit=1&appid=${key}`);
if (geocodingResponse.status === 404) {
throw new Error('Geocoding API returned 404');
}
const [geocodingData] = await geocodingResponse.json();
const latitude = geocodingData.lat;
const longitude = geocodingData.lon;
const [oneCallResponse, airPollutionResponse] = await Promise.all([
fetch(`https://api.openweathermap.org/data/2.5/onecall?lat=${latitude}&lon=${longitude}&appid=${key}&units=metric&exclude=minutely`),
fetch(`https://api.openweathermap.org/data/2.5/air_pollution?lat=${latitude}&lon=${longitude}&appid=${key}`),
]);
if (oneCallResponse.status !== 200) {
throw new Error('Unexpected error');
}
const [oneCallData, airPollutionData] = await Promise.all([
oneCallResponse.json(),
airPollutionResponse.json(),
]);

return {
city: `${geocodingData.name}, ${geocodingData.country}`,
oneCallData,
airPollutionData,
};
};

export default async function handler(req, res) {
if (req.method === 'POST') {
const { ville } = req.body;
try {
const { city, oneCallData, airPollutionData } = await fetchWeatherData(ville);
res.status(200).json({ city, oneCallData, airPollutionData });
} catch (error) {
res.status(400).json({ error: error.message });
}
} else {
res.status(404).send('');
}
}
const fetchWeatherData = async (ville) => {
const key = process.env.API_KEY;
const geocodingResponse = await fetch(`https://api.openweathermap.org/geo/1.0/direct?q=${ville}&limit=1&appid=${key}`);
if (geocodingResponse.status === 404) {
throw new Error('Geocoding API returned 404');
}
const [geocodingData] = await geocodingResponse.json();
const latitude = geocodingData.lat;
const longitude = geocodingData.lon;
const [oneCallResponse, airPollutionResponse] = await Promise.all([
fetch(`https://api.openweathermap.org/data/2.5/onecall?lat=${latitude}&lon=${longitude}&appid=${key}&units=metric&exclude=minutely`),
fetch(`https://api.openweathermap.org/data/2.5/air_pollution?lat=${latitude}&lon=${longitude}&appid=${key}`),
]);
if (oneCallResponse.status !== 200) {
throw new Error('Unexpected error');
}
const [oneCallData, airPollutionData] = await Promise.all([
oneCallResponse.json(),
airPollutionResponse.json(),
]);

return {
city: `${geocodingData.name}, ${geocodingData.country}`,
oneCallData,
airPollutionData,
};
};

export default async function handler(req, res) {
if (req.method === 'POST') {
const { ville } = req.body;
try {
const { city, oneCallData, airPollutionData } = await fetchWeatherData(ville);
res.status(200).json({ city, oneCallData, airPollutionData });
} catch (error) {
res.status(400).json({ error: error.message });
}
} else {
res.status(404).send('');
}
}
Loading

1 comment on commit 9972b57

@vercel
Copy link

@vercel vercel bot commented on 9972b57 Jul 11, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Successfully deployed to the following URLs:

meteo – ./

meteo-leoseguin.vercel.app
meteo-git-main-leoseguin.vercel.app

Please sign in to comment.