Sharp Monkey, Dull Keyboard

A blog about Bitcoin, Programming, Guinea Pigs, and other technical things.

My Complicated Conky Configuration (an update)

May 24, 2014 — Matt Traudt
Tags: Conky, Script/Function, Bash, Whatpulse

I've seen some interest in finding out more about my current conky configuration and how to recreate it. Well in this post I will describe it as fully as I can. Sorry for the wait, those of you that were interested.

For starters, I grabbed the large conky theme pack found here and stored the scripts in ~/Documents/scripts/conky-themes (not important, but it allowed me to symbolically link ~/.conkyrc to whatever them I wanted). Though it probably isn't a big deal since I re-did 90% of it, I did all this before the author updated his theme pack in April 2014. I then took the transparent + god-mode combination tweaked it around, and decided to redesign it for my liking when I found the config file jumping all over the place and I was having a hard time positioning things. I think to stop myself from rambling too much, I'll just start posting config files and try to explain them as I go. I want to apologize now for not using consitent file naming schemes or scripting conventions.

.conkyrc

Too long to post. Click here to download and look at it. I'd open it in a text editor with line numbers as I will reference them often. When you download it, it has a dot in front of it so it might be hidden!

Some background. I keep all the supporting scripts, images, etc. in ~/.conky-help/. Temporary information is stored in ~/.cache/ such as weather information or the number of unread emails. Conky's config is ~/.conkyrc.

So let's start at the top and move along until we run across something that looks like a supporting script that I need to tell you about.

updateWeather.sh
#!/bin/bash
curl -s "http://weather.yahooapis.com/forecastrss?w=2355844&u=f" -o $1

Replacing 2355844 and f with your WOEID (go here and search your zip code, the WOEID will be the last number in the URL) and the unit for temperature you prefer. As you can see on line 59 of .conkyrc, the result is output in ~/.cache/weather.xml.

reload-forecast-pics.sh

#!/bin/bash
cp -f ~/.conky-help/icons/weather-icons-light3/$(grep "yweather:forecast" ~/.cache/weather.xml | grep -o "code=\"[^\"]*\"" | grep -o "\"[^\"]*\"" | grep -o "[^\"]*" | awk 'NR==1').png ~/.cache/weather-1.png
cp -f ~/.conky-help/icons/weather-icons-light3/$(grep "yweather:forecast" ~/.cache/weather.xml | grep -o "code=\"[^\"]*\"" | grep -o "\"[^\"]*\"" | grep -o "[^\"]*" | awk 'NR==2').png ~/.cache/weather-2.png
cp -f ~/.conky-help/icons/weather-icons-light3/$(grep "yweather:forecast" ~/.cache/weather.xml | grep -o "code=\"[^\"]*\"" | grep -o "\"[^\"]*\"" | grep -o "[^\"]*" | awk 'NR==3').png ~/.cache/weather-3.png

Every time this script is run, a picture representing the next three days' weather conditions will be forcibly copied from the local stash of pictures you have in ~/.conky-help/ to the ~/.cache/ directory. This way, .conkyrc can always reference the same file name, but the image will change every now and then.

updateTotalWpStats.sh

#!/bin/bash
curl -s "http://api.whatpulse.org/user.php?user=pointychimp&formatted=yes" -o $1

Another single command script. If you don't use whatpulse to track your typing, mouse, and bandwidth usage patterns, then comment out the whatpulse-reated sections. Anyway, replace pointychimp with your whatpulse user name. As you can see on line 62 of .conkyrc, your statistics are stored in ~/.cache/wpTotalStats.xml.

updateCurrentWpStats.sh

#!/bin/bash
sqlite3 -csv ~/.local/share/data/WhatPulse/whatpulse.db "SELECT * FROM unpulsed_stats" > $1

Another whatpulse-related command called on line 63. This one pulls local, current, unpulsed stats from your local database and stores the output in ~/.cache/wpCurrentStats.txt.

unread-gmail.py

import imaplib
obj = imaplib.IMAP4_SSL('imap.gmail.com','993')
obj.login('your.email@gmail.com','yourEmailpassword!')
obj.select()
obj.search(None,'UnSeen')
print len(obj.search(None, 'UnSeen')[1][0].split())

Warning: I know basically no python and have only tested this to work with gmail. But I know enough to copy/paste some code from the internet and get this as the result. This script is called on line 65 and appends the resulting integer in ~/.cache/unreadmail. The reason for this is otherwise I had moments when no integer was displayed while conky waited for the script to finish fetching. To stop ~/.cache/unreadmail from getting too large, line 66 of .conkyrc clears it up every hour.

updateScrobbledMusic.sh

