Google CalendarとConkyを繋げよう

Ubuntu英語フォーラムTutorial of the Week翻訳技術評論社さんのUbuntu Weekly Topics、もとい執筆者の吉田さんに取り上げて頂いておりますし、引き続き翻訳させて頂きます。

以下はUbuntuの英語フォーラムTutorial of the Weekの翻訳です。原文「Conky Google Calendar Python Script」はユーザーkaivalagiによって執筆されています。英語フォーラムにおける投稿はCreative Commons Attribution 3.0です。この文章自体はCreative Commons Attribution Share Alike 3.0とします。tar.gzを用いるインストール方法はほぼ利用者がいないでしょうし、説明も不十分なので省きました。

私が書いたConky用のスクリプトは全てHardy, Interpid, Jaunty, Karmic向けにパッケージしてある。リポジトリの場所は以下のインストールの項を参照して欲しい。

conkyGoogleCalendar

紹介

以前に公開したconkyForecastスクリプトに引き続きconkyの利用者のための新しいスクリプト作った。conkyForecastスクリプトはこちらのスレッドにある。

このスクリプトはGoogle CalendarのデフォルトカレンダーにあるイベントをConkyで利用できる形で出力する。他にもコマンドラインで同じ事をする方法はあるだろうけど、自分で改造できるようにしたかったし、みんなのアイデアも取り入れていくつもりだ。

機能としては:

  • Google CalendarのAPIを利用する
  • イベントの出力結果にテンプレートを利用できる
  • システムのロカールを使って異なる時間帯をサポートする
  • 多くのイベントがある場合に早いものから先にイベントの数を制限して出力できる

READMEも添付してあるので一度は目を通してくれ。役に立ってくれるとうれしい。何か意見があれば是非教えてくれ。

インストール

aptを利用する

1. リポジトリにアクセスするためのリストを作成する

Karmic Koala:

sudo wget -q http://www.kaivalagi.com/ubuntu/ppa/m-buck-conky-karmic.list -O /etc/apt/sources.list.d/m-buck-conky-karmic.list

Jaunty Jackalope

sudo wget -q http://www.kaivalagi.com/ubuntu/ppa/m-buck-conky-jaunty.list -O /etc/apt/sources.list.d/m-buck-conky-jaunty.list

Intrepid Ibex

sudo wget -q http://www.kaivalagi.com/ubuntu/ppa/m-buck-conky-intrepid.list -O /etc/apt/sources.list.d/m-buck-conky-intrepid.list

Hardy Heron

sudo wget -q http://www.kaivalagi.com/ubuntu/ppa/m-buck-conky-hardy.list -O /etc/apt/sources.list.d/m-buck-conky-hardy.list

2. リポジトリの公開鍵をaptに追加する

wget -q http://www.kaivalagi.com/ubuntu/ppa/m-buck-conky-key.gpg -O- | sudo apt-key add -

3. apt-getでインストール

sudo apt-get update && sudo apt-get install conkygooglecalendar

debファイルを利用する

添付されているdebファイルをダウンロードして実行する。但し最新とは限らない。最初の方法でaptを利用すればアップデートも行われる。

使い方

ヘルプは次のオプションで見られる:

python ~/.scripts/conkyGoogleCalendar.py -h

ないし

python ~/.scripts/conkyGoogleCalendar.py --help

使い方は以下の通りだ:

