Home > Tags > calendar

calendar

WordPress CalendarCloud plugin

What ?

A WordPress TemplateTag plugin that displays yearly calendars containing 12 months weighed by their post counts, like Tag Cloud.

Example

and, live demo is placed in the sidebar of this blog.

Download

calendar_cloud.zip (20KB)

Install

  1. Upload and unzip calendar_cloud.zip to the /wp-content/plugins/ directory
  2. Activate the plugin through the ‘Plugins’ menu in WordPress

Use css to customize look & feel. See an example in style.css.

Usage

put following line in your template:

<?php calendar_cloud(); ?>

ChangeLog

  • 0.2 : accordance with WordPress Coding Standard.
  • 0.1 : initial release.

Feel free to send any feedbacks.

user_timeline_to_ical

What is this ?

A simple Ruby script that generates iCalendar format from Twitter user_timeline.

Download

user_timeline_to_ical.rb

Requirements

following gems installed:

  • json
  • icalendar

How to use

simply type

ruby user_timeline_to_ical.rb [your_screen_name]

to print out recent 20 events in iCalendar format to stdout.

Redirect its output to a file, then import it with iCal or Google Calendar.

Screenshot

from iCal: Twitter to iCalendar-01

from Google Calendar: Twitter to iCalendar-02

Future …

I’m developing a web service that serves iCalendar feed (by sending direct message to tracking bot). You will subscribe its URL to see your past behaviors at some time.

Code

Try it !

#
# create iCalendar from recent 20 user_timeline.
#
# usage
#   ruby user_timeline_to_ical.rb [username] > some.ics
#
require 'rubygems'
require 'json'
require 'icalendar'
require 'uri'
require 'open-uri'
require 'kconv'
require 'nkf'
require 'logger'
 
KCODE = 'u'
 
# XXX:
#   quick fix to avoid charset crash
module Icalendar
  class Component < Icalendar::Base
    def print_properties
      s = ""
 
      @properties.each do |key,val| 
        # Take out underscore for property names that conflicted
        # with built-in words.
        if key =~ /ip_.*/
          key = key[3..-1]
        end
 
        # Property name
        unless multiline_property?(key)
           prelude = "#{key.gsub(/_/, '-').upcase}" +
 
           # Possible parameters
           print_parameters(val) 
 
           # Property value
           value = ":#{val.to_ical}" 
           escaped = prelude + value.gsub("\\", "\\\\").gsub("\n", "\\n").gsub(",", "\\,").gsub(";", "\\;")
           #escaped = value
           #s << escaped.slice!(0, MAX_LINE_LENGTH) << "\r\n " while escaped.size > MAX_LINE_LENGTH # XXX : quick fix to avoid charset crash
           s << escaped << "\r\n"
           s.gsub!(/ *$/, '')
         else 
           prelude = "#{key.gsub(/_/, '-').upcase}" 
            val.each do |v| 
               params = print_parameters(v)
               value = ":#{v.to_ical}"
               escaped = prelude + params + value.gsub("\\", "\\\\").gsub("\n", "\\n").gsub(",", "\\,").gsub(";", "\\;")
               s << escaped.slice!(0, MAX_LINE_LENGTH) << "\r\n " while escaped.size > MAX_LINE_LENGTH
               s << escaped << "\r\n"
               s.gsub!(/ *$/, '')
            end
         end
      end
      s
    end
  end
end
 
class UserTimeLine
  attr_accessor :id, :since
  URL = 'http://twitter.com/statuses/user_timeline/'
 
  def initialize(id)
    @id = id
    #@log = Logger.new('debug.log')
  end
 
  def get(url)
    JSON.parse(open(url).readlines.join).sort { |a, b| a['id'] <=> b['id'] }
  end
 
  def url(*arg)
    url = URL + @id + '.json'
    return url if arg.empty?
 
    hash = arg[0]
    args = {}
 
    args['page'] = hash[:page] if hash[:page]
    if hash[:since]
      if String == hash[:since].class 
        args['since'] = URI.escape(hash[:since].split.join('+'))
      else # should be Number
        args['since_id'] = hash[:since]
      end
    end
    arg = args.collect { |k, v| [k, v].join('=') }.join('&')
 
    url + '?' + arg
  end
 
  def to_ical
    msgs = get(url).collect {|x| [x['text'], x['created_at']]}
    cal = Icalendar::Calendar.new
 
    (msgs.size-1).times do |i|
      cal.event do
        dtstart  DateTime.parse(msgs[i][1]).to_ical(true)
        dtend    DateTime.parse(msgs[i+1][1]).to_ical(true)
        summary  msgs[i][0]
      end
    end
 
    cal.to_ical
  end
end
 
 
utl = UserTimeLine.new(ARGV.shift)
print NKF.nkf('-w -Lw', utl.to_ical)

Home > Tags > calendar

Feeds

Return to page top