Created
June 15, 2013 09:40
-
-
Save sivagao/5787549 to your computer and use it in GitHub Desktop.
wandoujia weibo2zendesk CRM
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var isWaitingAuth = true; | |
var isScheduleWorking = false; | |
var processPostTime; | |
var processCommentByMeTime; | |
var processCommentToMeTime; | |
// 收集从什么时间开始信息 | |
// 基于已处理的postid和ticketid | |
var startTimestore = process.env.wandoucrmStartTime; | |
var processedMap = new Database('./db'); | |
function weibo_crm_cb(){ | |
isScheduleWorking = true; | |
wandoujia_weibo.mentions(function(result){ | |
//if(result.getLastOne().time > ) | |
for(var i){ | |
if(item.ctime < startTimestore){ | |
break; // 跳出循环 | |
} | |
if(item.postid notat processedMap){ | |
// create ticket | |
// save a postid /w ticketid in processMap | |
} | |
} | |
}); | |
wandoujia_weibo. comments_to_me(wandoujia_weibo, function(){ | |
// 如果最新一条的时间 == processCommentToMeTime return; | |
// 去这段时间类的新comment, 同步 | |
if(comment.postid in processedMap){ | |
// add a comment to a ticket | |
} | |
}); | |
} | |
// socket 建立传输, 当成log... | |
var connect = require('connect'); | |
var weibo = require('weibo'); | |
weibo.init('weibo', '1010669877', '76b167d987033672406df17ff15f61c4'); | |
/** | |
* Create a web application. | |
*/ | |
var app = connect( | |
connect.query(), | |
connect.cookieParser('oh year a cookie secret'), | |
connect.session({ secret: "oh year a secret" }), | |
// using weibo.oauth middleware for use login | |
// will auto save user in req.session.oauthUser | |
weibo.oauth({ | |
loginPath: '/login', | |
logoutPath: '/logout', | |
callbackPath: '/oauth/callback', | |
blogtypeField: 'type', | |
afterLogin: function (req, res, callback) { | |
console.log(req.session.oauthUser && req.session.oauthUser.screen_name, 'login success'); | |
// hack! | |
isWaitingAuth = false; | |
wandoujia_weibo = req.session.oauthUser; | |
schedule.doOnTime(weibo_crm_cb); | |
process.nextTick(callback); | |
}, | |
beforeLogout: function (req, res, callback) { | |
console.log(req.session.oauthUser && req.session.oauthUser.screen_name, 'loging out'); | |
process.nextTick(callback); | |
} | |
}) | |
); | |
app.use('/', function (req, res, next) { | |
var user = req.session.oauthUser; | |
res.writeHeader(200, { 'Content-Type': 'text/html' }); | |
if (isWaitingAuth) { | |
// send('waiting') | |
res.end('Login with <a href="/login?type=weibo">Weibo</a>'); | |
return; | |
} else { | |
} | |
if (!user) { | |
res.end('Login with <a href="/login?type=weibo">Weibo</a> | \ | |
<a href="/login?type=tqq">QQ</a> | \ | |
<a href="/login?type=github">Github</a>'); | |
return; | |
} | |
res.end('Hello, <img src="' + user.profile_image_url + '" />\ | |
<a href="' + user.t_url + | |
'" target="_blank">@' + user.screen_name + '</a>. ' + | |
'<a href="/logout">Logout</a><hr/><pre><code>' + JSON.stringify(user, null, ' ') + '</code></pre>'); | |
}); | |
app.listen(8088); | |
console.log('Server start on http://localhost.nodeweibo.com:8088/'); | |
var user = { blogtype: 'weibo' }; | |
var cursor = {count: 20}; | |
weibo.public_timeline(user, cursor, function (err, statuses) { | |
if (err) { | |
console.error(err); | |
} else { | |
console.log(statuses); | |
} | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment