下雨啦提醒

这段代码是一个简单的天气预报应用程序。它使用和风天气 API 获取特定经纬度坐标位置的未来两小时降雨情况,并通过控制台输出相应的信息。

如果降雨概率大于 0,程序将调用 fetchData 函数,该函数将使用自定义的 API(通过 URL)向指定接收器发送有关降雨情况的信息。在此过程中,information 参数被传递给 fetchData 函数作为数据的一部分。

const axios = require('axios');
const location = '000.00,000.00'; // 请替换为您所在的经纬度坐标先经度后纬度
const key = '697ceb4d6d5641a893ec6******'; //请替换为您的和风天气 API Key
const url = `https://devapi.qweather.com/v7/minutely/5m?location=${location}&key=${key}`;
axios.get(url)
  .then((response) => {
    const data = response.data;
    if (data.summary === "未来两小时无降水") {
      console.log("现在不需要带伞" + data.summary + "现在无需推送");
    } else {
      console.log("建议带上雨伞" + data.summary + "现在赶紧推送" );
      const information = data.summary;
      fetchData(information); // 将 information 作为参数传递给 fetchData 函数
    }
  })
  .catch((error) => {
    console.error(error);
  });

//这里使用bark推送  url和用户id自行替换

async function fetchData(information) { // 将 information 作为参数接收
  const title = '下雨啦';

  const config = {
    method: 'get',
    url: `https://url/用户id/${title}/${information}?icon=https://cdn.pixabay.com/photo/2016/03/31/18/14/icon-1294224_640.png`,
    headers: {}
  };

  try {
    const response = await axios(config);
    console.log(JSON.stringify(response.data));
  } catch (error) {
    console.log(error);
  }
}

0 */30 * * * *每30分钟运行一次

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值