mirror of
https://github.com/kennethnym/aris.git
synced 2026-02-02 05:01:17 +00:00
Add WeatherKit data source package
Implements @aris/data-source-weatherkit for fetching weather data from Apple WeatherKit REST API. - WeatherKitDataSource class implementing DataSource interface - Feed items: current, hourly, daily, and alerts - Priority adjustment based on weather conditions and alert severity - Unit conversion (metric/imperial) - Response validation with arktype - Test fixtures from real API responses Co-authored-by: Ona <no-reply@ona.com>
This commit is contained in:
@@ -0,0 +1,60 @@
|
||||
import { fetchWeather } from "../src/weatherkit"
|
||||
|
||||
function loadEnv(): Record<string, string> {
|
||||
const content = require("fs").readFileSync(".env", "utf-8")
|
||||
const env: Record<string, string> = {}
|
||||
|
||||
for (const line of content.split("\n")) {
|
||||
const trimmed = line.trim()
|
||||
if (!trimmed || trimmed.startsWith("#")) continue
|
||||
|
||||
const eqIndex = trimmed.indexOf("=")
|
||||
if (eqIndex === -1) continue
|
||||
|
||||
const key = trimmed.slice(0, eqIndex)
|
||||
let value = trimmed.slice(eqIndex + 1)
|
||||
|
||||
if (value.startsWith('"') && value.endsWith('"')) {
|
||||
value = value.slice(1, -1)
|
||||
}
|
||||
|
||||
env[key] = value.replace(/\\n/g, "\n")
|
||||
}
|
||||
|
||||
return env
|
||||
}
|
||||
|
||||
const env = loadEnv()
|
||||
|
||||
const credentials = {
|
||||
privateKey: env.WEATHERKIT_PRIVATE_KEY!,
|
||||
keyId: env.WEATHERKIT_KEY_ID!,
|
||||
teamId: env.WEATHERKIT_TEAM_ID!,
|
||||
serviceId: env.WEATHERKIT_SERVICE_ID!,
|
||||
}
|
||||
|
||||
const locations = {
|
||||
sanFrancisco: { lat: 37.7749, lng: -122.4194 },
|
||||
}
|
||||
|
||||
async function main() {
|
||||
console.log("Fetching weather data for San Francisco...")
|
||||
|
||||
const response = await fetchWeather(
|
||||
{ credentials },
|
||||
{ lat: locations.sanFrancisco.lat, lng: locations.sanFrancisco.lng },
|
||||
)
|
||||
|
||||
const fixture = {
|
||||
generatedAt: new Date().toISOString(),
|
||||
location: locations.sanFrancisco,
|
||||
response,
|
||||
}
|
||||
|
||||
const output = JSON.stringify(fixture)
|
||||
await Bun.write("fixtures/san-francisco.json", output)
|
||||
|
||||
console.log("Fixture written to fixtures/san-francisco.json")
|
||||
}
|
||||
|
||||
main().catch(console.error)
|
||||
Reference in New Issue
Block a user