d2jsp
Log InRegister
d2jsp Forums > Off-Topic > Computers & IT > Programming & Development > Random Avator And Signatures Rotator
Prev123
Add Reply New Topic New Poll
Member
Posts: 3,939
Joined: Feb 1 2013
Gold: 2,749.09
Warn: 20%
Aug 4 2016 07:57pm
http://getlvl99.com/rot/cybergod/Random.py

Code
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
Member
Posts: 13,425
Joined: Sep 29 2007
Gold: 0.00
Warn: 20%
Aug 4 2016 10:50pm
Slammed.

If anything should just use symlinks, why on earth would you copy the image each time.

Quote
You could use a CGI script to point requests to a sig/ava pair. Maybe based on time, like so:


This, have the cgi script create an index of ava sig pairs, then randomly select an index and feed the image back.

Or you can have two php scripts, one which sets the content type to image/png and has a sql database of ava/sig paris and a single entry for "current pair" and another which just reads the current pair and returns the image. This way each access to the master php script it will set a new pair and return the image sig, and each access to the slave script will return the avatar for the current pair.
Member
Posts: 109,874
Joined: Feb 1 2006
Gold: 10,152.00
Aug 7 2016 01:29am
ducky says he do it for 1.5k
op then pays 2.5k

aside from the irony of asking it for free then not giving t out thats some funny shit right there.
More so the guy who wrote it says its not his yet he paid for it.

:rofl:
Go Back To Programming & Development Topic List
Prev123
Add Reply New Topic New Poll