26

instagram是个iphone手机拍照利器,android党是无福消受了,不过幸好还有个类似强大的picplz,我比较喜爱70s和Little Plastic Lens特效。

近期换了个1.1G流量的3G卡,怎么用也才用到300M,浪费可耻鸟,得多拍拍照片。

picplz可以同步到twitter,facebook,4qs,就是没办法同步到新浪微博,网易微博,国内又没发现有这样的应用,有些遗憾。前些日子张锐感叹:再不做instagram,就有些晚了。

不过也没见网易有啥动静。

看来还是直接写点代码从picplz同步过来吧。

picplz个人页提供了个feed:http://picplz.com/user/seanwong/picfeed.rss/

思路是抓取第一条,下载了图文,再扔到新浪微博。

static Pattern patternImg = Pattern.compile("<img src=\"(.*?)\"");
public static void picplz(String url) {
//记录上次图片发布时间
String filename = "/picplz/picplz.log";
String tmppicname = "/picplz/picplz_tmp.jpg";
String picplztime = FileUtil.read(filename);
try {
URL feedUrl = new URL(url);

SyndFeedInput input = new SyndFeedInput();
SyndFeed feed = input.build(new XmlReader(feedUrl));
List list = feed.getEntries();
if(list.size()>0) {

SyndEntry entry = (SyndEntry) list.get(0);

long pubdate = entry.getPublishedDate().getTime();
//已经发布过的图片,避免重复发布
if(picplztime.equals(""+pubdate)){
return;
}
String title = entry.getTitle();
String imagesrc = entry.getDescription().getValue();
Matcher m = patternImg.matcher(imagesrc);
if (m.find()) {
imagesrc = m.group(1);
}
imagesrc = imagesrc.replaceAll("_thmb_", "_wmlg_");
//抓取图片到本地
wget(imagesrc,tmppicname);
//通过sina api上传图片
//String command = "/usr/bin/curl -u \"test@163.com:password" -F \"pic=@" + tmppicname + "\" -F \"status=asdfsdaf\" \"http://api.t.sina.com.cn/statuses/upload.json?source=4238273265\"";
String command = "/home/picplz_curl.sh " + title;

Process p = Runtime.getRuntime().exec(command);
p.waitFor();
//写入当前图片的时间
FileUtil.write(filename,""+pubdate);

}

} catch (Exception ex) {
ex.printStackTrace();

}
}

然后看见强叔在微博上震惊了,picplz居然可以同步到微博?

网易微博api有点复杂,貌似没有basic auth …

只能是先发图,获得图片链接,再发微博,汗了。。

Leave a Reply

preload preload preload