Ejemplo n.º 1
0
 public function testPersistDatabase()
 {
     $this->url($this->configuration['googleFormUrl']);
     $this->clickDisplayedElementByID('Email');
     $this->keys($this->configuration['email']);
     $this->clickDisplayedElementByID('next');
     $this->clickDisplayedElementByID('Passwd');
     $this->keys($this->password);
     $this->clickDisplayedElementByID('signIn');
     $timeFormat = 'H\\hi';
     $data = json_decode(file_get_contents($this->configuration['hourLogFile']), true);
     foreach ($data as $date => $keyList) {
         if (empty($keyList)) {
             continue;
         }
         $dateTime = DateTime::createFromFormat('Y-m-d', $date);
         foreach ($keyList as $key => $entryList) {
             if (empty($entryList)) {
                 continue;
             }
             $commentList = [];
             $total = new DateTime("@0");
             foreach ($entryList as $index => $entry) {
                 if (isset($entry['form'])) {
                     continue 2;
                 }
                 if (empty($entry['stop'])) {
                     continue;
                 }
                 $total->add(DateTime::createFromFormat($timeFormat, $entry['start'])->diff(DateTime::createFromFormat($timeFormat, $entry['stop'])));
                 if (!empty($entry['comment'])) {
                     $comment = str_replace('\\n', String::newLine(), $entry['comment']);
                     $commentList[$comment] = $comment;
                 }
             }
             $this->clickDisplayedElementByID('entry_116160053');
             $this->keys('MEBLO-' . $key);
             $this->executeJavaScript("document.getElementById('entry_789822953').value = '" . $dateTime->format('Y-m-d') . "';");
             $this->clickDisplayedElementByID('entry_368040154');
             $this->keys(number_format((int) $total->format('H') + (int) $total->format('i') / 60, 2, ',', ''));
             $this->clickDisplayedElementByID('entry_1252005894');
             $this->keys(implode(String::newLine(), $commentList));
             $this->clickDisplayedElementByID('emailReceipt');
             $this->clickDisplayedElementByID('ss-submit');
             $data[$date][$key][] = ['form' => $this->waitUntilShow(Selenium::BY_CLASS_NAME, 'ss-bottom-link')->attribute('href')];
             $this->url($this->configuration['googleFormUrl']);
         }
     }
     file_put_contents($this->configuration['hourLogFile'], json_encode($data, JSON_PRETTY_PRINT));
 }
Ejemplo n.º 2
0
                $date = $possibleDate->format($dateMySQLFormat);
                $argvIndex++;
            }
        }
        if (!isset($data[$date][$key])) {
            $data[$date][$key] = [];
        }
        $dataTodayKey =& $data[$date][$key];
        if (isset($argv[$argvIndex])) {
            $possibleTime = DateTime::createFromFormat($timeFormat, $argv[$argvIndex]);
            if ($possibleTime instanceof DateTime) {
                $argvIndex++;
                $dataTodayKey[] = ['start' => '00h00', 'stop' => $possibleTime->format($timeFormat), 'comment' => implode(' ', array_slice($argv, $argvIndex))];
                Cli::writeOutput($key . ' added' . String::newLine(2), Cli::COLOR_GREEN_BOLD);
                break;
            }
        }
        $count = count($dataTodayKey);
        $index = $count - 1;
        if ($count > 0 && !isset($dataTodayKey[$index]['stop'])) {
            $entry =& $dataTodayKey[$index];
            $entry['stop'] = $time;
            $entry['comment'] = implode(' ', array_slice($argv, 2));
            $duration = DateTime::createFromFormat($timeFormat, $entry['start'])->diff($now)->format($intervalFormat);
            Cli::writeOutput($key . ' stopped with ' . $duration . String::newLine(2), Cli::COLOR_GREEN_BOLD);
        } else {
            $dataTodayKey[] = ['start' => $time];
            Cli::writeOutput($key . ' started' . String::newLine(2), Cli::COLOR_GREEN_BOLD);
        }
}
file_put_contents($file, json_encode($data, JSON_PRETTY_PRINT));
Ejemplo n.º 3
0
<?php

use SimpleHelpers\Cli;
use SimpleHelpers\String;
declare (ticks=1);
$basePath = realpath(dirname(__FILE__) . '/../');
require $basePath . '/src/common.php';
$os = PHP_OS == 'Darwin' ? 'mac' : 'linux';
$showSeleniumDebug = false;
if (file_exists($basePath . '/vendor/chromedriver/chromedriver-' . $os . '/chromedriver')) {
    $seleniumDebug = $showSeleniumDebug ? '' : ' 2>&1';
    Cli::writeOutput('Starting Selenium' . String::newLine(2));
    $exec = exec('java -Dwebdriver.chrome.driver=' . $basePath . '/vendor/chromedriver/chromedriver-' . $os . '/chromedriver -jar ' . $basePath . '/vendor/seleniumhq/selenium-server-standalone/selenium-server-standalone-2.48.2.jar > /dev/null ' . $seleniumDebug . ' &', $output, $return);
    sleep(2);
    $shutdown = function () {
        Cli::writeOutput('Stopping Selenium' . String::newLine(2));
        $pid = Cli::execute('ps aux | grep selenium | grep -v grep | awk \'{ print $2 }\' "$@"');
        Cli::execute('kill -9 ' . $pid['return']);
        Cli::writeOutput('Done!' . String::newLine());
        exit;
    };
    register_shutdown_function($shutdown);
    // above not working yet :(
    pcntl_signal(SIGINT, $shutdown);
    pcntl_signal(SIGTERM, $shutdown);
    pcntl_signal(SIGUSR1, $shutdown);
    pcntl_signal(SIGQUIT, $shutdown);
}
Ejemplo n.º 4
0
        }
    }
}
$reader->close();
if (!empty($configuration['slackEndpoint']) && !empty($configuration['channel'])) {
    Cli::writeOutput('Notifying Slack team', Cli::COLOR_GREEN_DIM);
    // Instantiate with defaults, so all messages created
    // will be sent from 'Cyril' and to the #accounting channel
    // by default. Any names like @regan or #channel will also be linked.
    $client = new Client($configuration['slackEndpoint'], ['username' => 'HourBank', 'channel' => $configuration['channel'], 'icon' => ':clock4:', 'markdown_in_attachments' => ['fields']]);
    /** @var $client Message */
    !$dryRun && $client->attach(['fallback' => $teamFallback, 'color' => 'bad', 'fields' => $team])->send($headLine);
}
if ($configuration['markAsDone']) {
    $modify = new Google_Service_Gmail_ModifyMessageRequest();
    $modify->setRemoveLabelIds(['INBOX']);
    !$dryRun && $service->users_messages->modify($user, $message->getId(), $modify);
    Cli::writeOutput('Message marked as *done*', Cli::COLOR_YELLOW_DIM);
}
if ($configuration['removeMessage'] && !$dryRun) {
    !$dryRun && $service->users_messages->trash($user, $message->getId());
    Cli::writeOutput('Message moved to trash!', Cli::COLOR_YELLOW_DIM);
}
if ($headLine) {
    Cli::writeOutput(String::newLine() . $headLine . String::newLine(), Cli::COLOR_WHITE_BOLD);
}
foreach ($teamCli as $member => $data) {
    Cli::writeOutput($member . ': ' . $data['hours'] . ' ' . $data['hourDirection'], $data['hourDirection'] == 'positivas' ? Cli::COLOR_GREEN : Cli::COLOR_RED);
}
Cli::writeOutput(String::newLine());