geeker Voice
Joined: 10 Dec 2013 Posts: 1
|
Posted: Tue Dec 10, 2013 9:46 pm Post subject: Image downloader. |
|
|
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: |
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. |
|