Update and rename sources/How to integrate Google Calendar in Linux desktop.md to translated/How to integrate Google Calendar in Linux desktop.md

This commit is contained in:
Linchenguang 2014-01-17 09:47:37 +08:00
parent f4cfb18621
commit 430c5a9cf5
2 changed files with 224 additions and 206 deletions

View File

@ -1,206 +0,0 @@
**【chenguang翻译中】**
How to integrate Google Calendar in Linux desktop
================================================================================
Google Calendar is one of the most popular web applications. One can access or sync Google Calendar across multiple devices either via web interface or with native apps. In Linux, there are several ways to access Google Calendar natively, such as by using email client plugins (e.g., Evolution or Thunderbird) or calendar apps (e.g., Sunbird or Rainlendar). These solutions, however, typically involve installing unnecessarily bulky software which you will probably not need.
If all you want is to access and get reminded by Google Calendar natively on Linux, then you can consider [Google Calendar command line interface (or gcalcli)][1], which is much more light-weight. Even better for Linux desktop, you can use gcalcli together with [Conky][2], to integrate Google Calendar into your desktop theme transparently.
In this tutorial, I will demonstrate **how to integrate Google Calendar into Linux desktop, by using gcalcli and Conky**.
### Install gcalcli on Linux ###
Before installing gcalcli, verify that you are using Python 2, as gcalcli is not compatible with Python 3.
To install gcalcli on Debian, Ubuntu or Linux Mint, use the following commands.
$ sudo apt-get install git python-pip python-gdata python-dateutil python-gflags python-vobject python-parsedatetime
$ sudo pip install google-api-python-client
$ sudo pip install apiclient urllib3
$ git clone https://github.com/insanum/gcalcli.git
$ cd gcalcli
$ sudo python setup.py install
**Note**: gcalcli is included in the standard repository of Ubuntu or Linux mint. However, that version is not updated with the latest features and bug fixes. So I recommend building gcalcli from the source, as documented above.
To install gcalcli on Fedora, CentOS or RHEL, run the following.
$ sudo yum install git python-pip python-gdata python-dateutil python-gflags python-vobject
$ sudo pip install google-api-python-client
$ sudo pip install apiclient urllib3
$ git clone https://github.com/insanum/gcalcli.git
$ cd gcalcli
$ sudo python setup.py install
### Google Authentication for gcalcli ###
To be able to access Google Calendar with gcalcli, you need to go through OAuth2 authention with your Google account, in order to grant gcalcli permission to access your Google Calendar.
The first time you run gcalcl, OAuth2 authentication will automatically be initiated. Thus run the following command to start.
$ gcalcli agenda
The command will print out a URL as shown below.
[![](http://farm4.staticflickr.com/3791/11216331146_d2c5f95963_z.jpg)][3]
At the same time, it will pop up a web browser window, and direct you to the URL. If a web browser window fails to open for any reason, you can copy and paste the URL into a web browser window manually.
If you are not logged in to your Google account, you will be asked to log in. After logging in, you will see the following message, asking you to allow gcalcl to manage your Google Calendar. Click on "Accept" button.
[![](http://farm4.staticflickr.com/3810/11216308465_1008fc1bb3_z.jpg)][4]
Enable Google Calendar API
After authentication, the next step is to enable API access for Google Calendar. gcalcli accesses your Google Calendar via Google Calendar API. In order to use Google Calendar API, however, you need to explicitly enable the API under your Google account.
First go to: [https://cloud.google.com/console][5]. Click on "API Project" under project list.
Go to "APIs & auth" --> "APIs" to see a list of Google APIs. Click on toggle button for "Calendar API" to enable the API.
Now go to "APIs & auth" --> "Registered apps" to register gcalcli app. Click on "Register app" button on the top.
[![](http://farm8.staticflickr.com/7293/11216363656_c203b6dfa2_z.jpg)][6]
Fill in the app name (e.g., "My Gcalcli"), and choose "Native" as a platform. Click on "Register" button to finalize.
This will create and show OAuth client ID and secret as follows. Make a note of this information. You can ignore the warning saying that "You have not set up your product name".
[![](http://farm3.staticflickr.com/2890/11216593546_312a564f1f_z.jpg)][7]
The result of OAuth authentication will be saved in ~/.gcalcli_oauth text file.
### Access Google Calendar from the Command Line with gcalcli ###
You are almost ready to access Google Calendar with gcalcli.
Create a gcalcli configuration file in your home directory as follows. Put OAuth client ID and secret that you obtained before, in the following format.
$ vi ~/.gcalclirc
> --client_id='XXXXXXXXXX.apps.googleusercontent.com'
> --client_secret='YYYYYYYYYYYYYYYY'
At this point, you should be able to run gcalcli from the command line.
Try the following two commands, which will print a list of your Google Calendars, and an agenda for the next 5 days, respectively.
$ gcalcli list
$ gcalcli agenda
[![](http://farm4.staticflickr.com/3780/11216465043_c8f6d8967d_z.jpg)][8]
### Integrate gcalcli with Conky ###
The final step is to integrate the output of gcalcli into your desktop theme. For that, you need Conky, which is a very powerful tool that can display a wide range of information directly on desktop theme.
First [install Conky][9] on your Linux system.
Then, create a following script somewhere in your home directory (e.g., ~/bin).
$ vi ~/bin/gcal.sh
> #!/bin/sh
>
> gcalcli --conky calw 2 |
> sed -e 's/^[(0\x71^[(B/?/g' \
> -e 's/^[(0\x78^[(B/?/g' \
> -e 's/^[(0\x6A^[(B/?/g' \
> -e 's/^[(0\x6B^[(B/?/g' \
> -e 's/^[(0\x6C^[(B/?/g' \
> -e 's/^[(0\x6D^[(B/?/g' \
> -e 's/^[(0\x6E^[(B/?/g' \
> -e 's/^[(0\x74^[(B/?/g' \
> -e 's/^[(0\x75^[(B/?/g' \
> -e 's/^[(0\x76^[(B/?/g' \
> -e 's/^[(0\x77^[(B/?/g'
$ chmod +x ~/bin/gcal.sh
**Important Note**: '^[' in the above script must be the **actual ESCAPE key** (i.e. press Ctrl-V ESC in vi editor).
This script translates VT100 escape sequences to Unicode box drawing characters. This is a [needed workaround][10] because Conky does not support ASCII line art used by gcalcli.
Finally, create a Conky configuration file in your home directory as follows.
$ vi ~/.conkyrc
> alignment top_right
> maximum_width 630
> minimum_size 330 10
> gap_x 25
> gap_y 50
>
> own_window yes
> own_window_type conky
> own_window_hints undecorated,below,sticky,skip_taskbar,skip_pager
> own_window_transparent yes
> own_window_argb_visual yes
> own_window_argb_value 0
>
> update_interval 300
> background no
>
> border_width 1
> default_color cornflowerblue
> default_outline_color white
> default_shade_color white
> double_buffer no
> draw_borders no
> draw_graph_borders no
> draw_outline no
> draw_shades no
> max_port_monitor_connections 64
> max_specials 512
> max_user_text 16384
> text_buffer_size 8096
> no_buffers yes
> out_to_console no
> uppercase no
> use_xft yes
> xftfont Bitstream Vera Sans Mono:size=10
>
> TEXT
> *** Google Calendar Agenda ***
> ${execpi 300 gcalcli --conky agenda}
> ${execpi 300 ~/bin/gcal.sh}
This Conky configuration will display an agenda and two weeks' worth of schedules of your Google Calendar, directly in your desktop theme. The displayed info is updated every 5 minutes.
Now you can activate Conky by running the following.
$ conky
You should see Google Calendar in the right side of your Linux desktop as follows.
[![](http://farm8.staticflickr.com/7390/11216377436_72d00cec49_z.jpg)][11]
Once you verify that Google Calendar shows up correctly, you can set Conky to auto-start every time you log in to your desktop.
### Set up Google Calendar Reminder ###
gcalcli can also send a reminder for any upcoming schedule in your Google Calendar. It uses notify-send command to send desktop notifications. For Google Calendar reminder, you can set up a cron job like the following.
$ crontab -l
> */10 * * * * /usr/local/bin/gcalcli remind
--------------------------------------------------------------------------------
via: http://xmodulo.com/2013/12/integrate-google-calendar-linux-desktop.html
译者:[译者ID](https://github.com/译者ID) 校对:[校对者ID](https://github.com/校对者ID)
本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创翻译,[Linux中国](http://linux.cn/) 荣誉推出
[1]:https://github.com/insanum/gcalcli
[2]:http://conky.sourceforge.net/
[3]:http://www.flickr.com/photos/xmodulo/11216331146/
[4]:http://www.flickr.com/photos/xmodulo/11216308465/
[5]:https://cloud.google.com/console
[6]:http://www.flickr.com/photos/xmodulo/11216363656/
[7]:http://www.flickr.com/photos/xmodulo/11216593546/
[8]:http://www.flickr.com/photos/xmodulo/11216465043/
[9]:http://xmodulo.com/2013/12/install-configure-conky-linux.html
[10]:https://github.com/insanum/gcalcli/issues/97
[11]:http://www.flickr.com/photos/xmodulo/11216377436/

View File

@ -0,0 +1,224 @@
如何将Google Calendar 集成到Linux桌面
================================================================================
Google Calendar 是时下最流行的网页应用程序之一。用户可以通过网络接口或者本地的应用程序跨设备访问或同步Google Calendar。在Linux上有很多本地访问 Google Calendar 的解决方案,比如用电子邮件客户端插件(如 Evolution 或 Thunderbird )或者用日历应用程序(如 Sunbird 或 Rainklendar。这些方法通常都需要安装不必要的大型软件这些软件你很可能根本就不需要。
如果你只是想在本地的Linux上翻翻Google Calendar或者用它设置提醒那么你可以考虑使用[Google Calendar命令行接口或者 gcalcli][1]这是一种更轻型化的方法。对于Linux桌面操作系统用户来说好处不止这些如果将gcalcli与[Conky][2]搭配使用你就可以把Google Calendar透明地融入桌面主题。
在这个教程中,我会演示**如何利用 gcalcli 和 Conky 将 Google Calendar 融入 Linux桌面**
### 在 Linux 安装 gcalcli ###
在安装 gcalcli 之前,要确保你正在用的是 Phython 2 而不是 Phython 3 ,因为 Phython 3 与 gcalcli 不兼容。
如果是在 Debian、Ubuntu 或 Linux Mint 上可以用下面的命令安装 gcalcli
$ sudo apt-get install git python-pip python-gdata python-dateutil python-gflags python-vobject python-parsedatetime
$ sudo pip install google-api-python-client
$ sudo pip install apiclient urllib3
$ git clone https://github.com/insanum/gcalcli.git
$ cd gcalcli
$ sudo python setup.py install
**温馨提醒**Ubuntu 或 Linux Mint 标准容器中虽然有 gcalcli但是这些版本并不包含其最新的特性和针对bug的修复。所以这里推荐按以上所述的方法由源文件构建 gcalcli。
对于Fedora 、CentOS 或 RHEL可按如下方法安装。
$ sudo yum install git python-pip python-gdata python-dateutil python-gflags python-vobject
$ sudo pip install google-api-python-client
$ sudo pip install apiclient urllib3
$ git clone https://github.com/insanum/gcalcli.git
$ cd gcalcli
$ sudo python setup.py install
### gcalcli 的 Google 认证 ####
为了能让 gcalcli 访问 Google Calendar 你需要用你的Google 帐号通过 OAuth2 认证以使gcalcli获得访问你的 Google Calendar 的许可。
第一次运行 gcalcli 的时候OAuth2 认证会自动进行初始化。因此开始时运行下面的命令
$ gcalcli agenda
该命令会输出如下的一个 URL 。
[![](http://farm4.staticflickr.com/3791/11216331146_d2c5f95963_z.jpg)][3]
同时这个命令也会弹出一个指向该 URL 的浏览器窗口。如果你的浏览器没有反应,你可以手动复制粘贴这个 URL 到你的浏览器中。
如果你还没有登录你的 Google 帐号你得先登录。然后你会看到下面要求你许可gcalcli管理Google Calendar 的信息。点击“Accept”即可。
[![](http://farm4.staticflickr.com/3810/11216308465_1008fc1bb3_z.jpg)][4]
使能Google Calendar API
认证后,下一步就是使能 Google Calendar 的 API 访问。gcalcli通过 Google API 访问Google Calendar 。但是如果要使用Google API就必须明确地在你的Google 帐号下使能Google API。
首先到:[https://cloud.google.com/console][5]。点击工程列表下的“API Project ”
转到“Apiary & auth ”下面的“APIs”你会看见一个Google APIs 列表。点击“Calendar API”的开关按钮使能该API。
现在跳到“Apiary & auth”下的“Registered apps”那里去登记gcalcli app。点击最顶端的“Registered app”按钮。
[![](http://farm8.staticflickr.com/7293/11216363656_c203b6dfa2_z.jpg)][6]
填写 app 的名字“My Gcalcli”然后选择“ Native ”作为平台。点击“Registered”按钮。
这一步会生成并显示 OAuth 用户的 ID 和密码。另外关于上面提示的“You have not set up your product name”的信息你可以忽略它。
[![](http://farm3.staticflickr.com/2890/11216593546_312a564f1f_z.jpg)][7]
OAuth的认证结果将会保存在 /.gcalcli_oauth 文本文件中。
### 用 gcalcli 在命令行中访问Google Calendar ###
你现在就快可以用 gcalcli 访问Google Calendar 了。
在你的家目录创建如下的一个 gcalcli 配置文件。将你先前获得的 OAuth 用户 ID 和 密码按下面格式写进去。
$ vi ~/.gcalclirc
> --client_id='XXXXXXXXXX.apps.googleusercontent.com'
> --client_secret='YYYYYYYYYYYYYYYY'
到了这一步,你应该可以在命令行运行 gcalcli 了。
试试下面的命令这两个命令会分别打印出一个你的Google Calendar 的列表和今后 5 天的日程安排。
$ gcalcli list
$ gcalcli agenda
[![](http://farm4.staticflickr.com/3780/11216465043_c8f6d8967d_z.jpg)][8]
### 将 gcalcli 与 Conky 结合 ###
最后一步就是将 gcalcli 的输出导入你的桌面主题中。为了达到这个目的你需要Conky一个非常强大的工具它可以把许多信息直接显示在你的桌面主题中。
首先在你的 Linux 系统上 [安装 Conky][9]。
然后,在你的家目录下的某个地方( 可以是 /bin )创建如下的脚本程序。
$ vi ~/bin/gcal.sh
> #!/bin/sh
>
> gcalcli --conky calw 2 |
> sed -e 's/^[(0\x71^[(B/?/g' \
> -e 's/^[(0\x78^[(B/?/g' \
> -e 's/^[(0\x6A^[(B/?/g' \
> -e 's/^[(0\x6B^[(B/?/g' \
> -e 's/^[(0\x6C^[(B/?/g' \
> -e 's/^[(0\x6D^[(B/?/g' \
> -e 's/^[(0\x6E^[(B/?/g' \
> -e 's/^[(0\x74^[(B/?/g' \
> -e 's/^[(0\x75^[(B/?/g' \
> -e 's/^[(0\x76^[(B/?/g' \
> -e 's/^[(0\x77^[(B/?/g'
$ chmod +x ~/bin/gcal.sh
**重要提醒**:上面脚本中的 ^[ 必须是**真正的 ESCAPE 键**( 也就是说在 vi 中按 Ctrl-V 然后按 Esc )。
这个脚本程序将 VT100 转义序列转成Unicode组件图字符。这是[必须的一步][10],因为 Conky 不支持 gcalcli使用的 ASNII 的艺术线条。
最后,在你的家目录中创建下面的 Conky 的配置文件。
$ vi ~/.conkyrc
> alignment top_right
> maximum_width 630
> minimum_size 330 10
> gap_x 25
> gap_y 50
>
> own_window yes
> own_window_type conky
> own_window_hints undecorated,below,sticky,skip_taskbar,skip_pager
> own_window_transparent yes
> own_window_argb_visual yes
> own_window_argb_value 0
>
> update_interval 300
> background no
>
> border_width 1
> default_color cornflowerblue
> default_outline_color white
> default_shade_color white
> double_buffer no
> draw_borders no
> draw_graph_borders no
> draw_outline no
> draw_shades no
> max_port_monitor_connections 64
> max_specials 512
> max_user_text 16384
> text_buffer_size 8096
> no_buffers yes
> out_to_console no
> uppercase no
> use_xft yes
> xftfont Bitstream Vera Sans Mono:size=10
>
> TEXT
> *** Google Calendar Agenda ***
> ${execpi 300 gcalcli --conky agenda}
> ${execpi 300 ~/bin/gcal.sh}
这个 Conky 配置文件会直接在你的桌面主题上显示你的Google Calendar 的一个日程表和一个有两个星期的时间表。
现在,你可以运行下面的命令激活 Conky。
$ conky
你应该可以在Linux桌面的右边看到 Google Calendar。
[![](http://farm8.staticflickr.com/7390/11216377436_72d00cec49_z.jpg)][11]
确认 Google Calendar 可以正常运行后你可以将Conky 设为在每次登录时自动启动。
### 设置Google Calendar 提醒 ###
gcalcli 也可以为Google Calendar 中即将到来的事件发送一个提醒。它使用 notify-send 命令。对于Google Calendar 提醒,你可以像下面一样设置一个例行性工作。
$ crontab -l
> */10 * * * * /usr/local/bin/gcalcli remind
--------------------------------------------------------------------------------
via: http://xmodulo.com/2013/12/integrate-google-calendar-linux-desktop.html
译者:[Linchenguang](https://github.com/Linchenguang) 校对:[校对者ID](https://github.com/校对者ID)
本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创翻译,[Linux中国](http://linux.cn/) 荣誉推出
[1]:https://github.com/insanum/gcalcli
[2]:http://conky.sourceforge.net/
[3]:http://www.flickr.com/photos/xmodulo/11216331146/
[4]:http://www.flickr.com/photos/xmodulo/11216308465/
[5]:https://cloud.google.com/console
[6]:http://www.flickr.com/photos/xmodulo/11216363656/
[7]:http://www.flickr.com/photos/xmodulo/11216593546/
[8]:http://www.flickr.com/photos/xmodulo/11216465043/
[9]:http://xmodulo.com/2013/12/install-configure-conky-linux.html
[10]:https://github.com/insanum/gcalcli/issues/97
[11]:http://www.flickr.com/photos/xmodulo/11216377436/