#!/bin/bash
TMPFILE=/tmp/scrobbledmusic.txt
curl -s http://ws.audioscrobbler.com/1.0/user/SirMatt2013/recenttracks.rss | grep "<title>" | grep -v "<docs>" | sed 's/<title>//g' | sed 's/<\/title>//g' > $TMPFILE
cp $TMPFILE $1

Called on line 68, this script pulls info from last.fm about your recently listend music. Similar situation with this one as the unread email problem. Conky sometimes worked too fast and didn't wait long enough for the inforamation to be updated in ~/.cache/scrobbledMusic.txt. So my solution was to have curl output into a super temporary file and then have the script quickly copy the latest info over to the file conky is expecting it to be in.

Lines 72-84 display horizontal and vertical bars between sections. There seems to be a typo on one of the final comments or something. I'm pretty sure the last comment should explain that the last image is between the disk info and the scrobbled tracks. 88-95 put weather pictures in their places. Line 99 takes care of the time and diplays the unread emails with a gramatical check for singular/plural.

Line 101 uses curl to pull current bitcoin price data from my personal database service. You should know that I'm planning on redesigning it and don't guarantee it will stay up. If you are into bitcoin and want current price data in conky, you should see if you can pull from the exchanges directoy. If you still would like to use mine while it is around, go here and mess around until you get the data displayed how you want, then copy the URL.

nowplaying.sh

The fact that there's a newline character in the file is stopping markdown from understanding what to do with this source. Get it here.

On line 102 we see another new script, ~/.conky-help/nowplaying.sh. I use clementine for my music listening, so don't expect this to work out of the box with any other music player.

getweather.sh

#!/bin/bash

[[ $1 == "temp"      ]] && echo $(grep "yweather:condition"  ~/.cache/weather.xml | grep -o "temp=\"[^\"]*\""     | grep -o "\"[^\"]*\"" | grep -o "[^\"]*")
[[ $1 == "pressure"  ]] && echo $(grep "yweather:atmosphere" ~/.cache/weather.xml | grep -o "pressure=\"[^\"]*\"" | grep -o "\"[^\"]*\"" | grep -o "[^\"]*") 
[[ $1 == "humidity"  ]] && echo $(grep "yweather:atmosphere" ~/.cache/weather.xml | grep -o "humidity=\"[^\"]*\"" | grep -o "\"[^\"]*\"" | grep -o "[^\"]*")
[[ $1 == "wind"      ]] && echo $(grep "yweather:wind"       ~/.cache/weather.xml | grep -o "speed=\"[^\"]*\""    | grep -o "\"[^\"]*\"" | grep -o "[^\"]*")
[[ $1 == "condition" ]] && echo $(grep "yweather:condition"  ~/.cache/weather.xml | grep -o "text=\"[^\"]*\""     | grep -o "\"[^\"]*\"" | grep -o "[^\"]*")

[[ $1 == "forecastday1" ]] && echo $(grep "yweather:forecast" ~/.cache/weather.xml | grep -o "day=\"[^\"]*\"" | grep -o "\"[^\"]*\"" | grep -o "[^\"]*" | awk 'NR==1' )
[[ $1 == "forecastday2" ]] && echo $(grep "yweather:forecast" ~/.cache/weather.xml | grep -o "day=\"[^\"]*\"" | grep -o "\"[^\"]*\"" | grep -o "[^\"]*" | awk 'NR==2' )
[[ $1 == "forecastday3" ]] && echo $(grep "yweather:forecast" ~/.cache/weather.xml | grep -o "day=\"[^\"]*\"" | grep -o "\"[^\"]*\"" | grep -o "[^\"]*" | awk 'NR==3' )

[[ $1 == "forecasttemp1" ]] && echo $(grep "yweather:forecast" ~/.cache/weather.xml | grep -o "low=\"[^\"]*\"" | grep -o "\"[^\"]*\"" | grep -o "[^\"]*" | awk 'NR==1')° / $(grep "yweather:forecast" ~/.cache/weather.xml | grep -o "high=\"[^\"]*\"" | grep -o "\"[^\"]*\"" | grep -o "[^\"]*" | awk 'NR==1')°
[[ $1 == "forecasttemp2" ]] && echo $(grep "yweather:forecast" ~/.cache/weather.xml | grep -o "low=\"[^\"]*\"" | grep -o "\"[^\"]*\"" | grep -o "[^\"]*" | awk 'NR==2')° / $(grep "yweather:forecast" ~/.cache/weather.xml | grep -o "high=\"[^\"]*\"" | grep -o "\"[^\"]*\"" | grep -o "[^\"]*" | awk 'NR==2')°
[[ $1 == "forecasttemp3" ]] && echo $(grep "yweather:forecast" ~/.cache/weather.xml | grep -o "low=\"[^\"]*\"" | grep -o "\"[^\"]*\"" | grep -o "[^\"]*" | awk 'NR==3')° / $(grep "yweather:forecast" ~/.cache/weather.xml | grep -o "high=\"[^\"]*\"" | grep -o "\"[^\"]*\"" | grep -o "[^\"]*" | awk 'NR==3')°

