Created
September 19, 2024 01:21
-
-
Save smzn/5975f98124ba15a2f0e52c07dafe1281 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import requests | |
import json | |
# APIリクエストのURL | |
url_w = "https://api.open-meteo.com/v1/forecast?latitude=34.9768466&longitude=138.3803926&timezone=Asia/Tokyo¤t_weather=true" | |
# リクエストを送信 | |
response_w = requests.get(url_w) | |
# レスポンスをJSON形式で整形 | |
weather_data = response_w.json() | |
# 必要な天気情報を抽出 | |
current_weather = weather_data['current_weather'] | |
temperature = current_weather['temperature'] | |
windspeed = current_weather['windspeed'] | |
winddirection = current_weather['winddirection'] | |
weather_time = current_weather['time'] | |
# 天気情報をメッセージとしてフォーマット | |
message_text = ( | |
f"【静岡の現在の天気】\n" | |
f"日時: {weather_time}\n" | |
f"気温: {temperature}°C\n" | |
f"風速: {windspeed} km/h\n" | |
f"風向き: {winddirection}°" | |
) | |
url = "https://webexapis.com/v1/messages" | |
payload = json.dumps({ | |
"roomId": "Y2lzY29zcGFyazovL3VzL1JPT00vYTliNjRjZDAtZWViOC0xMWU4LWJmZTItZDliYWRmMDgxNTcz", | |
"text": message_text | |
}) | |
headers = { | |
'Content-Type': 'application/json', | |
'Authorization': 'Bearer ZDBhNmFiN2EtMTEyYS00ZTYzLTljODAtNjJhNmZiMGI0NzY0ZjEwNDdiMjEtYmEx_P0A1_8e922505-3178-4b77-8fc7-9f393761f81e' | |
} | |
response = requests.request("POST", url, headers=headers, data=payload) | |
print(response.text) | |
def lambda_handler(event, context): | |
# TODO implement | |
return { | |
'statusCode': 200, | |
'body': json.dumps('Hello from Lambda!') | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment