Last active
August 29, 2015 14:01
-
-
Save xavieryao/082fc6973e73c96e23ca to your computer and use it in GitHub Desktop.
Automatically and randomly change weibo avatar
This file contains 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
# Automatically change avatar! | |
# This is magical! | |
# Xavier Yao 2014-05-10 Sat | |
# Don't forget to install request (`npm install request') | |
fs = require 'fs' | |
request = require 'request' | |
date = new Date() | |
console.log date.toLocaleString() | |
luckyNum = Math.floor (Math.random()*10) %9 | |
filepath = "#{__dirname}/pic/#{luckyNum}.jpg" | |
console.log "Attempting to upload #{filepath}" | |
options = | |
url:"http://weibo.cn/account/setting/avatar/?vt=4&st=4eeb&gsid=#{gsid}" | |
headers: | |
'User-Agent':'Mozilla/5.0 (iPhone; CPU iPhone OS 7_0 like Mac OS X) AppleWebKit/537.51.1 (KHTML, like Gecko) Version/7.0 Mobile/11A465 Safari/9537.53' | |
'Referer':'http://weibo.cn/account/setting/avatar/?vt=4&st=4eeb' | |
'Origin':'http://weibo.cn' | |
r = request.post options,(err,response,body)-> | |
if err or body.length isnt 0 | |
console.log 'Upload failed! \nerr:%s\nbody:\n%s',JSON.stringify(err),body | |
return console.log '>>>>>>>>>>>>>>>>>>>>>>>>>>>>>' | |
console.log 'Upload successful!' | |
console.log '>>>>>>>>>>>>>>>>>>>>>>>>>>>>>' | |
form = r.form() | |
form.append 'act','avatar' | |
form.append 'save','1' | |
form.append 'pic',fs.createReadStream filepath |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment