Topic: Help me write a fun script for my wallpaper project!

Hi!  I've used this page's script to make OpenBox load a random wallpaper every few minutes.  It works great.

I'm a zooarchaeologist, and in my work I have to memorize a lot of what different animal bones look like.  There's a nice site with high-res reference images that I've downloaded and my wallpaper scrolls through those.  With any luck I'll learn this information by osmosis!

http://i998.photobucket.com/albums/af105/rabidredfox/Crunchbang/scolling_wall.png 1024 x 819

The thing is, the images do not have specimen names written on them, so I wouldn't know for sure what they are when they come on-screen.  They do, however, have IDs that you can look up online.  For example, a cranium of a bottlenose dolphin is specimen DKY_0120 which you can look up by going to the DKY list here* and finding the number, which leads to the species name.  The filenames have the IDs in them already; the dolphin above, for example, is named "DKY_0120R.jpg".

Is there any way to get OpenBox to display the species name when the image comes up?  It would be cool if we could write a script to fetch the information and run it through Conky.

If this could work, it'd be epic for me.

Thanks for your help, as always.

//Edit:  there's some strange truncation that happens when I try to make a post, where it leaves out half the text...  It's only been happening the past three posts I've made...

Last edited by rabidfox (2011-01-25 01:14:10)

...But I'm ever so squeezable!

Re: Help me write a fun script for my wallpaper project!

knowing the filename of the wallpaper, it should be relatively easy to get the specimen name from the website with curl and some editing...

the part i don't know how to do right now is get the name of the wallpaper thats showing to the script

It's hard to find something if you don't know what you're looking for.
I have a blog, it's mostly about conky and lua stuff... go here.

Re: Help me write a fun script for my wallpaper project!

This is the relevant part that calls the wallpaper...  I don't know if that helps.  hmm

#!/bin/bash

