Some of my scripts for daily use on a linux desktop

Sunday, January 31, 2010

How to get random pictures from deviantArt (get_deviation.sh v1.0)

As I was a bit boring to see always the sames pictures from my hard drive with my conky script "Photo Album Stack", I tried to get some other pictures from the web.

Picasa as an interesting Slideshow tool.
If you open just this page in a browser (epiphany for example), you have to set the folder of the cache
/home/wlourf/.gnome2/epiphany/mozilla/epiphany/Cache in the script and that's it.
But pictures on Picasa are not really interesting, isn't it?

DeviantArt has also a random tool but whithout slideshow, so you have to click to display images ...
I wrote this script (get_deviation.sh) that go to the random page and save the image (in fullsize) to the hard disk. This one can be improved because regular expressions are not my favorite toy!
Next, I will try to do the same for pictures from one single category.

Before running the script you have to set the folder variable in it.

This script can also be downloaded here.


In a few days, I will post the last version of the Photo Album Script which will run with this script.


En français (soyons fous)!
Ceci est un script qui enregistre des images aléatoires du site deviantArt sur son PC. Pour être utilisé, il faut paramétrer la variable folder au début du script.


The script : get_deviation.sh

#! /bin/bash
#This script get a random image from deviant art website and save it to hard disk!
#
# by wlourf http://u-scripts.blogspot.com/
# v1.0 - 31 Jan. 2010
#
#argument 1 (optional) is the path+filename where to save the image
#if argument 1 is not present, image will be saved in $folder
#
#other paramaters are set here
file1=/tmp/get_random.txt
file2=/tmp/get_image.txt
folder=~/deviant

############################# end ###########################

#get a random url
GET http://www.deviantart.com/random/deviation > $file1

#extract the link to the deviation page
match="<input type="\" name="\" value="\" begin="http" end="\">"

a=$(($(expr "$url_line" : ".*$begin")-${#begin}))
b=$(($(expr "$url_line" : ".*$end")-$a-${#end}))

url_page=${url_line:$a:$b}

#echo "deviation--> "$url_page

#get the deviation page
GET $url_page > $file2

#extract the link to the fullview image
match="fullview"
url_line=""

while read line
do
  if [[ "$line" =~ "${match}" ]]; then
    url_line=$line
    break
  fi
done < $file2

begin="src\":\""
end="\"},\"smallview"

b=$(($(expr "$url_line" : ".*$end")-${#end}))
url2=${url_line:0:$b}

a=$(($(expr "$url2" : ".*$begin")))
url_img=${url2:$a}

#save image to hard disk if url ok
if [[ $url_img != "" ]]; then
  cd $folder
  if [[ $1 != "" ]]; then
    wget $url_img -O $1
  else
    wget $url_img
  fi
fi



If you want the script to run in a loop, just write in another script:

while true
do
  ./get_deviation.sh
done

Tuesday, January 19, 2010

Calendar wheel


Well, as I explore the conky a little bit deeper, I am very amazing of things we can draw with some lines of codes.
Last week I tried the Conky Contest of the Month with this "Calendar Wheel". We were only two guys to participate (too bad) but you can vote for my calendar if you like the conky I will now explain !! Edit: I won coool !

This script simply draw a circular calendar on the left side of the screen (I didn't try on the right side as text alignment is not easy with cairo).

The most difficult part of this script was to rotate the dates because cairo doesn't allow that: the trick was to draw each date on a separate image, rotate the image and then render the rotated image on the screen.
Customization can be done with colors, height and width and some text can be added (depending on the date) on the left side of the arc.

This is what I've done for the contest (and for learning myself Lua) !

After that, I added some improvements in version 1.1 :
- today's date can now be set anywere in the arc (not on only the horizontal line) : yoffset
- today's date can now have an offset (positive or negative) : xoffset
- the main thing is that the calendar is draw only at the start of the conky and when the date change (i.e. the calendar is saved in a PNG file and this is this file that will be displayed in the conky) or if the PNG file is deleted : so the conky become really really fast ...

And in version 1.2, the calendar can be drawn on the right side of the conky.

The script can be downloaded from ubuntu forums here.

Edit : how to set date in local language:
Here is what I've done for having dates according to my locale settings:
It your conkyrc, in the TEXT section, write
${time}
If you want to hide this date ,
use_xft yes
xftalpha 0
default_color 000000

It seems it works only for the black color .
I didn' manage to do that in Lua only

Happy Conkying !


More screenshots :




There is also a gallery on picasa

Sunday, January 10, 2010

Shaded clock widget


This is my attempt to draw a eye-candy clock using cairo and conky.
I draw some examples on the picture with the parameters used.
Effects are nice but code need to be optimized.

Edit : I updated my "shadowed clock" to a "clock shaded", (is this more english ?). It's now easy to use because it's a widget that can be cut/paste in a Lua script.
Again, it can be downloaded from ubuntu forums .

Sunday, January 3, 2010

Photo Album Stack


Hi,

This is my first attempt to use lua bindings in conky (> 1.7.2).
This script is based on londonali's Photo Album Script but it can display than more one image at a time and in a more messy way (if configured to).

In the conkyrc, don't forget the blank line after TEXT
To start with an empty photo album, delete the file created by the script :

rm /tmp/img.png & conky -c ~/scripts/conkyrc-album-stack &

Some improvments made in version 1.1 :
- little images are no more enlarged
- the filename of the image can be written in the frame or/and elsewhere in the conky.
- gray shadow on the bottom right side of each image can be added
(this is optional but has to be improved : the shadow has to be "blur" and shadows don't work for big pictures)
It can be used with the script get_deviation.sh (see this post) or any other script that get a random image from the web.


The scripts can be downloaded from ubuntu forums.

Another screenshot :



En français, soyons fous! Ce script affiche des images de son disque dur sur votre conky dans une façon un peu bordélique. Les dernières modifications sont :
- les petites images ne sont plus agrandies
- le nom de l'image peut être affiché dans le cadre ou n'importe où dans la fenêtre du conky
- une sorte d'ombre peut être ajoutée mais ceci devra être amélioré (il n'y a pas d'effet de flou et ça ne fonctionne pas bien pour les grandes images)
- le script peut être utilisé avec un autre script qui génère des images aléatoires comme get_deviation.sh que j'ai posté il y a quelques jours


Happy conkying!