-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtimi.30s.php
152 lines (118 loc) Β· 4.52 KB
/
timi.30s.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
#!/usr/bin/php
<?php
# <bitbar.title>TimiApp</bitbar.title>
# <bitbar.version>v1.6</bitbar.version>
# <bitbar.author>Rutger Laurman</bitbar.author>
# <bitbar.author.github>lekkerduidelijk</bitbar.author.github>
# <bitbar.desc>Show running timers from timiapp.com.</bitbar.desc>
# <bitbar.image>https://timiapp.com/apple-touch-icon.png</bitbar.image>
# <bitbar.dependencies>php</bitbar.dependencies>
# <bitbar.abouturl>https://timiapp.com/</bitbar.abouturl>
// =============================================================================
// Configuration
// =============================================================================
$TOKEN = "x";
$EMAIL = "x";
$TIMEZONE = "Europe/Amsterdam";
$ANIMATECLOCK = true;
// Don't edit below this line unless you know what you're doing
// =============================================================================
// Set correct time zone
date_default_timezone_set($TIMEZONE);
// =============================================================================
// Functions
// =============================================================================
function doCurl($url) {
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
$output = curl_exec($ch);
curl_close($ch);
if(!$output) {
return false;
} else {
return json_decode($output);
}
}
// =============================================================================
// API endpoint
// =============================================================================
$apiEndpoint = "https://timiapp.com/api/v1/";
$apiAuth = "email=" . $EMAIL . "&token=" . $TOKEN;
// =============================================================================
// Get entries for today
// =============================================================================
// Format url and get data
$TODAY = date("Y-m-d");
$URL = $apiEndpoint . "time_entries.json?" . $apiAuth . "&date=" . $TODAY;
$outputToday = doCurl($URL);
// Check for connection
if($outputToday === false) {
echo "Timi: ?:?? π₯\n";
echo "---\n";
echo "No internet connection\n";
die();
}
// Process data
$timeToday = $outputToday->time_entries;
// Define vars
$minutesToday = 0;
$hoursToday = 0;
// Loop through time entries
foreach ($timeToday as $entry) {
$minutesToday = $minutesToday + $entry->duration;
}
// Format minutes to proper notation
$hoursToday = gmdate("H:i", ($minutesToday));
// =============================================================================
// Get timer
// =============================================================================
// Format url and get data
$URL = $apiEndpoint . "time_entries/timer.json?" . $apiAuth;
$outputTimer = doCurl($URL);
$hasRunningTimer = (count(get_object_vars($outputTimer)) > 0) ? true : false;
if($hasRunningTimer) {
// Define vars
$timerDuration = $outputTimer->duration;
$timerStarted = $outputTimer->timer_started_at;
$timerBody = $outputTimer->body;
$timerId = $outputTimer->id;
$timerDurationMinutes = floor($timerDuration/60);
// Add time difference from timer_started_at
$currentTimer = new DateTime($timerStarted, new DateTimeZone($TIMEZONE));
$minutesTimer = new DateTime("now", new DateTimeZone($TIMEZONE));
$hoursDiff = $minutesTimer->diff($currentTimer)->h;
$minutesDiff = $minutesTimer->diff($currentTimer)->i;
$minutesDiffTotal = ($hoursDiff * 60) + $minutesDiff;
$currentMinutes = $timerDurationMinutes + (int)$minutesDiffTotal;
$hours = floor($currentMinutes / 60);
$minutes = ($currentMinutes % 60);
$hoursTimer = $hours . ":" . sprintf('%02d', $minutes);
}
// =============================================================================
// Format output
// =============================================================================
// Check if timer is running
if($hasRunningTimer) {
if($ANIMATECLOCK) {
echo "Timi: $hoursTimer π |dropdown=false\n";
echo "Timi: $hoursTimer π |dropdown=false\n";
echo "Timi: $hoursTimer π |dropdown=false\n";
echo "Timi: $hoursTimer π |dropdown=false\n";
echo "Timi: $hoursTimer π |dropdown=false\n";
echo "Timi: $hoursTimer π |dropdown=false\n";
} else {
echo "Timi: $hoursTimer β±οΈ |dropdown=false\n";
}
echo "---\n";
echo "Timer actief: $hoursTimer\n";
echo "-- $timerBody| length=40\n";
} else {
echo "Timi: -:--\n";
echo "---\n";
echo "Timer niet actief\n";
}
echo "Vandaag: $hoursToday uur| href=https://timiapp.com/time_entries?date=$TODAY\n";
echo "---\n";
echo "Open Timi| href=https://timiapp.com\n";
echo "---";