Created
February 27, 2011 04:49
-
-
Save basicxman/845912 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/* | |
@author: Andrew Horsman | |
@description: Notifies Folding@Home progress. | |
@prerequisites: | |
Ubuntu 9.04+ (Notification Systray) | |
libnotify-bin (install via sudo apt-get install libnotify-bin) | |
PHP 5+ | |
Folding@Home (http://folding.stanford.edu) | |
@install: | |
Folding@Home as a service. | |
Create a cron job to run this script every minute, passing the FAH WD as a parameter. | |
*/ | |
// ~~~Functions~~~ | |
function getUnitInfo($directory) { | |
return file_get_contents($directory . "/unitinfo.txt"); | |
} | |
function getProject($search) { | |
if (preg_match("^(?<=Name: ).*^", $search, $matches)) return $matches[0]; else return "Folding@Home"; | |
} | |
function getProgress($search) { | |
if (preg_match("^(?<=Progress: )[0-9]+%^", $search, $matches)) return $matches[0]; else return 0; | |
} | |
function notifyUser($title, $body) { | |
$command = '/usr/bin/notify-send "' . $title . '" "' . $body . '" -i notification-message-im'; | |
`$command`; | |
} | |
// ~~~End Functions~~~ | |
if ($argc != 2) die("Not enough arguments."); | |
$prev = trim(file_get_contents($argv[1] . "/prev.txt")); | |
$unit = getUnitInfo($argv[1]); | |
if ($prev != getProgress($unit)) { | |
notifyUser(getProject($unit), getProgress($unit)); | |
$prevP = fopen($argv[1] . "/prev.txt", "w"); | |
fwrite($prevP, getProgress($unit)); | |
fclose($prevP); | |
} | |
?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment