LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Software (https://www.linuxquestions.org/questions/linux-software-2/)
-   -   Random photo every two minutes recursively (https://www.linuxquestions.org/questions/linux-software-2/random-photo-every-two-minutes-recursively-450214/)

geletine 05-31-2006 08:33 AM

Random photo every two minutes recursively
 
I trying to find a script that can use fbsetbg and change the background ramdomly through directories

i found this python script and changed it to the following , but it gives me errors , i think its because there are directories in directories

here is my modified version
Code:

# Copyright 2005 Michael Rice
# errr (at) errr-online (dot) com
#
# This will set a random image. It will pull the image from a pool
# of as many dirs as you want and its timed and will change every 2 mins
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 of the License, or
# (at your option) any later version.

import os,random
from time import sleep

def get_bgimgs():
    h = []
    #add your paths here no need to remove any if you dont want to
    #any path that isnt there will be skipped
    paths =["/mnt/allix/photos"]
    for imgpth in paths:
            try:
                imgs = os.listdir(os.path.expanduser(imgpth))
                for i in imgs:
                    i = i.replace(" ","/ ")
                    h.append(imgpth+"/"+i)
            except (OSError):
                pass
    os.system("fbsetbg -f "+ random.choice(h))
    sleep(240)
    #print random.choice(h)

if __name__ == "__main__":
    while 1:
        get_bgimgs()


e5150 05-31-2006 08:45 AM

Code:

import os,random, time
paths=['/mnt/allix/photos']
images=[]
for path in paths:
  if os.path.isdir(path)==False: continue
  for root,dirs,files in os.walk(path):
    for name in files:
      images.append(os.path.join(root,name))

while True:
  os.system('fbsetbg -f "%s"'%images[random.randint(0,len(images))])
  time.sleep(240)


havn't tested it, but I reckon it should work...

geletine 05-31-2006 09:03 AM

thanks its working , i don't think it will start up if i put it in .fluxbox/init
apart from putting it on the menu, how would you suggest i automate it when the fluxbox loads?

e5150 05-31-2006 09:08 AM

if you add
#!/usr/bin/python
or wherever your python binary is located at the top of the script and
chmod 755 nameofscript.py
then you could just set
session.screen0.rootCommand: nameofscript.py
in your ~/.fluxbox/init

geletine 05-31-2006 10:07 AM

thanks, that works


All times are GMT -5. The time now is 06:12 AM.