Auto-sync: 2026-02-28 05:00:03
This commit is contained in:
10
workflows/f/weather/weather_sync.schedule.yaml
Normal file
10
workflows/f/weather/weather_sync.schedule.yaml
Normal file
@@ -0,0 +1,10 @@
|
||||
args: {}
|
||||
cron_version: v2
|
||||
email: akiracraftwork@gmail.com
|
||||
enabled: true
|
||||
is_flow: true
|
||||
no_flow_overlap: false
|
||||
schedule: 0 0 6 * * *
|
||||
script_path: f/weather/weather_sync
|
||||
timezone: Asia/Tokyo
|
||||
ws_error_handler_muted: false
|
||||
18
workflows/f/weather/weather_sync__flow/flow.yaml
Normal file
18
workflows/f/weather/weather_sync__flow/flow.yaml
Normal file
@@ -0,0 +1,18 @@
|
||||
summary: Weather Sync - 気象データ日次同期
|
||||
description: Open-Meteo から昨日の気象データを取得し、Keinasystem DB に保存する。毎朝6時実行。
|
||||
value:
|
||||
modules:
|
||||
- id: a
|
||||
summary: 気象データ取得・同期
|
||||
value:
|
||||
type: rawscript
|
||||
content: '!inline 気象データ取得・同期.py'
|
||||
input_transforms: {}
|
||||
lock: '!inline 気象データ取得・同期.lock'
|
||||
language: python3
|
||||
schema:
|
||||
$schema: 'https://json-schema.org/draft/2020-12/schema'
|
||||
type: object
|
||||
order: []
|
||||
properties: {}
|
||||
required: []
|
||||
12
workflows/f/weather/weather_sync__flow/気象データ取得・同期.lock
Normal file
12
workflows/f/weather/weather_sync__flow/気象データ取得・同期.lock
Normal file
@@ -0,0 +1,12 @@
|
||||
# py: 3.12
|
||||
anyio==4.12.1
|
||||
certifi==2026.2.25
|
||||
charset-normalizer==3.4.4
|
||||
h11==0.16.0
|
||||
httpcore==1.0.9
|
||||
httpx==0.28.1
|
||||
idna==3.11
|
||||
requests==2.32.5
|
||||
typing-extensions==4.15.0
|
||||
urllib3==2.6.3
|
||||
wmill==1.646.0
|
||||
72
workflows/f/weather/weather_sync__flow/気象データ取得・同期.py
Normal file
72
workflows/f/weather/weather_sync__flow/気象データ取得・同期.py
Normal file
@@ -0,0 +1,72 @@
|
||||
import wmill
|
||||
import requests
|
||||
import datetime
|
||||
|
||||
LATITUDE = 33.213
|
||||
LONGITUDE = 133.133
|
||||
TIMEZONE = "Asia/Tokyo"
|
||||
|
||||
OPEN_METEO_URL = "https://archive-api.open-meteo.com/v1/archive"
|
||||
DAILY_VARS = [
|
||||
"temperature_2m_mean",
|
||||
"temperature_2m_max",
|
||||
"temperature_2m_min",
|
||||
"sunshine_duration",
|
||||
"precipitation_sum",
|
||||
"wind_speed_10m_max",
|
||||
"surface_pressure_min",
|
||||
]
|
||||
|
||||
|
||||
def main():
|
||||
api_key = wmill.get_variable("u/admin/KEINASYSTEM_API_KEY")
|
||||
base_url = wmill.get_variable("u/admin/KEINASYSTEM_API_URL").rstrip("/")
|
||||
sync_url = f"{base_url}/api/weather/sync/"
|
||||
|
||||
yesterday = (datetime.date.today() - datetime.timedelta(days=1)).isoformat()
|
||||
print(f"Fetching weather data for {yesterday} ...")
|
||||
|
||||
params = {
|
||||
"latitude": LATITUDE,
|
||||
"longitude": LONGITUDE,
|
||||
"start_date": yesterday,
|
||||
"end_date": yesterday,
|
||||
"daily": DAILY_VARS,
|
||||
"timezone": TIMEZONE,
|
||||
}
|
||||
resp = requests.get(OPEN_METEO_URL, params=params, timeout=30)
|
||||
if resp.status_code != 200:
|
||||
raise Exception(f"Open-Meteo API error: {resp.status_code} {resp.text[:300]}")
|
||||
|
||||
daily = resp.json().get("daily", {})
|
||||
dates = daily.get("time", [])
|
||||
if not dates:
|
||||
print("No data returned from Open-Meteo.")
|
||||
return {"status": "no_data"}
|
||||
|
||||
sunshine_raw = daily.get("sunshine_duration", [])
|
||||
records = []
|
||||
for i, d in enumerate(dates):
|
||||
sun_sec = sunshine_raw[i]
|
||||
records.append({
|
||||
"date": d,
|
||||
"temp_mean": daily["temperature_2m_mean"][i],
|
||||
"temp_max": daily["temperature_2m_max"][i],
|
||||
"temp_min": daily["temperature_2m_min"][i],
|
||||
"sunshine_h": round(sun_sec / 3600, 2) if sun_sec is not None else None,
|
||||
"precip_mm": daily["precipitation_sum"][i],
|
||||
"wind_max": daily["wind_speed_10m_max"][i],
|
||||
"pressure_min": daily["surface_pressure_min"][i],
|
||||
})
|
||||
|
||||
headers = {
|
||||
"X-API-Key": api_key,
|
||||
"Content-Type": "application/json",
|
||||
}
|
||||
post_resp = requests.post(sync_url, json=records, headers=headers, timeout=30)
|
||||
if post_resp.status_code not in (200, 201):
|
||||
raise Exception(f"Keinasystem sync error: {post_resp.status_code} {post_resp.text[:300]}")
|
||||
|
||||
result = post_resp.json()
|
||||
print(f"Sync complete: {result}")
|
||||
return result
|
||||
Reference in New Issue
Block a user