feat(provider): add fission_mq_trigger, fission_cron_trigger, fission_iot_device + weather-demo example
This commit is contained in:
@@ -0,0 +1,45 @@
|
||||
import os
|
||||
import json
|
||||
import psycopg2
|
||||
|
||||
|
||||
def main(event, context):
|
||||
pg_dsn = os.environ["PG_DSN"]
|
||||
|
||||
# Извлекаем тело сообщения из SQS (POST от sqs-consumer)
|
||||
body = getattr(event, "body", event)
|
||||
if isinstance(body, (bytes, bytearray)):
|
||||
body = body.decode("utf-8")
|
||||
if isinstance(body, str):
|
||||
data = json.loads(body)
|
||||
else:
|
||||
data = body
|
||||
|
||||
conn = psycopg2.connect(pg_dsn)
|
||||
try:
|
||||
cur = conn.cursor()
|
||||
cur.execute(
|
||||
"""
|
||||
INSERT INTO weather_metrics
|
||||
(city, country, temperature, feels_like, humidity,
|
||||
pressure, wind_speed, description, recorded_at)
|
||||
VALUES (%s, %s, %s, %s, %s, %s, %s, %s, to_timestamp(%s))
|
||||
""",
|
||||
(
|
||||
data["city"],
|
||||
data["country"],
|
||||
data["temperature"],
|
||||
data["feels_like"],
|
||||
data["humidity"],
|
||||
data["pressure"],
|
||||
data["wind_speed"],
|
||||
data["description"],
|
||||
data["owm_timestamp"],
|
||||
),
|
||||
)
|
||||
conn.commit()
|
||||
cur.close()
|
||||
finally:
|
||||
conn.close()
|
||||
|
||||
return {"status": "ok", "city": data["city"], "temp": data["temperature"]}
|
||||
Reference in New Issue
Block a user