Yfaite commited on
Commit
6cb7dfc
·
verified ·
1 Parent(s): 69b6726

I can't find cities

Browse files
Files changed (2) hide show
  1. README.md +9 -5
  2. index.html +241 -18
README.md CHANGED
@@ -1,10 +1,14 @@
1
  ---
2
- title: Undefined
3
- emoji: 👀
4
- colorFrom: green
5
- colorTo: blue
6
  sdk: static
7
  pinned: false
 
 
8
  ---
9
 
10
- Check out the configuration reference at https://huggingface.co/docs/hub/spaces-config-reference
 
 
 
1
  ---
2
+ title: undefined
3
+ colorFrom: blue
4
+ colorTo: green
5
+ emoji: 🐳
6
  sdk: static
7
  pinned: false
8
+ tags:
9
+ - deepsite-v3
10
  ---
11
 
12
+ # Welcome to your new DeepSite project!
13
+ This project was created with [DeepSite](https://deepsite.hf.co).
14
+
index.html CHANGED
@@ -1,19 +1,242 @@
1
- <!doctype html>
2
- <html>
3
- <head>
4
- <meta charset="utf-8" />
5
- <meta name="viewport" content="width=device-width" />
6
- <title>My static Space</title>
7
- <link rel="stylesheet" href="style.css" />
8
- </head>
9
- <body>
10
- <div class="card">
11
- <h1>Welcome to your static Space!</h1>
12
- <p>You can modify this app directly by editing <i>index.html</i> in the Files and versions tab.</p>
13
- <p>
14
- Also don't forget to check the
15
- <a href="https://huggingface.co/docs/hub/spaces" target="_blank">Spaces documentation</a>.
16
- </p>
17
- </div>
18
- </body>
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
19
  </html>
 
1
+ <!DOCTYPE html>
2
+ <html lang="en">
3
+ <head>
4
+ <meta charset="UTF-8">
5
+ <meta name="viewport" content="width=device-width, initial-scale=1.0">
6
+ <title>Cloudy With a Chance of Data</title>
7
+ <script src="https://cdn.tailwindcss.com"></script>
8
+ <script src="https://unpkg.com/feather-icons"></script>
9
+ <script src="https://cdn.jsdelivr.net/npm/feather-icons/dist/feather.min.js"></script>
10
+ <style>
11
+ @import url('https://fonts.googleapis.com/css2?family=Poppins:wght@300;400;500;600;700&display=swap');
12
+ body {
13
+ font-family: 'Poppins', sans-serif;
14
+ background: linear-gradient(135deg, #f5f7fa 0%, #c3cfe2 100%);
15
+ min-height: 100vh;
16
+ }
17
+ .weather-card {
18
+ backdrop-filter: blur(10px);
19
+ background: rgba(255, 255, 255, 0.2);
20
+ border-radius: 20px;
21
+ box-shadow: 0 8px 32px 0 rgba(31, 38, 135, 0.1);
22
+ border: 1px solid rgba(255, 255, 255, 0.18);
23
+ }
24
+ .search-btn {
25
+ transition: all 0.3s ease;
26
+ }
27
+ .search-btn:hover {
28
+ transform: translateY(-2px);
29
+ box-shadow: 0 4px 8px rgba(0, 0, 0, 0.1);
30
+ }
31
+ .forecast-item {
32
+ transition: all 0.3s ease;
33
+ }
34
+ .forecast-item:hover {
35
+ transform: translateY(-5px);
36
+ box-shadow: 0 8px 16px rgba(0, 0, 0, 0.1);
37
+ }
38
+ </style>
39
+ </head>
40
+ <body class="py-8 px-4">
41
+ <div class="max-w-4xl mx-auto">
42
+ <!-- Header -->
43
+ <header class="text-center mb-8">
44
+ <h1 class="text-4xl font-bold text-gray-800 mb-2">Cloudy With a Chance of Data</h1>
45
+ <p class="text-gray-600">Your personal weather oracle</p>
46
+ </header>
47
+
48
+ <!-- Search Bar -->
49
+ <div class="flex mb-8 justify-center">
50
+ <div class="relative w-full max-w-md">
51
+ <input
52
+ type="text"
53
+ id="location-input"
54
+ placeholder="Enter city name..."
55
+ class="w-full px-6 py-3 rounded-full border-0 shadow-md focus:outline-none focus:ring-2 focus:ring-blue-400"
56
+ >
57
+ <button
58
+ id="search-btn"
59
+ class="absolute right-2 top-1/2 transform -translate-y-1/2 bg-blue-500 hover:bg-blue-600 text-white p-2 rounded-full search-btn"
60
+ >
61
+ <i data-feather="search"></i>
62
+ </button>
63
+ </div>
64
+ </div>
65
+
66
+ <!-- Current Weather -->
67
+ <div id="current-weather" class="weather-card p-6 mb-8 text-center hidden">
68
+ <div class="flex justify-between items-center mb-4">
69
+ <div class="text-left">
70
+ <h2 id="location" class="text-2xl font-bold text-gray-800">New York, US</h2>
71
+ <p id="date" class="text-gray-600">Friday, 15 October</p>
72
+ </div>
73
+ <div id="weather-icon" class="w-20 h-20">
74
+ <!-- Weather icon will be inserted here -->
75
+ </div>
76
+ </div>
77
+ <div class="flex justify-around items-center">
78
+ <div>
79
+ <p id="temp" class="text-5xl font-bold text-gray-800">22°C</p>
80
+ <p id="weather-desc" class="text-gray-600">Partly Cloudy</p>
81
+ </div>
82
+ <div class="grid grid-cols-2 gap-4 text-sm">
83
+ <div class="flex items-center">
84
+ <i data-feather="wind" class="mr-2 text-blue-500"></i>
85
+ <span id="wind-speed">5 km/h</span>
86
+ </div>
87
+ <div class="flex items-center">
88
+ <i data-feather="droplet" class="mr-2 text-blue-500"></i>
89
+ <span id="humidity">65%</span>
90
+ </div>
91
+ <div class="flex items-center">
92
+ <i data-feather="compass" class="mr-2 text-blue-500"></i>
93
+ <span id="pressure">1012 hPa</span>
94
+ </div>
95
+ <div class="flex items-center">
96
+ <i data-feather="eye" class="mr-2 text-blue-500"></i>
97
+ <span id="visibility">10 km</span>
98
+ </div>
99
+ </div>
100
+ </div>
101
+ </div>
102
+
103
+ <!-- Forecast -->
104
+ <div id="forecast-container" class="hidden">
105
+ <h2 class="text-xl font-semibold text-gray-800 mb-4">5-Day Forecast</h2>
106
+ <div id="forecast" class="grid grid-cols-1 sm:grid-cols-2 md:grid-cols-3 lg:grid-cols-5 gap-4">
107
+ <!-- Forecast items will be inserted here -->
108
+ </div>
109
+ </div>
110
+
111
+ <!-- Loading State -->
112
+ <div id="loading" class="text-center hidden">
113
+ <div class="inline-block animate-spin rounded-full h-8 w-8 border-t-2 border-b-2 border-blue-500 mb-2"></div>
114
+ <p>Fetching weather data...</p>
115
+ </div>
116
+
117
+ <!-- Error State -->
118
+ <div id="error" class="text-center hidden">
119
+ <i data-feather="alert-circle" class="text-red-500 w-12 h-12 mx-auto mb-2"></i>
120
+ <p id="error-message" class="text-red-500">Location not found. Please try another city.</p>
121
+ <div class="mt-4 text-sm text-gray-600">
122
+ <p>Search tips:</p>
123
+ <ul class="list-disc list-inside">
124
+ <li>Check your spelling</li>
125
+ <li>Try a nearby major city</li>
126
+ <li>Include country code (e.g. "Paris, FR")</li>
127
+ </ul>
128
+ </div>
129
+ </div>
130
+ </div>
131
+
132
+ <script>
133
+ feather.replace();
134
+
135
+ document.getElementById('search-btn').addEventListener('click', fetchWeather);
136
+ document.getElementById('location-input').addEventListener('keypress', function(e) {
137
+ if (e.key === 'Enter') {
138
+ fetchWeather();
139
+ }
140
+ });
141
+
142
+ async function fetchWeather() {
143
+ const location = document.getElementById('location-input').value.trim();
144
+ if (!location) return;
145
+
146
+ // Show loading state
147
+ document.getElementById('loading').classList.remove('hidden');
148
+ document.getElementById('current-weather').classList.add('hidden');
149
+ document.getElementById('forecast-container').classList.add('hidden');
150
+ document.getElementById('error').classList.add('hidden');
151
+ try {
152
+ // Fetch current weather
153
+ const currentWeatherResponse = await fetch(`https://api.openweathermap.org/data/2.5/weather?q=${location}&units=metric&appid=YOUR_API_KEY`);
154
+
155
+ if (!currentWeatherResponse.ok) {
156
+ if (currentWeatherResponse.status === 404) {
157
+ throw new Error('City not found. Try a different spelling or nearby location.');
158
+ } else if (currentWeatherResponse.status === 401) {
159
+ throw new Error('API issue. Please try again later.');
160
+ } else {
161
+ throw new Error(`Error: ${currentWeatherResponse.statusText}`);
162
+ }
163
+ }
164
+
165
+ const currentWeatherData = await currentWeatherResponse.json();
166
+
167
+ // Fetch forecast
168
+ const forecastResponse = await fetch(`https://api.openweathermap.org/data/2.5/forecast?q=${location}&units=metric&appid=YOUR_API_KEY`);
169
+ if (!forecastResponse.ok) throw new Error('Forecast data unavailable');
170
+ const forecastData = await forecastResponse.json();
171
+
172
+ // Validate we got data for the city
173
+ if (currentWeatherData.cod !== 200 || forecastData.cod !== "200") {
174
+ throw new Error('Incomplete weather data received');
175
+ }
176
+ // Update UI with current weather
177
+ updateCurrentWeather(currentWeatherData);
178
+
179
+ // Update UI with forecast
180
+ updateForecast(forecastData);
181
+
182
+ // Hide loading, show weather
183
+ document.getElementById('loading').classList.add('hidden');
184
+ document.getElementById('current-weather').classList.remove('hidden');
185
+ document.getElementById('forecast-container').classList.remove('hidden');
186
+ } catch (error) {
187
+ console.error('Error fetching weather:', error);
188
+ document.getElementById('loading').classList.add('hidden');
189
+ document.getElementById('error').classList.remove('hidden');
190
+ document.getElementById('error-message').textContent = error.message;
191
+ }
192
+ }
193
+
194
+ function updateCurrentWeather(data) {
195
+ document.getElementById('location').textContent = `${data.name}, ${data.sys.country}`;
196
+ document.getElementById('date').textContent = new Date(data.dt * 1000).toLocaleDateString('en-US', { weekday: 'long', year: 'numeric', month: 'long', day: 'numeric' });
197
+ document.getElementById('temp').textContent = `${Math.round(data.main.temp)}°C`;
198
+ document.getElementById('weather-desc').textContent = data.weather[0].description;
199
+ document.getElementById('wind-speed').textContent = `${data.wind.speed} km/h`;
200
+ document.getElementById('humidity').textContent = `${data.main.humidity}%`;
201
+ document.getElementById('pressure').textContent = `${data.main.pressure} hPa`;
202
+ document.getElementById('visibility').textContent = `${data.visibility / 1000} km`;
203
+
204
+ // Update weather icon
205
+ const weatherIcon = document.getElementById('weather-icon');
206
+ weatherIcon.innerHTML = `<img src="https://openweathermap.org/img/wn/${data.weather[0].icon}@2x.png" alt="${data.weather[0].description}">`;
207
+ }
208
+
209
+ function updateForecast(data) {
210
+ const forecastContainer = document.getElementById('forecast');
211
+ forecastContainer.innerHTML = '';
212
+
213
+ // Filter to get one forecast per day (every 24 hours)
214
+ const dailyForecasts = data.list.filter((forecast, index) => index % 8 === 0);
215
+
216
+ dailyForecasts.forEach(forecast => {
217
+ const date = new Date(forecast.dt * 1000);
218
+ const dayName = date.toLocaleDateString('en-US', { weekday: 'short' });
219
+
220
+ const forecastItem = document.createElement('div');
221
+ forecastItem.className = 'weather-card p-4 text-center forecast-item';
222
+ forecastItem.innerHTML = `
223
+ <p class="font-medium text-gray-800">${dayName}</p>
224
+ <p class="text-sm text-gray-600 mb-2">${date.toLocaleDateString('en-US', { month: 'short', day: 'numeric' })}</p>
225
+ <img src="https://openweathermap.org/img/wn/${forecast.weather[0].icon}.png" alt="${forecast.weather[0].description}" class="mx-auto w-16 h-16">
226
+ <p class="text-gray-600 text-sm capitalize">${forecast.weather[0].description}</p>
227
+ <div class="flex justify-center gap-4 mt-2">
228
+ <span class="font-bold text-gray-800">${Math.round(forecast.main.temp_max)}°</span>
229
+ <span class="text-gray-600">${Math.round(forecast.main.temp_min)}°</span>
230
+ </div>
231
+ `;
232
+ forecastContainer.appendChild(forecastItem);
233
+ });
234
+ }
235
+ // Example: Load default weather for London on page load (more reliable)
236
+ window.addEventListener('load', () => {
237
+ document.getElementById('location-input').value = 'London, UK';
238
+ fetchWeather();
239
+ });
240
+ </script>
241
+ </body>
242
  </html>