You are not logged in.

#1 2013-01-05 16:31:56

vrooom
Member
Registered: 2013-01-03
Posts: 2

HOWTO: Conky & Kanji

Hello everyone!

This is my first post on the forum and I'm pretty new to Arch (I use FreeBSD on my other box). After watching some Japanese anime (particularly Ghost in the Shell smile ), I decided to take a first step in learning Japanese language. After (almost) mastering kana, I decided to speed up Kanji learning process and make it more easy. I found an interesting site (http://www.kanji-a-day.com/), so I used it in my Bash script to get a new Kanji every day.

Here is the script kanji.sh:

#!/bin/bash

function newLine {
	for ((i=0; i<$1; i++))
	do
        	printf "\n"
	done
}

# conky variables (fonts and colors)
FONT1='Droid Sans Fallback:size=32:bold'	# kanji font
FONT2='Droid Sans Fallback:size=8'              # font for help stings
FONT3='Droid Sans Fallback:size=8:bold'         # font for readings
COLOR1="#1692d0"				# kanji color
COLOR2="#1692d0"				# color for help strings
COLOR3="#ffffff"				# font for readings
NLBEFORE=0					# new line(s) before conky line
NLAFTER=1					# new line(s) after conky line

# set kanji level (1-4), default level is 3
LEVEL="3"

# kanji level can be passed to the script
if [ ! $1 == "" ]; then
	if [ $1 == "1" ] ||
	   [ $1 == "2" ] ||
	   [ $1 == "3" ] ||
	   [ $1 == "4" ]; then
		LEVEL=$1
	fi
fi

# web page URL
URL="http://feeds.feedburner.com/Kanji-a-dayLevel"$LEVEL"?format=xml"

# get important lines of the web page
TEMP=$(wget -qO- $URL | sed '16,18!d' | iconv -f EUC-JP -t UTF-8)

# format strings
KANJI=${TEMP#*"<title>"}
TEMP=$KANJI
KANJI=${TEMP%%"</title>"*}
KANJI=${KANJI//" "/""}

ONREADING=${TEMP#*"on readings: "}
TEMP=$ONREADING
ONREADING=${TEMP%%"kun readings: "*}
ONREADING=${ONREADING//"&lt;br&gt;"/""}

KUNREADING=${TEMP#*"kun readings: "}
TEMP=$KUNREADING
KUNREADING=${TEMP%%"meaning(s): "*}
KUNREADING=${KUNREADING//"&lt;br&gt;"/""}
KUNREADING=${KUNREADING//"."/""}

MEANING=${TEMP#*"meaning(s): "}
TEMP=$MEANING
MEANING=${TEMP%%"img src"*}
MEANING=${MEANING//"&lt"/""}
MEANING=${MEANING:0:${#MEANING}-1}

# print empty line(s) before conky line
newLine $NLBEFORE

# print conky lines
if [ ${#KUNREADING} == 0 ]; then
	# without kun reading and romaji
	MEANING=${MEANING:0:${#MEANING}-1}
	printf "\${color $COLOR1}\${font $FONT1}\${alignc}$KANJI\${color}\n\${color $COLOR2}\${font $FONT2}On reading:\${color}\${color $COLOR3}\${alignr}\${font $FONT3}$ONREADING\${color}\n\${color $COLOR2}\${font $FONT2}Meaning:\${color}\${color $COLOR3}\${alignr}\${font $FONT3}$MEANING\${color}\n"
else
	# with romaji
	ROMAJI=$(echo $MEANING | awk -F"; " '{print $NF}')
	MEANING="${MEANING%;*}"
	printf "\${color $COLOR1}\${font $FONT1}\${alignc}$KANJI\${color}\n\${color $COLOR2}\${font $FONT2}On reading:\${color}\${color $COLOR3}\${alignr}\${font $FONT3}$ONREADING\${color}\n\${color $COLOR2}\${font $FONT2}Kun reading:\${color}\${color $COLOR3}\${alignr}\${font $FONT3}$KUNREADING\${color}\n\${color $COLOR2}\${font $FONT2}Romaji:\${color}\${color $COLOR3}\${alignr}\${font $FONT3}$ROMAJI\${color}\n\${color $COLOR2}\${font $FONT2}Meaning:\${color}\${color $COLOR3}\${alignr}\${font $FONT3}$MEANING\${color}\n"
fi

# print empty line(s) after conky line
newLine $NLAFTER

If you want to change font or the color of the output, just edit variables $FONT1-3 and $COLOR1-3. Variables $NLBEFORE and $NLAFTER are used to print number of empty lines before and after a conky line. There are 4 levels of Kanji, so you can pass an argument 1, 2, 3 or 4 according to the desired level of Kanji.

Don't forget to:

chmod +x kanji.sh

Here is an example of the conky config file kanji with all 4 levels of Kanji. I keep my conky file kanji and kanji.sh script in $HOME/.conky directory:

update_interval 5
total_run_times 0
net_avg_samples 1
cpu_avg_samples 1
if_up_strictness link
imlib_cache_size 0
double_buffer yes
no_buffers yes
format_human_readable
use_xft yes
xftfont Ubuntu:size=8
override_utf8_locale yes
text_buffer_size 2048
own_window_class Conky
own_window yes
own_window_type normal
own_window_argb_visual yes
own_window_argb_value 180
own_window_transparent yes
own_window_hints undecorated,below,sticky,skip_taskbar,skip_pager
alignment top_left
gap_x 25
gap_y 40
minimum_size 300 600
maximum_width 300
default_bar_size 60 8
draw_shades no
default_cccccc
color1 black
TEXT
${if_up wlan0}
${color1}${voffset -4}${font Ubuntu:style=Bold:size=8}LEVEL 1 $hr${font}
${execpi 3600 $HOME/.conky/kanji.sh 1}
${color1}${voffset -4}${font Ubuntu:style=Bold:size=8}LEVEL 2 $hr${font}
${execpi 3600 $HOME/.conky/kanji.sh 2}
${color1}${voffset -4}${font Ubuntu:style=Bold:size=8}LEVEL 3 $hr${font}
${execpi 3600 $HOME/.conky/kanji.sh 3}
${color1}${voffset -4}${font Ubuntu:style=Bold:size=8}LEVEL 4 $hr${font}
${execpi 3600 $HOME/.conky/kanji.sh 4}
${else}${if_up eth0}
${color1}${voffset -4}${font Ubuntu:style=Bold:size=8}LEVEL 1 $hr${font}
${execpi 3600 $HOME/.conky/kanji.sh 1}
${color1}${voffset -4}${font Ubuntu:style=Bold:size=8}LEVEL 2 $hr${font}
${execpi 3600 $HOME/.conky/kanji.sh 2}
${color1}${voffset -4}${font Ubuntu:style=Bold:size=8}LEVEL 3 $hr${font}
${execpi 3600 $HOME/.conky/kanji.sh 3}
${color1}${voffset -4}${font Ubuntu:style=Bold:size=8}LEVEL 4 $hr${font}
${execpi 3600 $HOME/.conky/kanji.sh 4}
${else}${if_up ppp0}
${color1}${voffset -4}${font Ubuntu:style=Bold:size=8}LEVEL 1 $hr${font}
${execpi 3600 $HOME/.conky/kanji.sh 1}
${color1}${voffset -4}${font Ubuntu:style=Bold:size=8}LEVEL 2 $hr${font}
${execpi 3600 $HOME/.conky/kanji.sh 2}
${color1}${voffset -4}${font Ubuntu:style=Bold:size=8}LEVEL 3 $hr${font}
${execpi 3600 $HOME/.conky/kanji.sh 3}
${color1}${voffset -4}${font Ubuntu:style=Bold:size=8}LEVEL 4 $hr${font}
${execpi 3600 $HOME/.conky/kanji.sh 4}
${else}
${voffset 4}${offset 4}${color1}${font Wingdings:size=20}N${font}${color1}${voffset -6}${goto 32}Network Unavailable${voffset 14}${endif}${endif}${endif}

Here is the screenshot: http://i49.tinypic.com/359d5b8.png

Good luck and have fun learning Japanese! smile

Edit:
Heikete, thanks for the tip! smile

Last edited by vrooom (2013-02-19 16:13:42)


"Your effort to remain what you are is what limits you."

Offline

#2 2013-01-08 00:51:30

eqyiel
Member
From: Australia
Registered: 2011-09-29
Posts: 9

Re: HOWTO: Conky & Kanji

This is pretty creative and cool.  I'm also studying Kanji on Arch Linux, using Heisig's "Remembering the Kanji" volumes 1-3; community/anki (SRS) and Koohii (memnonics).  Denshi Jisho is great, too.  Good luck on your journey!

Offline

#3 2013-01-19 14:08:19

Heikete
Member
Registered: 2007-04-28
Posts: 37

Re: HOWTO: Conky & Kanji

It is better to replace execp with execpi to make it more stable.

${execpi 3600 $HOME/.conky/kanji.sh 2}

Offline

Board footer

Powered by FluxBB