WALLPAPERS="$HOME/img/walls"
ALIST=( `ls -w1 $WALLPAPERS` )
RANGE=${#ALIST[*]}
SHOW=$(( $RANDOM % $RANGE ))

feh --bg-scale $WALLPAPERS/${ALIST[$SHOW]}
...But I'm ever so squeezable!

Re: Help me write a fun script for my wallpaper project!

are all the wallpapers from the DKY site?
and do they all follow the same format?
ie 4 digits followed by "R" followed by ".jpg"

then this lua script can get the specimen name  from the wallpaper name... now just have to work out how to get the wallpaper name into the script

require "cairo"
function trim(s)
return s:gsub("^%s+", ""):gsub("%s+$", "")
end
----------------------------------------------------------------------------------------------------------
function string:split(delimiter)
local result = { }
local from  = 1
local delim_from, delim_to = string.find( self, delimiter, from  )
while delim_from do
table.insert( result, string.sub( self, from , delim_from-1 ) )
from  = delim_to + 1
delim_from, delim_to = string.find( self, delimiter, from  )
end
table.insert( result, string.sub( self, from  ) )
return result
end
--####################################################################################################
function conky_draw_fig()
local updates=conky_parse('${updates}')
updates=tonumber(updates)
if conky_window==nil then return end
local w=conky_window.width
local h=conky_window.height
local cs=cairo_xlib_surface_create(conky_window.display, conky_window.drawable, conky_window.visual, w, h)
cr=cairo_create(cs)
--####################################################################################################
if updates>5 then -- starts the display
--####################################################################################################
jpeg="DKY_0018R.jpg"
fnum=tostring(string.gsub(jpeg,"[%a%p]",""))
if tonumber(fnum)>0099 then
fnum2d=string.gsub(fnum,".", "%1|")
fnum2d=string.split(fnum2d,"|")
fnum2d=tostring(fnum2d[1] .. fnum2d[2] .. "00")
else
fnum2d="0000"
end--if
timer=(updates %30)+1
if timer==1 or updates==7 then
local f = io.popen("curl 'http://macro.dokkyomed.ac.jp/mammal/en/specimen_no/" ..  fnum2d .. ".html' | grep '" .. fnum .. "' | awk -F 'class=\"italic\">' '{print $2}' | awk -F '</li>' '{print $1}' | sed 's|</span>||'")
specimen= f:read("*a")
specimen=trim(specimen)
f:close()
end
adjust=10
font="Sans"
fontsize=12
cairo_select_font_face (cr, font, CAIRO_FONT_SLANT_NORMAL, CAIRO_FONT_WEIGHT_NORMAL);
cairo_set_font_size (cr, fontsize);
cairo_move_to (cr, 50,50)
cairo_show_text (cr, specimen)
cairo_stroke (cr)
--####################################################################################################
end--if updates >5
end--function

unfortunately i only know enough code to do it in lua smile

Last edited by mrpeachy (2011-01-25 04:16:51)

It's hard to find something if you don't know what you're looking for.
I have a blog, it's mostly about conky and lua stuff... go here.

Re: Help me write a fun script for my wallpaper project!

Yes, they are all labelled by that rubric:

DKY_####R.jpg
PRI_####R.jpg
ILF_####R.jpg
JMC_####R.jpg
THK_####R.jpg

Where # are numbers and are the only things that change and there are only those five character assemblages.  I'll try this in Lua and come back.

Last edited by rabidfox (2011-01-25 04:49:43)

...But I'm ever so squeezable!

Re: Help me write a fun script for my wallpaper project!

rabidfox wrote:

Yes, they are all labelled by that rubric:

DKY_####R.jpg
PRI_####R.jpg
ILF_####R.jpg
DKY_####R.jpg
THK_####R.jpg

Where # are numbers and are the only things that change and there are only those five character assemblages.  I'll try this in Lua and come back.

it will only work with the DKY numbers as of yet smile
...this should get them all

require "cairo"
function trim(s)
return s:gsub("^%s+", ""):gsub("%s+$", "")
end
------------------------------------------------------------------------------
function string:split(delimiter)
local result = { }
local from  = 1
local delim_from, delim_to = string.find( self, delimiter, from  )
while delim_from do
table.insert( result, string.sub( self, from , delim_from-1 ) )
from  = delim_to + 1
delim_from, delim_to = string.find( self, delimiter, from  )
end
table.insert( result, string.sub( self, from  ) )
return result
end
--####################################################################################################
function conky_draw_fig()
local updates=conky_parse('${updates}')
updates=tonumber(updates)
if conky_window==nil then return end
local w=conky_window.width
local h=conky_window.height
local cs=cairo_xlib_surface_create(conky_window.display, conky_window.drawable, conky_window.visual, w, h)
cr=cairo_create(cs)
--####################################################################################################
if updates>5 then -- starts the display
--####################################################################################################
jpeg="ILF_0125R.jpg"
fdbase=string.split(jpeg,"_")
fdbase=tostring(fdbase[1])
fnum=tostring(string.gsub(jpeg,"[%a%p]",""))

if fdbase=="DKY" then
if tonumber(fnum)>0099 then
fnum2d=string.gsub(fnum,".", "%1|")
fnum2d=string.split(fnum2d,"|")
fnum2d=tostring(fnum2d[1] .. fnum2d[2] .. "00")
else
fnum2d="0000"
end--if 0099
end--if DKY

if fdbase=="PRI" then
fnum2d="index_pri"
end

if fdbase=="ILF" then
fnum2d="index_ilf"
end

if fdbase=="THK" then
fnum2d="index_thk"
end

timer=(updates %30)+1
if timer==1 or updates==7 then
local f = io.popen("curl 'http://macro.dokkyomed.ac.jp/mammal/en/specimen_no/" ..  fnum2d .. ".html' | grep '" .. fnum .. "' | awk -F 'class=\"italic\">' '{print $2}' | awk -F '</li>' '{print $1}' | sed 's|</span>||'")
specimen= f:read("*a")
specimen=trim(specimen)
f:close()
end
adjust=10
font="Sans"
fontsize=12
cairo_set_source_rgba (cr,1,1,1,1)
cairo_select_font_face (cr, font, CAIRO_FONT_SLANT_NORMAL, CAIRO_FONT_WEIGHT_NORMAL);
cairo_set_font_size (cr, fontsize);
cairo_move_to (cr, 50,50)
cairo_show_text (cr, specimen)
cairo_stroke (cr)
--####################################################################################################
end--if updates >5
end--function

Last edited by mrpeachy (2011-01-25 04:41:20)

It's hard to find something if you don't know what you're looking for.
I have a blog, it's mostly about conky and lua stuff... go here.

Re: Help me write a fun script for my wallpaper project!

Alright, that's closer!  It's been a while for me & Lua, so I'll need your help.

What I've done so far is this, but I don't quite know what I'm doing:

1. create ~/pgm/skellies.lua and pasted the most recent contents into it
2. pasted sample jpgs into ~/pgm/
3. written in .conkyrc:
lua_load ~/pgm/skellies.lua
conky_draw_fig()


I'm not sure how to get the jpgs into the process either...  What should I do?

...But I'm ever so squeezable!

Re: Help me write a fun script for my wallpaper project!

as for getting the wallpaper filename onto the script
SunJack did it here, using nitrogen to set the wallpaper...

http://crunchbanglinux.org/forums/topic … en-script/

and there must be other ways

re above you need this in the .conkyrc

lua_load ~/pgm/skellies.lua
lua_draw_hook_pre draw_fig

Last edited by mrpeachy (2011-01-25 04:49:07)

It's hard to find something if you don't know what you're looking for.
I have a blog, it's mostly about conky and lua stuff... go here.

Re: Help me write a fun script for my wallpaper project!

i gotta be off im afraid...

i know mobilediesel sometimes drops in on this forum... he has written a wallpaper change script, and i'm sure he could put the pieces together!

i think i could piece together a lua function to swap wallpapers, with a bit of time. 

and i am sure there is a way to do what you want smile

It's hard to find something if you don't know what you're looking for.
I have a blog, it's mostly about conky and lua stuff... go here.

Re: Help me write a fun script for my wallpaper project!

Gotcha.  Fixed conky.  Does it get called just by being in those two lines, or is there a line I should put under "TEXT"?

Right now the image is being displayed by feh, but is there a way to get nitrogen to log that or should the wallpaper calling script be written with nitrogen?

Thanks MrPeachy, you're so awesome!  See you next time.



nitroconf="$HOME/.config/nitrogen/bg-saved.cfg"  .... hmmm...

Last edited by rabidfox (2011-01-25 05:01:13)

...But I'm ever so squeezable!

11

Re: Help me write a fun script for my wallpaper project!

hello rabidfox,
can you please post the output of

ls $HOME/img/walls

i think it might be useful in writing the needed bits. (relevant question: are you only using the DKY or also the other files?)

meanwhile: what does

NR=`echo ${ALIST[$SHOW]#*_} | cut -c 1-4`
curl http://macro.dokkyomed.ac.jp/mammal/en/specimen_no/${NR:0:2}00.html | \
  sed -n 's/^<li><a href="[^"]*">'$NR'<\/a> <span class="italic">\([^<]*\)<\/span>.*/\1/p'

give you for a filename with DKY?
luc
EDIT: oh i should have updated ... hmm

Last edited by luc (2011-01-25 05:03:20)

Re: Help me write a fun script for my wallpaper project!

Edit:

(There are a couple duplicates for some reason, must have been the wget code I wrote.)

I'm using all the files, though they are very many!  I'm going to need this to function for a long time and keep some challenge to it over the years.

I'm so glad you're here, Luc!

Last edited by rabidfox (2011-02-06 18:26:51)

...But I'm ever so squeezable!

13

Re: Help me write a fun script for my wallpaper project!

thx fox, so i missed your whole lua conversation above while fighting my shell smile.
Q: what is the way you want to go now?
-> have a cron job change the wall? have a script change the wall?
-> get the name of the animal from within conky / lua ? get the name from within the (cron-)script?

EDIT:
If you use a shell script it could dump the name of the current animal to a file like

echo "$animal_name" > ~/.animal_name

and you could read that from lua (if the file timestamp updates)

Last edited by luc (2011-01-25 05:31:56)

Re: Help me write a fun script for my wallpaper project!

Hmm... whichever is most likely to produce the desired effect (allow for change of wall and display species name)...

My intuition says that if we can get something to capture the wallpaper name as would have

nitroconf="$HOME/.config/nitrogen/bg-saved.cfg" 

, that'd be the easiest.

Supposing we can somehow read from feh, we might go with option #2, get name from w/in conky lua...?

But I trust your opinion more than I trust mine in this case.

Edit:  But then, would a chron job be easier for capturing the filename?  I don't see a way to read from feh, so maybe it'd be better if we rewrote it so we could access that name when it calls rand.

Last edited by rabidfox (2011-01-25 05:34:39)

...But I'm ever so squeezable!

Re: Help me write a fun script for my wallpaper project!

luc wrote:

thx fox, so i missed your whole lua conversation above while fighting my shell smile.
EDIT:
If you use a shell script it could dump the name of the current animal to a file like

echo "$animal_name" > ~/.animal_name

and you could read that from lua (if the file timestamp updates)

That's good.  I'm just stuck on how to isolate the name if we don't just write a new script to do it.  Like, use one script that will call up a random file from the folder, store the filename value, use feh or nitrogen on the image, and then have lua/conky display the title based on the stored value...?

Last edited by rabidfox (2011-01-25 05:41:52)

...But I'm ever so squeezable!

16

Re: Help me write a fun script for my wallpaper project!

does this work?

#!/bin/bash

LOGFILE=$HOME/.animal_names
DIR="$HOME/img/walls"
ALIST=( `ls -w1 $DIR` )

while true; do
  FILE=${ALIST[$(($RANDOM % ${#ALIST}))]}

  feh --bg-scale $DIR/$FILE

  case $FILE in
    DKY*)
      curl http://macro.dokkyomed.ac.jp/mammal/en/specimen_no/${FILE:4:2}00.html | \
      sed -n 's/^<li>[^>]*>'${FILE:4:4}'.*"italic">\([^<]*\).*/\1/p' ;;
    *)
      curl http://macro.dokkyomed.ac.jp/mammal/en/specimen_no/index_`echo ${FILE%%_*} | tr [:upper:] [:lower:]`.html | \
      sed -n 's/^<li>[^>]*>'${FILE:4:4}'.*"italic">\([^<]*\).*/\1/p' ;;
  esac > $LOGFILE

  sleep 6m
done

Last edited by luc (2011-01-25 05:54:47)

Re: Help me write a fun script for my wallpaper project!

Nearly?


feh WARNING: /home/xxx/img/walls//home/xxx/img/walls/DKY_0054R.jpg - File does not exist
feh ERROR: Couldn't load image in order to set bg
  % Total    % Received % Xferd  Average Speed   Time    Time     Time  Current
                                 Dload  Upload   Total   Spent    Left  Speed
100   250    0   250    0     0     43      0 --:--:--  0:00:05 --:--:--  1157

...But I'm ever so squeezable!

18

Re: Help me write a fun script for my wallpaper project!

sorry! i edited it.

Re: Help me write a fun script for my wallpaper project!

Seems to.  The images are blown up a bit larger I think, but:
Edit:  I think I'm hallucinating.  It's the same.


  % Total    % Received % Xferd  Average Speed   Time    Time     Time  Current
                                 Dload  Upload   Total   Spent    Left  Speed
100  4529  100  4529    0     0    684      0  0:00:06  0:00:06 --:--:-- 12476
^C

Last edited by rabidfox (2011-01-25 05:59:30)

...But I'm ever so squeezable!

20

Re: Help me write a fun script for my wallpaper project!

we need "curl --silent"
what  is in $HOME/.animal_names ?

Last edited by luc (2011-01-25 06:00:37)

Re: Help me write a fun script for my wallpaper project!

Edit: Saimiri sciureus

Brilliant!  Now how do we put that through Conky...?

Last edited by rabidfox (2011-01-25 06:04:00)

...But I'm ever so squeezable!

22

Re: Help me write a fun script for my wallpaper project!

"while true" should loop forever (or at least as long true is really true big_smile ) (I merged the two scripts into one)
I am sorry i don't know any conky or lua but if it was bash you would do

cat $HOME/.animal_names

Re: Help me write a fun script for my wallpaper project!

It seems to be stuck on the first value: cat $HOME/.animal_names  --> Saimiri sciureus, after several switchovers.... is it just me?

...But I'm ever so squeezable!

Re: Help me write a fun script for my wallpaper project!

Adding this to conky will allow it to display it:

${execi 28800 cat /home/xxx/.animal_names}

Last edited by rabidfox (2011-01-25 06:11:59)

...But I'm ever so squeezable!

25

Re: Help me write a fun script for my wallpaper project!

I just found this on google for "conky read file"

${exec cat <path to file>}
execi lets you specify refresh interval

@stuck on first value
Edit: what happens if you put "esac | tee $LOGFILE" instead of "esac > $LOGFILE" (it should also print the text to stdout)

Last edited by luc (2011-01-25 06:18:53)