Lines 106-120 call ~/.conky-help/getweather.sh over and over again, passing different key words to it each time in order to tell it to get different things out of ~/.cache/weather.xml.

In the process section starting on line 124 I start out using a lot of conky's built in functions for creating the lists of top processes.

getCpuInfo.sh

#!/bin/bash

CORE=$1
echo $(echo "scale = 2; $(cat /sys/devices/system/cpu/cpu$CORE/cpufreq/cpuinfo_cur_freq) / 1000000" | bc)GHz

On line 136 I use this script to pull cpu frequency information from linux and diplay it in a pretty way. When I first was trying to get this to work, I had to give my user account permission to access the /sys/devices/system/ directory (or something along those lines), and the permissions got reset with every reboot. Lately, however, I haven't had that problem and it works just fine from the get-go. So if this doesn't work for you, check to see if permissions are the cuprit.

The network section starting on line 146 is entirely built-in conky commands with some fancy if/else statements. As you can see in the screenshot of how conky looks at the time of writing, I don't always have all the VPNs running that I did when I worked on this, so I am wasting some space with all the tunnels being listed like that. If your network devices have different names or you don't use any VPNs, don't hesitate to remove some of this section.

The whatpulse section starting on line 175 calls two different scipts in order to display your information. ~/.conky-help/getTotalRankWpStat.pl diplays total and rank information that we pulled from whatpulse.org earlier. It is also written in pearl, but unlike the pythong script higher up, I wrote this basically from scratch even though I know even less about pearl. ~/.conky-help/getCurrentWpStat.sh is a good 'ol bash that displays current, unpulsed statistics that we got from the database earlier.

getTotalRankWpStat.pl

Too long to post, click here.

getCurrentWpStat.sh

#!/bin/bash

FILENAME=$1
STAT=$2

STAT=$(echo $STAT | tr '[:upper:]' '[:lower:]')

VALUE=$(cat $FILENAME | grep $STAT | sed 's/[^0-9]*//')

[[ $STAT == "keys"     ]] && VALUE=$(echo $VALUE | ~/.conky-help/commify.sh)
[[ $STAT == "clicks"   ]] && VALUE=$(echo $VALUE | ~/.conky-help/commify.sh)
[[ $STAT == "download" ]] && VALUE=$(~/.conky-help/bytes2readable.sh $VALUE 2)
[[ $STAT == "upload"   ]] && VALUE=$(~/.conky-help/bytes2readable.sh $VALUE 2)
[[ $STAT == "uptime"   ]] && VALUE=$(~/.conky-help/secs2readable.sh $VALUE)

echo $VALUE

Pretty straight forward, and pretty pretty too! The __2readable.sh scripts can be found here: bytes2readable.sh secs2readable.sh. The commify.sh script is here.

The storage section starting on line 201 uses built-in conky commands to display some disk statistics. If you're wondering why my ssd and "hdd1" have the same stats in the picture, it is because I used to have a 1TB drive mounted as /home. Now that /home is "temporarily" on my ssd, the two lines in the picture have the same stats until I get around to commenting out the right lines in ~/.conkyrc.

Finally, the last two lines display the songs I've recently listened to according to last.fm. They simply output ~/.cache/scrobbledMusic.txt that we created many scripts ago.

Final Words

I would be very suprised if you got this working the very first time you try. Also, tips for continuing my work to make conky your own.

  • Try running scripts from the command line directly if you don't think they're working. The "updating" scripts may output some helpful information about why the couldn't update something. The "fetching" or "getting" scripts output to stdout so you can see what they're saying directly.
  • This config was very much talored to me and my setup. If you don't use whatpulse, last.fm, or clementine, then you'll be leaving out like half of the final product. Or if you don't want three tunnels displayed in the network section, you'll have to add in some dead space to make sure things stay aligned correctly. I hope seeing this and maybe even trying it out is a learning experience for you if nothing more.
  • http://conky.sourceforge.net/variables.html is a good place to start to learn about conky's built-in awesomeness
  • http://google.com

If you want to contact me for thanks, complaints, spelling corrections, or suggestions, please do so at conkyhelp@mineoas.us. If you want to send a few bits my way, point your wallet towards 1G6SYPKeTWq45JCBKJHvaA1NbED8LfDaUR.