-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.html
429 lines (372 loc) · 13.4 KB
/
index.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Celeste</title>
<link rel="icon" href="data:image/svg+xml,<svg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 100 100'><circle cx='50' cy='50' r='40' fill='%23000000'/><circle cx='50' cy='50' r='35' fill='%23333333'/><circle cx='35' cy='40' r='5' fill='white' opacity='0.8'/><circle cx='60' cy='35' r='3' fill='white' opacity='0.6'/><circle cx='70' cy='50' r='2' fill='white' opacity='0.5'/></svg>">
<style>
* {
margin: 0;
padding: 0;
box-sizing: border-box;
}
@font-face {
font-family: 'Satoshi-Regular';
src: url('Satoshi-Regular.woff2') format('woff2'),
url('Satoshi-Regular.woff') format('woff'),
url('Satoshi-Regular.ttf') format('truetype');
font-weight: 400;
font-display: swap;
font-style: normal;
}
@font-face {
font-family: 'Satoshi-Italic';
src: url('Satoshi-Italic.woff2') format('woff2'),
url('Satoshi-Italic.woff') format('woff'),
url('Satoshi-Italic.ttf') format('truetype');
font-weight: 400;
font-display: swap;
font-style: italic;
}
@font-face {
font-family: 'Satoshi-Medium';
src: url('Satoshi-Medium.woff2') format('woff2'),
url('Satoshi-Medium.woff') format('woff'),
url('Satoshi-Medium.ttf') format('truetype');
font-weight: 500;
font-display: swap;
font-style: normal;
}
@font-face {
font-family: 'Satoshi-Bold';
src: url('Satoshi-Bold.woff2') format('woff2'),
url('Satoshi-Bold.woff') format('woff'),
url('Satoshi-Bold.ttf') format('truetype');
font-weight: 500;
font-display: swap;
font-style: normal;
}
:root {
--background-color: #ffffff;
--text-color: #000000;
--border-color: #e5e7eb;
--hover-color: #f3f4f6;
--secondary-text: #4b5563;
--muted-text: #6B7280;
--skeleton-color: #ddd;
}
@media (prefers-color-scheme: dark) {
:root {
--background-color: #1a1a1a;
--text-color: #ffffff;
--border-color: #2e3138;
--hover-color: #2a2d33;
--secondary-text: #9ba3af;
--muted-text: #8c96a3;
--skeleton-color: #333;
}
}
body, html {
font-family: 'Satoshi-Regular', system-ui, -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
background-color: var(--background-color);
color: var(--text-color);
transition: background-color 0.3s, color 0.3s;
line-height: 1.4;
margin: 0;
padding: 0;
width: 100%;
height: 100%;
overflow: hidden;
position: relative;
}
.container {
display: flex;
flex-direction: column;
justify-content: center;
align-items: center;
height: 100vh;
padding: 20px;
box-sizing: border-box;
width: 100%;
}
.event-info {
width: 100%;
max-width: 900px;
padding: 20px;
}
.event-summary {
font-size: 32px;
line-height: 1.5;
font-weight: 400;
color: var(--text-color);
text-align: left;
width: 100%;
padding: 10px 0;
}
.event-summary .highlight {
text-decoration: underline;
font-family: 'Satoshi-Medium', system-ui, -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
font-weight: 500;
}
.loading {
width: 100%;
max-width: 900px;
padding: 20px;
}
.error {
padding: 20px;
max-width: 900px;
margin-bottom: 15px;
font-weight: 400;
font-size: 20px;
color: var(--text-color);
}
/* Skeleton loader styles */
.skeleton {
position: relative;
background-color: var(--skeleton-color);
border-radius: 3px;
animation: pulse 1.5s infinite;
overflow: hidden;
}
.skeleton-line1 {
width: 100%;
height: 32px;
margin-bottom: 15px;
}
.skeleton-line2 {
width: 95%;
height: 32px;
margin-bottom: 15px;
}
.skeleton-line3 {
width: 90%;
height: 32px;
}
@keyframes pulse {
0% {
opacity: 0.6;
}
50% {
opacity: 0.3;
}
100% {
opacity: 0.6;
}
}
/* Fade in blur animation */
.fade-in-blur {
animation: fadeInBlur 0.8s ease-out forwards;
filter: blur(8px);
opacity: 0;
}
@keyframes fadeInBlur {
0% {
filter: blur(8px);
opacity: 0;
}
100% {
filter: blur(0);
opacity: 1;
}
}
@media (min-width: 1440px) {
.event-info, .loading, .error {
max-width: 1200px;
}
.event-summary {
font-size: 36px;
}
}
</style>
</head>
<body>
<div class="container">
<div id="loading" class="loading">
<div class="skeleton skeleton-line1"></div>
<div class="skeleton skeleton-line2"></div>
<div class="skeleton skeleton-line3"></div>
</div>
<div id="error-message" class="error" style="display: none;"></div>
<div id="event-info" class="event-info" style="display: none;">
<div id="event-summary" class="event-summary fade-in-blur"></div>
</div>
</div>
<script>
const TAVILY_API_KEY = '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';
const GEMINI_API_KEY = 'AIzaSyCbODz7UC5WuOdydsbBT_KHwtUOfQnIAAc';
document.addEventListener('DOMContentLoaded', function() {
const loadingIndicator = document.getElementById('loading');
const errorMessage = document.getElementById('error-message');
const eventInfo = document.getElementById('event-info');
const eventSummary = document.getElementById('event-summary');
fetchCelestialEvents();
async function fetchCelestialEvents() {
try {
const events = await searchSpecificEvents();
if (!events || events.length === 0) {
throw new Error("No events found");
}
const summary = await generateEventSummary(events[0]);
displayEventSummary(summary);
} catch (error) {
console.error("Error:", error);
showError("Unable to find celestial events at this time. Please try again later.");
}
}
async function searchSpecificEvents() {
const currentDate = new Date();
const monthNames = ["January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December"];
const currentMonth = monthNames[currentDate.getMonth()];
const nextMonth = monthNames[(currentDate.getMonth() + 1) % 12];
const query = `upcoming specific celestial events in ${currentMonth} and ${nextMonth} 2025 including meteor showers, eclipses, planet conjunctions, supermoons, visible planets`;
try {
const response = await fetch('https://api.tavily.com/search', {
method: 'POST',
headers: {
'Content-Type': 'application/json',
'Authorization': `Bearer ${TAVILY_API_KEY}`
},
body: JSON.stringify({
query: query,
search_depth: 'advanced',
include_domains: ['space.com', 'skyandtelescope.org', 'earthsky.org', 'nasa.gov', 'timeanddate.com', 'almanac.com'],
max_results: 3
})
});
if (!response.ok) {
throw new Error(`Tavily API error: ${response.status}`);
}
const data = await response.json();
console.log("Search results:", data);
return extractEventsFromSearchResults(data.results || []);
} catch (error) {
console.error("Search error:", error);
throw error;
}
}
async function extractEventsFromSearchResults(searchResults) {
if (!searchResults || searchResults.length === 0) {
return [];
}
const combinedContent = searchResults.map(result => {
return {
title: result.title,
content: result.content,
url: result.url
};
});
try {
const prompt = `
Extract the most significant upcoming celestial event from the following astronomy information.
Focus on finding a specific event with a date, like a meteor shower, eclipse, planet conjunction, etc.
Format your response as a JSON object with these properties:
{
"name": "Event name",
"date": "Specific date or date range",
"description": "Brief description of the event",
"viewingInfo": "Where in the sky to look, best time, etc."
}
ONLY extract ONE specific upcoming event with detailed information. Here's the astronomy content to analyze:
${JSON.stringify(combinedContent)}
`;
const response = await fetch('https://generativelanguage.googleapis.com/v1beta/models/gemini-1.5-flash-latest:generateContent?key=' + GEMINI_API_KEY, {
method: 'POST',
headers: {
'Content-Type': 'application/json'
},
body: JSON.stringify({
contents: [{
parts: [{
text: prompt
}]
}],
generationConfig: {
temperature: 0.2,
maxOutputTokens: 800
}
})
});
if (!response.ok) {
throw new Error(`Gemini API error: ${response.status}`);
}
const data = await response.json();
const resultText = data.candidates[0].content.parts[0].text;
const jsonMatch = resultText.match(/\{[\s\S]*\}/);
if (jsonMatch) {
try {
const eventData = JSON.parse(jsonMatch[0]);
console.log("Extracted event data:", eventData);
return [eventData];
} catch (jsonError) {
console.error("Error parsing JSON from Gemini response:", jsonError);
throw new Error("Failed to parse event data");
}
} else {
throw new Error("No valid event data found in Gemini response");
}
} catch (error) {
console.error("Error extracting events:", error);
throw error;
}
}
async function generateEventSummary(event) {
try {
const prompt = `
Create a single, conversational sentence about this upcoming celestial event:
${JSON.stringify(event)}
Format it like this example:
"Look up around <span class="highlight">March 13, 2025</span> for a beautiful sight: the <span class="highlight">Moon and Jupiter Conjunction</span> where the Moon will appear incredibly close to Jupiter, a dazzling celestial pairing visible from anywhere with clear skies."
Do NOT use line breaks. Make it sound natural and exciting.
Use language that matches the template, with highlight spans as shown in the example.
Include essential viewing details like when it happens, what makes it special, and where to look.
`;
const response = await fetch('https://generativelanguage.googleapis.com/v1beta/models/gemini-1.5-flash-latest:generateContent?key=' + GEMINI_API_KEY, {
method: 'POST',
headers: {
'Content-Type': 'application/json'
},
body: JSON.stringify({
contents: [{
parts: [{
text: prompt
}]
}],
generationConfig: {
temperature: 0.3,
maxOutputTokens: 400
}
})
});
if (!response.ok) {
throw new Error(`Gemini API error: ${response.status}`);
}
const data = await response.json();
return data.candidates[0].content.parts[0].text;
} catch (error) {
console.error("Error generating summary:", error);
throw error;
}
}
function displayEventSummary(summary) {
eventSummary.innerHTML = summary;
loadingIndicator.style.display = 'none';
eventInfo.style.display = 'block';
const animatedElements = document.querySelectorAll('.fade-in-blur');
animatedElements.forEach(element => {
element.style.animation = 'none';
element.offsetHeight;
element.style.animation = null;
});
}
function showError(message) {
errorMessage.textContent = message;
errorMessage.style.display = 'block';
loadingIndicator.style.display = 'none';
}
});
</script>
</body>
</html>
</html>