/**
 * fetch today's news regarding objects monitored by the user
 *
 * @param string $user - OppUser object
 * @return void
 * @author Guglielmo Celata
 */
function opp_sync_politician_image($pol)
{
    $start_time = microtime(true);
    $success = true;
    echo pakeColor::colorize(sprintf('Processing politician %s...', $pol), array('fg' => 'red', 'bold' => true));
    // invoke the remote getPolImage function to grab the images from op_openpolis
    $remote_img_url = sfConfig::get('app_remote_politicians_images_service_url') . '/' . sfConfig::get('app_remote_openpolis_api_key') . '/' . $pol->getId();
    /* debug
      echo pakeColor::colorize(sprintf('Url:  %s...', $remote_img_url), 
                              array('fg' => 'red', 'bold' => true));
      */
    $file = fopen($remote_img_url, "r");
    if (!$file) {
        $err = "unable to open remote file.";
        $success = false;
    }
    $remote_img_str = '';
    while (!feof($file)) {
        $remote_img_str .= fgets($file, 1024);
    }
    fclose($file);
    $images_root = SF_ROOT_DIR . DIRECTORY_SEPARATOR . 'web' . DIRECTORY_SEPARATOR . 'images' . DIRECTORY_SEPARATOR . 'parlamentari' . DIRECTORY_SEPARATOR;
    // resizes images and stores them in the FS
    $picture = new sfImage();
    $picture->setMimeType('image/jpeg');
    $picture->loadString($remote_img_str);
    $picture->resize(91, null);
    $picture->saveAs($images_root . 'picture/' . $pol->getId() . '.jpeg', 'image/jpeg');
    $thumb = new sfImage();
    $thumb->setMimeType('image/jpeg');
    $thumb->loadString($remote_img_str);
    $thumb->resize(40, null);
    $thumb->saveAs($images_root . 'thumb/' . $pol->getId() . '.jpeg', 'image/jpeg');
    $execution_time = microtime(true) - $start_time;
    if ($success) {
        echo " ok (";
    } else {
        echo " {$err} (";
    }
    echo pakeColor::colorize(sprintf("%f", $execution_time), array('fg' => 'cyan'));
    echo ")\n";
}