Usage: conkyGoogleCalendar [options]
Options:
  -h, --help            show this help message and exit
  -u USERNAME, --username=USERNAME
                        Username for login into Google Calendar, this will
                        normally be your gmail account
  -p PASSWORD, --password=PASSWORD
                        Password for login
  -r TEXT, --requestCalendarNames=TEXT
                        Define a list of calendars to request event data for,
                        calendar names should be separated by semi-colons ";".
                        For example --requestCalendarNames="cal1;cal2;other
                        cal" If not set all calendar data will be returned.
  -d NUMBER, --daysahead=NUMBER
                        [default: 7] Define the number of days ahead you wish
                        to retrieve calendar entries for, starting from today.
  -s DATE, --startdate=DATE
                        Define the start date to retrieve calendar events. In
                        the form '2007-12-01'
  -e DATE, --enddate=DATE
                        Define the end date to retrieve calendar events, must
                        be supplied if --startdate supplied. In the form
                        '2007-12-01'
  -a, --allevents       Retrieve all calendar events
  -w TEXT, --wordsearch=TEXT
                        Define the text to search calendar entries with.
  -l NUMBER, --limit=NUMBER
                        [default: 0] Define the maximum number of calendar
                        events to display, zero means no limit.
  -t FILE, --template=FILE
                        Template file determining the format for each event.
                        Use the following placeholders: [title], [starttime],
                        [endtime], [location], [description], [who]. Ensure
                        only one placeholder per line, as the whole line is
                        removed if no data for that placeholder exists.
  -f "DATEFORMAT", --dateformat="DATEFORMAT"
                        If used this overrides the default date formatting.
                        The values to use are standard formatting strings e.g.
                        Weekday=%a, Day=%d, Month=%m, Year=%y. For an output
                        like "Thu 15/10/2008" you would require
                        --dateformat="%a %d/%m/%y", to have no date you would
                        require --dateformat=""
  -F "TIMEFORMAT", --timeformat="TIMEFORMAT"
                        If used this overrides the default time formatting.
                        The values to use are standard formatting strings e.g.
                        Hours (12hr)=%l, Hours (24hr)=%H, Minutes=%M,
                        Seconds=%S, AM/PM=%P. For an output like "05:22 PM"
                        you would require --timeformat="%l:%M %P",
                        --timeformat="" is not supported, default locale
                        settings are used
  -i NUMBER, --indent=NUMBER
                        [default: 0] Define the number of spaces to indent the
                        output (excludes template based output)
  -m NUMBER, --maxwidth=NUMBER
                        [default: 40] Define the number of characters to
                        output per line
  -n, --nowho           Hides who is attending the events (excludes template
                        based output)
  -c NUMBER, --connectiontimeout=NUMBER
                        [default: 10] Define the number of seconds before a
                        connection timeout can occur.
  -v, --verbose         Request verbose output, no a good idea when running
                        through conky!
  -V, --version         Displays the version of the script.
  --errorlogfile=FILE   If a filepath is set, the script appends errors to the
                        filepath.
  --infologfile=FILE    If a filepath is set, the script appends info to the
                        filepath.

重要な点としてはConky内での呼び出し方次のようになったことだ:

{execi 1800 conkyGoogleCalendar ...options...}

以前はこうだった:

{execi 1800 python /path/to/file/conkyGoogleCalendar.py ...options...}

設定

conkyGoogleCalendar.pyスクリプトには一つ重要な設定値がある。記述が長くなったときのために出力の量に上限を設定できる。

MAX_WIDTH = 47

必要であればこの値を変えてみてほしい。

その他

出力結果の省略

Conkyはデフォルトでexeciを含め変数当たり128バイト以上の出力を受け付けない。このデフォルトのバッファーサイズよりも大きな出力をするようなテンプレートを作ると、出力結果が一部省略されてしまう。デフォルトを変更するにはconkyrcファイルを次のように変更すればよい。

text_buffer_size 512

キャプチャ

“GoogleCalendarEngine Initialisation:Unexpected error:Captcha Required”というエラーで動かなくなることがある。これはグーグルがやってることで、次のURLで認証を行えば解決できる。https://www.google.com/accounts/UnlockCaptcha

ロカールとユニコード

“ERROR: writeOutput:Unexpected error:’ascii’ codec can’t decode byte 0xc3 in position 14: ordinal not in range(128)”というようなエラーはスクリプトがシステムのロカールを取り扱えていないということだ。conkyrcファイルの TEXTの上に次の行を加えれば解決する。

override_utf8_locale yes

開発履歴

開発履歴は次のページで見られる。https://code.launchpad.net/~m-buck/+…googlecalendar

私が提供しているパッケージは以下にある:

  1. Conky Packages – https://launchpad.net/~m-buck/+archive/conky
  2. gtk-desktop-info – https://launchpad.net/~m-buck/+archive/gtk-desktop-info
  3. Rhythmbox Packages – https://launchpad.net/~m-buck/+archive/rhythmbox

新しいウェブサイトも作った。今のところあまり中身がないがconkyスクリプトについてもそれなりにかかれている。こちらだ:http://www.kaivalagi.com

添付ファイル

Google CalendarとConkyを繋げよう」への2件のフィードバック

  1. Conkyに興味を持ちました。試してみようと思います。

    細かいですが・・・
    s/イベント我ある場合/イベントがある場合/

  2. コメントありがとうございます。

    修正させていただきました。ブログのためにまとまった量の日本語を書いていると、変換精度がもう少し高いといいなと思います。よくチェックすればいいんですがWordpressのエディタの動作が鈍いので怠りがちです。

コメントは停止中です。