require'faraday'require'yaml'require'json'classWeiboPosterdefinitialize@weibo_config=YAML.load_file(File.expand_path(File.dirname(__FILE__)+'/weibo-config.yml'))@pushups=YAML.load_file(File.expand_path(File.dirname(__FILE__)+'/pushups.yml'))enddefpost_weibo(number)@number=numberconn=Faraday.new(:url=>"https://api.weibo.com")result=conn.post'/2/statuses/update.json',:access_token=>@weibo_config['access_token'],:status=>generate_postresponseJSON=JSON.parseresult.bodyifresponseJSON['error_code']puts'post error:'+responseJSON['error']elseputs"post to weibo successfully"endendprivatedefgenerate_posttotal=get_historytotal=total+@number.to_inumber_rest=4000-totalsave_to_historytotalpost_template=@weibo_config['post_template'].force_encoding("utf-8")post_template%{:number_done=>@number,:total=>total,:number_rest=>number_rest}enddefget_history@pushups['total']enddefsave_to_history(total)@pushups['total']=totalFile.open('pushups.yml','w')do|h|h.write@pushups.to_yamlendendendposter=WeiboPoster.newposter.post_weiboARGV[0]