Get your conky location aware

2010-02-19-225826_188x44_scrot

Add this in your conkyrc

${exec curl -s "http://api.hostip.info" | xpath -e "//gml:featureMember/Hostip/gml:name/text()" -q} ${exec curl -s "http://api.hostip.info" | xpath -e "//gml:featureMember/Hostip//gml:coordinates/text()" -q}

Hostip is well known as a service provider of the geoclue framework. It translates IP address to geolocation information. The API we use will return a GML document like

<?xml version="1.0" encoding="ISO-8859-1" ?>
<hostipLookupResultSet version="1.0.1" xmlns:gml="http://www.opengis.net/gml" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="http://www.hostip.info/api/hostip-1.0.1.xsd">
 <gml:description>This is the Hostip Lookup Service</gml:description>
 <gml:name>hostip</gml:name>
 <gml:boundedBy>
  <gml:Null>inapplicable</gml:Null>
 </gml:boundedBy>
 <gml:featureMember>
  <hostip>
   <ip>58.212.88.212</ip>
   <gml:name>Nanjing</gml:name>
   <countryName>CHINA</countryName>
   <countryAbbrev>CN</countryAbbrev>
   <!-- Co-ordinates are available as lng,lat -->
   <ipLocation>
    <gml:pointProperty>
     <gml:Point srsName="http://www.opengis.net/gml/srs/epsg.xml#4326">
      <gml:coordinates>118.883,32.05</gml:coordinates>
     </gml:Point>
    </gml:pointProperty>
   </ipLocation>
  </hostip>
 </gml:featureMember>
</hostipLookupResultSet>

Because it uses ip to lookup your address, you cannot expect higher resolution and precision currently.

Using weather

Ubuntu仓库里有个weather-util包,可以用来查看天气信息。weather工具从weather.noaa.gov网站获得天气信息,对美国的城市可以直接用名字查询,其他国家只能使用id查询。id的规则和weather.com不太相同。

中国的天气站点id可以在这个页面上查到。比如南京ZSNJ,上海浦东ZSPD。使用weather工具查询:
weather -i ZSNJ

Current conditions at China (ZSNJ) 32-00N 118-48E 12M (ZSNJ)
Last updated Feb 18, 2010 – 08:00 AM EST / 2010.02.18 1300 UTC
Temperature: 35 F (2 C)
Relative Humidity: 59%
Wind: from the SSW (210 degrees) at 4 MPH (4 KT)

简化操作,可以在$HOME下创建.weatherrc文件,形如

[default]
ID = ZSPD
[nj]
ID = ZSNJ

就可以直接使用
weather

Current conditions at China (ZSPD) 31-07N 121-46E (ZSPD)
Last updated Feb 18, 2010 – 08:00 AM EST / 2010.02.18 1300 UTC
Temperature: 35 F (2 C)
Relative Humidity: 47%
Wind: from the NE (050 degrees) at 7 MPH (6 KT) (direction variable)


weather nj

Current conditions at China (ZSNJ) 32-00N 118-48E 12M (ZSNJ)
Last updated Feb 18, 2010 – 08:00 AM EST / 2010.02.18 1300 UTC
Temperature: 35 F (2 C)
Relative Humidity: 59%
Wind: from the SSW (210 degrees) at 4 MPH (4 KT)

Location Support on Empathy

好久不写了 ||

昨天看到了这么一篇介绍Gnome桌面上对地理位置的支持的文章(汗这句子)。地址在这里

我印象中最早的就是Gnome 2.24开始那个日期applet增加的一个地图,可以选择和设置当前的location,于是有了比较好的时区支持和天气服务。文章里还提到居然Tracker搜索也支持这么一个地理元信息,可以搜出在某个地方(是说地球上的某个地方)编辑的文件。这个很强。

然后就是Empathy对location的支持了。这个看起来很强大,截图和介绍可以看这里看这里看这里。Empathy可以用来发布你evolution的联系人地址。话说,很容易就想起来了,XMPP协议有一个地理位置的扩展。不过文中说几乎除了GoogleTalk其他都支持地理位置扩展。好家伙,这个又只能遥远地YY了。

文中提到的提供LBS的库叫做Geoclue,而在Gnome上显示地图是一个叫做libchamplain的widget。而地图,当然毫无疑问是OSM了。有兴趣的朋友可以去关注。

没了,静静等待这个Empathy变得越来越强大吧。