Sunday, August 12, 2007

YourGmailContacts.findAll{it.usePicasaweb()}

This groovy script checks an exported GMail contact list and find out whom on the list are using the Google Picasaweb to share photos. Download. View source

Why you create this script
Well, because some of my friends recently share photos on picasaweb but I am not aware of that until they send me the links. So far Picasa doesn't allow me to search the public albums among my GMail contacts.

How it works
First the user needs to export the Gmail contacts to a CSV file(HOWTO). Then specify the file path as the first parameter of this script, say C:>groovy picasaCheck C:\temp\gmail.csv . It will check each line and find out those gmail address. By leveraging the Picasa Web Albums Data API, it can easily verify whether those users are sharing public albums on picasa. The final result will be shown as a html file. Under the cover, this script will write a temp file and use groovy XML MarkupBuilder to add HTML code and open it using the system default browser. This blog explains how to launch the default browser in Windows/Linux/Mac.

Possible improvements
  • Get the gmail contacts via GTalk XMPP service. But I am doubt how many of you will type the gmail account in such an untrusted script -____-
  • Automatically add those contacts as picasa favorite. It's likely doable via the Picasa Web Albums Data API
  • Provide GUI. Not everyone likes command line tools, especially Windows users. SWING seems to be the only choice. But I prefer using the Groovy SWT module.
How to run
  1. Install JRE and Groovy if necessary
  2. Download the script and save the groovy file to any location
  3. Export your gmail contacts as CSV file
  4. Open a command line window and run groovy picasaCheck.groovy path.to.the.csv

看看还有谁把照片放在Google Picasaweb




这两年好多同学同事都结婚了, 不少把照片放在Google PicasaWeb上, 好处显而易见, 免费,空间够大,无需登录就可以访问,支持幻灯片放映.. 当然也够快

不论平时主要用MSN还是QQ, 身边还是有不少朋友有Gmail/GTalk帐号, 可惜目前Picasa还不支持查看你的联系人中还有谁在网上放了照片, 一个个试又很麻烦. 于是这个周末我写了下面这个小程序, 帮我检查Gmail通讯录中谁在picasa有公开的照片

做法其实很简单, 第一步自然是要得到整个Gmail通讯录. 目前很多Web2.0应用都有所谓的Invite Import, 输入MSN,GTalk帐号,向所有人发送invite----所谓的Web2.0病毒式传播. 不过网上查了查似乎没有现成的Code. 一个可行的做法应该是利用Google Talk的XMPP服务, 找个能用的Lib登录到talk.google.com, 得到好友列表. 不过目前这个小程序没有这样做, 或许以后可以加上. 一来怕麻烦, 二来也担心用户会有顾虑, 凭什么把Google帐号给你, 万一你把用户名密码偷去怎么办. 所以,目前的做法是, 用户需要自己登录GMail, 然后点Contact,再选择Export, 把联系人列表导出成CSV, 即逗号分割的文件. 详见GMail的帮助

然后就简单了, 遍历每一行,找到xxx@gmail.com, 然后发个请求http://picasaweb.google.com/data/feed/api/user/xxx?kind=album 这个服务是所谓的Picasa Web Albums Data API, 具体内容见这里. 他会返回一个ATOM feed, 包括该用户的Public Album. 我这段程序会去判断有多少个公开的相册, 只要有一个就加入列表. 如果那人从来没用过picasaweb, 会返回"No such user."如果他放了照片但都没有list出来, 那么这段feed中就没有entry

结果最后用一个HTML文件来显示, 列出哪些人被验证在picasaweb放了照片, 并列出有多少个相册. 用程序在系统临时目录写一个文件,然后用rundll32 url.dll,FileProtocolHandler path.to.the.html来让系统默认浏览器打开. 当然这只能在Windows上有效, 要支持Linux/Mac也不难, 参见这里

程序用Groovy完成, 总共才65行, 如果用java写估计得500+行. 没有GUI, 命令行中指定导出的Gmail联系人列表, 然后他会一个个check,最后写个HTML文件,自动打开



下载这个程序 有什么问题给我留言, 或直接Gmail/Gtalk与我联系 jovezhong@gmail.com