Skip to content

Instantly share code, notes, and snippets.

@ksky521
Created May 7, 2013 13:27
Show Gist options
  • Save ksky521/5532540 to your computer and use it in GitHub Desktop.
Save ksky521/5532540 to your computer and use it in GitHub Desktop.
使用iweibo,30行代码搞定微博天气机器人
var bdTemplate = require('./baiduTemplate').template;
var iweibo = require('iweibo');//npm install iweibo
var Weibo = iweibo.Weibo;
var access_token = '2.xxxxx';
iweibo.set({
appkey: 'xxxx',
appsecret: 'xxxxx'
});
var weibo = new Weibo(access_token, '');
function getWeather(callback) {
var html = '#<%=city%>天气#<%=date_y%>[<%=week%>]:<%=temp1%>,<%=weather1%>,<%=wind1%>,<%=index_d%> 明天:<%=temp2%>,<%=weather2%>,<%=wind2%>';
var json = weibo.get('http://m.weather.com.cn/data/101010100.html').done(function(err, data) {
data = JSON.parse(data).weatherinfo;
html = bdTemplate(html, data);
callback(html);
});
}
getWeather(function(html) {
weibo.api('statuses/update', {
status: html
}).done(function(err, result) {
console.log(result);
}).fail(function(err, result) {
console.log('出错啦!!' + JSON.stringify(result));
});
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment