You are not logged in.

#1 2010-05-28 20:10:32

Greenstuff
Member
From: Israel
Registered: 2009-06-30
Posts: 64

[Solved] Trying to get conky to display hebrew right...

ok,
So i've been using ${mpd_status} to display my songs on conky. However, some of my song's names are in hebrew, and hebrew has this problem that the terminal (and conky) display it the other way around. For exaple, hebrew word abc (a,b,c are hebrew letters) are displaed cba. So, I wrote 2 scripts: One to reverse the hebrew so on the terminal it looks "ok" (If it sounds rediculus to you, that's the way we get around the hebrew problem on computers, we've been doing it since computers were invented), and another to get the song's name and feed it to the first script.

So, after all this work, I managed to make the scripts display hebrew song names on the terminal perfectly. However, conky refuses to show my song names. English eongs work fine, hebrew songs are just not displayed. This leads me to believe there's a problem. I was wondering if the kind people of the forum can help?

PS I realize this is in the gray area between programming and help. That's why I put it in here. If the admins think there's a better place for it, please move this tread, thank you.

revHebrew.py

#!/usr/bin/python
# This script takes a sentence as an argument and reverses all hebrew so it's
# displayed right in the terminal and in conky. 
# USAGE: revHebrew.py [word1] [word2] [...]

import sys

ENGLISH_LETTERS = []
UPPER_CASE_START_INDEX = 65
LOWER_CASE_START_INDEX = 97
NUMBER_OF_LETTERS_IN_ENGLISH = 26
ENCODING = "utf-8"
args = sys.argv[1:]

def inEnglish(word):
    letters = list(word)
    for letter in letters:
        if letter in ENGLISH_LETTERS:
            return True
    return False

def generateEnglishLetters():
    global ENGLISH_LETTERS
    ENGLISH_LETTERS = map(chr, range(UPPER_CASE_START_INDEX,
        UPPER_CASE_START_INDEX + NUMBER_OF_LETTERS_IN_ENGLISH) +
        range(LOWER_CASE_START_INDEX,LOWER_CASE_START_INDEX +
            NUMBER_OF_LETTERS_IN_ENGLISH))
   
def reverseWord(word):
    return word[::-1]

def reverseSentence(sentence):
    ltrSubsentence = []
    orderedSentence = []
    for word in sentence:
        if not inEnglish(word):
            ltrSubsentence.insert(0,word)
        else:
            ltrSubsentence.append(word)
            orderedSentence += ltrSubsentence
            ltrSubsentence = []
    orderedSentence += ltrSubsentence
    return orderedSentence

def main():
    generateEnglishLetters()
    sentence = []
    for word in args:
        word = unicode(word, ENCODING)
        if not inEnglish(word):
            word = reverseWord(word)
        sentence.append(word)
    print u' '.join(reverseSentence(sentence))
    
if __name__ == "__main__":
    main()

hebrewMPDstatus.sh

#!/bin/bash
# A script to display hebrew and english songs from MPD in the right way
# USAGE: hebrewMPDstatis.sh 
Title=`sonata info | grep Title: | cut -c8-`
Artist=`sonata info | grep Artist: | cut -c9-`
Song="$Title - $Artist"
Command="python revHebrew.py ${Song}"
eval $Command

my .conkyrc

#override_utf8_locale no
format_human_readable yes
double_buffer yes
alignment top_middle
background yes
border_width 0
cpu_avg_samples 2
default_color white
default_outline_color white
default_shade_color white
draw_borders no
draw_graph_borders yes
draw_outline no
draw_shades no
use_xft yes
#xftfont Miriam Mono CLM:size=10
xftfont Sans:size=10
gap_x 0
gap_y 0
minimum_size 1672 0
maximum_width 1672 0
net_avg_samples 2
no_buffers yes
out_to_console no
out_to_stderr no
extra_newline no
own_window yes
own_window_class Conky
own_window_type desktop
own_window_transparent no
own_window_hints undecorated,below,skip_taskbar,skip_pager,sticky
stippled_borders 0
update_interval 1.0
uppercase no
use_spacer yes
show_graph_scale no
show_graph_range no
text_buffer_size 2048
TEXT
$nodename - $sysname $kernel on $machine :: ${color grey}Uptime:$color $uptime :: ${color grey}Frequency:$color $freq_g GHz :: ${color grey}Processes:$color $processes  ${color grey}Running:$color $running_processes :: Net: Up:$color ${upspeed wlan0} ${color grey} Down:$color ${downspeed wlan0} :: ${color gray} Heat$color: Core0: ${font mpd:style=Bold:color=white:size=10}${execi 8 sensors | grep -A 1 'Core 0' | cut -c15-16 | sed '/^$/d'}C${font} Core1: ${font mpd:style=Bold:color=white:size=10}${execi 8 sensors | grep -A 1 'Core 1' | cut -c15-16 | sed '/^$/d'}C${font} temp: ${font mpd:style=Bold:color=white:size=10}${execi 8 sensors | grep -A 1 'temp1' | cut -c15-16 | sed '/^$/d'}C${font} :: ${font Miriam Mono CLM:style=Bold:size=10}${color lightblue}${execi 1 ~/hebrewMPDstatus.sh} - $mpd_status ${mpd_elapsed} ${color grey} ${mpd_bar 10}${color} 
#RAM Usage:$color $mem/$memmax - $memperc% ${membar 4} ${color grey}Swap Usage:$color $swap/$swapmax - $swapperc% ${swapbar 4} ${color grey}CPU Usage:$color $cpu% ${cpubar 4}

Additional info: Unless I made a mistike, the script's output should be utf8. I looked around and apperantly sometimes the font's at fault so I decided to try a hebrew font, but no luck.



SOLVED: Ok, solved my own problem. I saw this error:

UnicodeEncodeError: 'ascii' codec can't encode character u'\xa0' in position 0: ordinal not in range(128)

and decided to invastigate it. It lead me to the following page: http://stackoverflow.com/questions/4924 … -in-python
Basiclly turns out python's print command outputs in ASCII. I modified my main as instructed in the page, to change the default encoding to utf-8 and it did the trick!
Another thing I had to do in my .conkyrc was to set "override_utf8_locale yes" in the config. I now have working hebrew in my conky! I hope others will find this post in the future and be saved the trouble.

Last edited by Greenstuff (2010-05-29 00:06:20)

Offline

#2 2013-05-27 04:49:51

Ba7a7chy
Member
Registered: 2013-05-04
Posts: 35

Re: [Solved] Trying to get conky to display hebrew right...

Can you share you Conky ? I would love an Hebrew one smile

Offline

#3 2013-05-27 05:22:41

bohoomil
Member
Registered: 2010-09-04
Posts: 2,376
Website

Re: [Solved] Trying to get conky to display hebrew right...

Did you see the date of the edit?

Last edited by Greenstuff (2010-05-29 02:06:20)


:: Registered Linux User No. 223384

:: github
:: infinality-bundle+fonts: good looking fonts made easy

Offline

#4 2013-05-27 07:17:01

jasonwryan
Forum & Wiki Admin
From: .nz
Registered: 2009-05-09
Posts: 19,364
Website

Re: [Solved] Trying to get conky to display hebrew right...


Arch + dwm   •   Mercurial repos  •   Github

Registered Linux User #482438

Offline

Board footer

Powered by FluxBB