Intermediate 3-4 hours · 2 APIs

Build a Weather-Based Playlist Matcher

Get Spotify playlist recommendations based on the current weather. Sunny day? Upbeat tracks. Rainy afternoon? Chill vibes.

APIs Used

Data Flow

USER User enters their city name API Fetch current weather conditions via OpenWeatherMap PROCESS Map weather to mood keyword API Search playlists matching mood via Spotify OUTPUT Display playlist recommendations with Spotify links
User Action
API Call
Transform
Output

How It Works

1

Fetch current weather conditions for the user's city

2

Map weather condition to a mood keyword (sunny -> happy, rain -> chill, snow -> cozy)

3

Search Spotify for playlists matching the mood keyword

4

Display a list of matching playlists with links to open in Spotify

Code Outline

Pseudocode / JavaScript
// 1. Get current weather
const weatherRes = await fetch(
  'https://api.openweathermap.org/data/2.5/weather?q=London&appid=YOUR_API_KEY'
);
const { weather } = await weatherRes.json();
const condition = weather[0].main; // 'Rain', 'Clear', 'Snow', etc.

// 2. Map weather to mood
const moodMap = { Clear: 'happy', Rain: 'chill', Snow: 'cozy', Clouds: 'indie', Thunderstorm: 'intense' };
const mood = moodMap[condition] || 'relaxing';

// 3. Get Spotify access token (Client Credentials flow)
const tokenRes = await fetch('https://accounts.spotify.com/api/token', {
  method: 'POST',
  headers: { 'Content-Type': 'application/x-www-form-urlencoded' },
  body: 'grant_type=client_credentials&client_id=YOUR_ID&client_secret=YOUR_SECRET'
});
const { access_token } = await tokenRes.json();

// 4. Search for playlists by mood
const playlistRes = await fetch(
  `https://api.spotify.com/v1/search?q=${mood}&type=playlist&limit=5`,
  { headers: { 'Authorization': `Bearer ${access_token}` } }
);
const { playlists } = await playlistRes.json();
playlists.items.forEach(p => console.log(`${p.name}: ${p.external_urls.spotify}`));

Note: These recipes are AI-generated suggestions based on API capabilities. Actual implementation may vary. Always refer to official API documentation for the latest specifications.