Skip to content

Instantly share code, notes, and snippets.

@hxgdzyuyi
Created May 11, 2012
Embed
What would you like to do?
导出人人网生日信息
bundle install
bundle exec shotgun birthday-2-ical.rb -p 4567 -s webrick 

访问 http://127.0.0.1:4567 就会自动生成 birthday.ics

# encoding: utf-8
require 'rubygems'
require 'sinatra'
require 'omniauth-renren'
require 'renren'
require 'icalendar'
use Rack::Session::Cookie
#you can use your api_key and api_secret
Renren::Config.api_key = "a8342350bfe04e48918c8d01ecae0740"
Renren::Config.api_secret = "355c9715691a44bebf4a97685140599d"
use OmniAuth::Builder do
provider :Renren, Renren::Config.api_key, Renren::Config.api_secret
end
configure do
mime_type :ics, 'text/calendar'
end
get '/' do
unless session["token"]
redirect "/auth/renren"
else
renren = Renren::Base.new(session["token"])
#for more renren API, visit http://wiki.dev.renren.com/wiki/API
friendsUid = renren.call_method(:method => 'friends.get').join(',')
friendsInfo = renren.call_method(:method => 'users.getInfo',
:uids => friendsUid,
:fields =>'name,birthday')
cal = Icalendar::Calendar.new
cal.timezone do
tzid 'Asia/Shanghai'
standard do
tzoffsetfrom '+0800'
tzoffsetto '+0800'
tzname 'CST'
end
end
friendsInfo.each do |user|
birthdayStr = "2012" + user["birthday"][4..-1]
next if birthdayStr.include?("-00")
birthday = DateTime.parse(birthdayStr)
desc = "今天是" + user['name'] + "的生日"
cal.event do
dtstart birthday
dtend birthday.new_offset('+24:00')
summary desc
end
end
cal.publish
content_type :ics
response['Content-Disposition'] = "attachment; filename=birthday.ics"
cal.to_ical
end
end
get '/auth/:name/callback' do
puts request.env['omniauth.auth'].inspect
session["token"] = request.env['omniauth.auth']['credentials']['token']
redirect "/"
end
source 'http://rubygems.org'
gem 'omniauth-renren', '~> 1.0.0.rc2', :git => 'git://github.com/huangxiangdan/omniauth-renren.git'
gem 'renren'
gem 'sinatra'
gem 'shotgun'
gem 'icalendar'
@1703011
Copy link

1703011 commented Nov 20, 2013

请问能不能指导一下如何使用?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment