Created
June 5, 2014 15:13
-
-
Save pupca/7c8dfa71ce10023c6f8c to your computer and use it in GitHub Desktop.
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
require 'rubygems' | |
require 'active_support/all' | |
require 'awesome_print' | |
require 'google_calendar' | |
require 'simple_xlsx' | |
def id_from_name(name) | |
name = name.split(" ") | |
return name[1] + name[0][0] | |
end | |
def aaa | |
# :064:0> users.each do |login, value| | |
user = User.find_by_login(login) | |
puts "Warning - No user #{login} found" if user.nil? | |
unless user.nil? | |
Event.create(:from => Date.new(2013,1,1), :to => Date.new(2013,1,1), :work_days => value[:vacation_per_year]["2013"], :user_id => user.id, :kind => "vacation_credit", :note => "Vacation credit for year 2013") | |
Event.create(:from => Date.new(2014,1,1), :to => Date.new(2014,1,1), :work_days => value[:vacation_per_year]["2014"], :user_id => user.id, :kind => "vacation_credit", :note => "Vacation credit for year 2014") | |
if value[:remaining_vacation_from]["2012"].to_i > 0 | |
Event.create(:from => Date.new(2013,1,1), :to => Date.new(2013,1,1), :work_days => value[:remaining_vacation_from]["2012"], :user_id => user.id, :kind => "vacation_credit", :note => "Remaining vacation credits from 2012") | |
# irb(main):072:3> end | |
# irb(main):073:2> if value[:extra_work]["2013"].to_i > 0 | |
# irb(main):074:3> Event.create(:from => Date.new(2013,12,31), :to => Date.new(2013,12,31), :work_days => value[:extra_work]["2013"], :user_id => user.id, :kind => "vacation_credit", :note => "Extra work vacation credits for 2013") | |
# irb(main):075:3> | |
# irb(main):076:3* end | |
# irb(main):077:2> end | |
# irb(main):078:1> end | |
require "open-uri" | |
File.open(open("https://gist.githubusercontent.com/pupca/54db746e9512c646267f/raw/935c783382d3de994a7a339fa6d46a406c77acc7/gistfile1.yml"), "r") {|file| @events = YAML.load(file)} | |
@events.each do |event| | |
user = User.find_by_login(event[:login]) | |
puts "Warning - No user #{login} found" if user.nil? | |
unless user.nil? | |
Event.create(:from => event[:start].to_datetime, :to => event[:end_date].to_datetime, :kind => "vacation", "status" => "done", :user_id => user.id) | |
end | |
end | |
end | |
nice_hash = [] | |
cal = Google::Calendar.new(:username => "[email protected]", :password => "a123c456", :app_name => 'gcalvacation', :calendar => "Prague Vacations") | |
events = cal.find_events_in_range(Date.new(2013,1,1), Date.new(2014,12,31),options = {:max_results => 100000}) | |
events.each do |event| | |
nice_hash << {:start => Time.parse(event.start_time), :end_date => Time.parse(event.end_time), :login => id_from_name(event.title.mb_chars.normalize(:kd).gsub(/[^\x00-\x7F]/,'').downcase.split(" ").collect{|element| element.gsub(/\W+/, '')}[0..1].join(" "))} | |
end | |
File.open("events.yaml", "w+") {|file| file.puts nice_hash.to_yaml } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment