如何在Bash上获得户外温度?

时间:2014-02-27 23:13:01

标签: bash geolocation temperature

我需要在bash和python上编写一个脚本,它将使用地理定位方法从户外接收温度 我提醒说,当我积极使用Ubuntu时,我有一个片段或类似的东西。它来自某个地方的室外温度,风向,风速等。
我想如果存在一些这样的公共API,我的脚本会很棒。
我相信SO社区知道它。分享,请=)

1 个答案:

答案 0 :(得分:3)

结帐http://developer.yahoo.com/weather/

您的python脚本可能会:

  1. http://weather.yahooapis.com/forecastrss?w=2442047&u=f的接口,其中w=是您的WOEID
  2. 使用可用的python库解析XML
  3. 显示所需的输出
  4. 或(BASH):

    1. 通过bash(wget
    2. 下载xml
    3. 使用grep / awk / sed提取所需信息
    4. 在终端中显示
    5. *编辑:

      在bash中搞砸了它。这将提取温度。我相信你可以清理它。

      #!/bin/bash
      
      wget http://weather.yahooapis.com/forecastrss?w=2502265 -O test.xml > /dev/null 2>&1
      TEMP=$(grep "yweather:condition" test.xml | cut -d"=" -f4 | cut -d"\"" -f2)
      echo "Temperature: " $TEMP
      rm -rf test.xml
      

      在此处轻松计算您的WOEID:http://isithackday.com/geoplanet-explorer/