Skip to content

Instantly share code, notes, and snippets.

@twtw
Created April 12, 2012 08:10
Show Gist options
  • Save twtw/2365555 to your computer and use it in GitHub Desktop.
Save twtw/2365555 to your computer and use it in GitHub Desktop.
update calendar, schedule column by sequel
# encoding: UTF-8
# example records
#id|odate|opentime|m|n|e|start|end
#12|2012-01-12|8:00~23:00|0|0|0|0|0
#13|2012-01-13|學期考結束Final Exams end 8:00~23:00|0|0|0|0|0
#14|2012-01-14|選舉Election Day 休館一天Closed|0|0|0|0|0
#15|2012-01-15|9:00~17:00|0|0|0|0|0
#16|2012-01-16|寒假開始Winter Vacation begins 8:00~21:00|0|0|0|0|0
def change_mne(open)
if open.opentime =~ /^(\d+):\d+~(\d+):\d+$/
if $1.to_i < 12
open.m =1
end
open.n = 1
if $2.to_i > 17
open.e = 1
end
open.start = $1
open.end = $2
open.save
elsif open.opentime =~ /(\D*)(\d+):\d+~(\d+):\d+/
if $2.to_i < 12
open.m =1
end
open.n = 1
if $3.to_i > 17
open.e = 1
end
open.start = $2
open.end = $3
open.save
else
# 本日閉館,不用改預設的 mne 皆為0
end
end
DB = Sequel.connect('sqlite://open.db')
opens = DB[:opens]
class Open < Sequel::Model(:opens)
end
Open.all.each do |open|
change_mne(open)
puts open.odate
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment