<commit_before><?php

require(dirname(__FILE__) . '/vendor/autoload.php');
require(dirname(__FILE__) . '/includes.php');

use AJT\Toggl\TogglClient;
use AJT\Toggl\ReportsClient;

$options = getopt("v");
$debug = array_key_exists('v', $options);
$config = json_decode(file_get_contents('config.json'), true);

$toggl_client = TogglClient::factory(
    array(
        'api_key' => $config['toggl_api_key'], 
        'debug'   => $debug,
    )
);

$reports_client = ReportsClient::factory(
    array(
        'api_key' => $config['toggl_api_key'], 
        'debug'   => $debug,
    )
);

$current_ws = getWorkspaceByName($config['toggl_workspace'], $toggl_client);


if (!$current_ws) {
    die("ERROR: Workspace '{$config['toggl_workspace']}' not found. Dying.\n");
}
$users = $toggl_client->getWorkspaceUsers(array('id' => $current_ws['id']));

$today    = (new DateTime('today'))->format('Y-m-d');
$tomorrow = (new DateTime('tomorrow'))->format('Y-m-d');

foreach ($users as $user) {
    $output = '';

    // get hours billed for the day
    $daily_report = $reports_client->details(
        array(
            'user_agent'   => $config['recipient_email'],
            'workspace_id' => $current_ws['id'],
            'user_ids'     => "{$user['id']}",
            'order_desc'   => 'off',
            'since'        => $today,
            'until'        => $tomorrow
        )
    );
    $total = $daily_report['total_grand'] / 1000 / 60 / 60;
    $output .= "Hi {$user['fullname']},\n\n";
    $output .= "Total for the day: $total hours\n\n";
    foreach ($daily_report['data'] as $row_i => $time_entry) {
        $time = $time_entry['dur'] / 1000 / 60 / 60;
        $output .= "* {$time_entry['client']}: {$time_entry['project']}: {$time_entry['description']}: {$time} hours\n";
    }
    $output .= "\nLook good?  Great!\n\nNeed to make changes?\n\nhttps://www.toggl.com/app/reports/detailed/{$current_ws['id']}/period/today/billable/both";
    $output .= "\n\nThanks, {$current_ws['name']} Bot\n";
    // echo $user['email'] . "\n";
    // echo $output . "\n";
    if ($user['email'] == '<EMAIL>') {
        mail($user['email'], "[{$current_ws['name']}] Daily Hours Report for {$today}", $output);
    }<commit_msg>sending to everyone now<commit_after><?php

require(dirname(__FILE__) . '/vendor/autoload.php');
require(dirname(__FILE__) . '/includes.php');

use AJT\Toggl\TogglClient;
use AJT\Toggl\ReportsClient;

$options = getopt("v");
$debug = array_key_exists('v', $options);
$config = json_decode(file_get_contents('config.json'), true);

$toggl_client = TogglClient::factory(
    array(
        'api_key' => $config['toggl_api_key'], 
        'debug'   => $debug,
    )
);

$reports_client = ReportsClient::factory(
    array(
        'api_key' => $config['toggl_api_key'], 
        'debug'   => $debug,
    )
);

$current_ws = getWorkspaceByName($config['toggl_workspace'], $toggl_client);


if (!$current_ws) {
    die("ERROR: Workspace '{$config['toggl_workspace']}' not found. Dying.\n");
}
$users = $toggl_client->getWorkspaceUsers(array('id' => $current_ws['id']));

$today    = (new DateTime('today'))->format('Y-m-d');
$tomorrow = (new DateTime('tomorrow'))->format('Y-m-d');

foreach ($users as $user) {
    $output = '';

    // get hours billed for the day
    $daily_report = $reports_client->details(
        array(
            'user_agent'   => $config['recipient_email'],
            'workspace_id' => $current_ws['id'],
            'user_ids'     => "{$user['id']}",
            'order_desc'   => 'off',
            'since'        => $today,
            'until'        => $tomorrow
        )
    );
    $total = $daily_report['total_grand'] / 1000 / 60 / 60;
    $output .= "Hi {$user['fullname']},\n\n";
    $output .= "Total for the day: $total hours\n\n";
    foreach ($daily_report['data'] as $row_i => $time_entry) {
        $time = $time_entry['dur'] / 1000 / 60 / 60;
        $output .= "* {$time_entry['client']}: {$time_entry['project']}: {$time_entry['description']}: {$time} hours\n";
    }
    $output .= "\nLook good?  Great!\n\nNeed to make changes?\n\nhttps://www.toggl.com/app/reports/detailed/{$current_ws['id']}/period/today/billable/both";
    $output .= "\n\nThanks, {$current_ws['name']} Bot\n";
    // echo $user['email'] . "\n";
    // echo $output . "\n";
    mail($user['email'], "[{$current_ws['name']}] Daily Hours Report for {$today}", $output);
{'fraction_non_alphanumeric': 0.21417215534862594, 'fraction_numerical': 0.0072677719736543266, 'mean_word_length': 3.210325047801147, 'pattern_counts': {'":': 0, '<': 6, '<?xml version=': 0, '>': 36, 'https://': 2, 'lorem ipsum': 0, 'www.': 2, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '7216132', 'n_tokens_mistral': 1609, 'n_tokens_neox': 1545, 'n_words': 272}