chore: initial Observable workspace with technical README
This commit is contained in:
47
docs/data/ca-earthquakes-last365d.json.js
Normal file
47
docs/data/ca-earthquakes-last365d.json.js
Normal file
@@ -0,0 +1,47 @@
|
||||
const now = new Date();
|
||||
const start = new Date(now.getTime() - 365 * 24 * 60 * 60 * 1000);
|
||||
|
||||
const params = new URLSearchParams({
|
||||
format: "geojson",
|
||||
starttime: start.toISOString(),
|
||||
endtime: now.toISOString(),
|
||||
minmagnitude: "2.5",
|
||||
minlatitude: "32",
|
||||
maxlatitude: "42.5",
|
||||
minlongitude: "-125",
|
||||
maxlongitude: "-114",
|
||||
orderby: "time-asc",
|
||||
});
|
||||
|
||||
const url = `https://earthquake.usgs.gov/fdsnws/event/1/query?${params}`;
|
||||
const response = await fetch(url);
|
||||
if (!response.ok) {
|
||||
throw new Error(`USGS request failed: ${response.status}`);
|
||||
}
|
||||
|
||||
const payload = await response.json();
|
||||
const features = Array.isArray(payload.features) ? payload.features : [];
|
||||
|
||||
const quakes = features
|
||||
.map((feature) => {
|
||||
const [longitude, latitude] = feature.geometry?.coordinates ?? [];
|
||||
const mag = Number(feature.properties?.mag);
|
||||
if (
|
||||
!Number.isFinite(latitude) ||
|
||||
!Number.isFinite(longitude) ||
|
||||
!Number.isFinite(mag)
|
||||
) {
|
||||
return null;
|
||||
}
|
||||
return {
|
||||
id: feature.id,
|
||||
latitude,
|
||||
longitude,
|
||||
mag,
|
||||
place: feature.properties?.place ?? "",
|
||||
time: feature.properties?.time ?? null,
|
||||
};
|
||||
})
|
||||
.filter(Boolean);
|
||||
|
||||
process.stdout.write(JSON.stringify(quakes));
|
||||
Reference in New Issue
Block a user