This is the new home of the egghelp.org community forum.
All data has been migrated (including user logins/passwords) to a new phpBB version.


For more information, see this announcement post. Click the X in the top right-corner of this box to dismiss this message.

Image downloader.

Help for those learning Tcl or writing their own scripts.
Post Reply
g
geeker
Voice
Posts: 1
Joined: Tue Dec 10, 2013 9:40 pm

Image downloader.

Post by geeker »

I wrote a script to download images posted from URLs to the channel, Im running this on a small VPS server (3Gb disk), im looking to figure out the best way to check if there is space available before it even attempts to download the image

so far this is what i've came up with.

Code: Select all

proc freespace {} {
set dir /home
regexp {(\d+)} [lindex [lindex [split [exec df -k $dir] \n] end] end-2] -> kbytes
if {$kbytes > 1073741824} { 
	set result [expr ${kbytes}.0 / 1073741824.0]; set sz "TB" 
} elseif {$kbytes > 1048576} { 
	set result [expr ${kbytes}.0 / 1048576.0] ; set sz "GB" 
} else { 
	set result [expr $kbytes / 1024.0] ; set sz "MB" 
}
	set result "[format %.2f $result]${sz}"; puts $result
puts $kbytes
}
If the file cant be downloaded, it notifys the channel its too large.
The filesize given from the image site is in human-readable format
1.02MB. for example.
any ideas? thanks.
Post Reply