http://getlvl99.com/rot/cybergod/Random.pyCode
minTime = 1 # Min time in seconds between sig/ava change
maxTime = 5 # Max time in seconds between sig/ava change
# No touchy
import os
import random
import shutil
import time
cwd = os.getcwd()
while True:
images = os.listdir(cwd + "/Images/")
num = random.randint(0, (len(images)/2)-1)
sigs = []
avas = []
for i in xrange(0, len(images)):
if images[i].startswith("ava"):
avas.append(images[i])
else:
sigs.append(images[i])
liveSig = sigs[num]
for i in avas:
if liveSig.split(".")[0][3:] == i.split(".")[0][3:]:
liveAva = i
shutil.copy(cwd + "/Images/" + liveSig, cwd + "/Live/LiveSig." + liveSig.split(".")[1])
shutil.copy(cwd + "/Images/" + liveAva, cwd + "/Live/LiveAva." + liveAva.split(".")[1])
time.sleep(random.randint(minTime, maxTime))
Unless I'm missing something, this script performs an average of 57600 file copies on your webserver per day. I hope your web host doesn't mind.
I thought the use of xrange was cute, as if saving a few CPU cycles matters compared to the 3.5 GB/day of extraneous disk writes.
Half of what's in the while loop has no business being in a loop. Actually, this should be a CGI script with no while loop.
I could poke more holes, but moving on..
You could use a CGI script to point requests to a sig/ava pair. Maybe based on time, like so:
Code
import time
cntAvatars = 12
n = 1 + str(int(time.time()) % cntAvatars)
"ava" + n + ".gif"
"sig" + n + ".gif"
That would keep your basic time-based rotation idea while eliminating the file copies.
PS: cybergod, you can prevent directory listing with .htaccess
PPS: your avatar and signature are working nice, and if your host doesn't complain you don't necessarily need to change anything
@laz: no offense xD