-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcli.php
More file actions
executable file
·97 lines (81 loc) · 2.41 KB
/
Copy pathcli.php
File metadata and controls
executable file
·97 lines (81 loc) · 2.41 KB
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
#!/usr/bin/php
<?php
include dirname(__FILE__) . "/config.php";
include dirname(__FILE__) . "/feed_generator.php";
date_default_timezone_set("America/New_York");
// name of script calling
$name = array_shift($argv);
$command = array_shift($argv);
if ($command == 'update') {
$feed = array_shift($argv);
update($feed);
exit();
} else {
printOptions();
exit();
}
function printOptions() {
echo "usage: hours update [<feed name>]\n";
}
function update($which = "") {
$feeds = array(
"today" => OUTPUT_LOCATION . "/today.json",
"week" => OUTPUT_LOCATION . "/week.json",
"year" => OUTPUT_LOCATION . "/year.json"
);
// if $which is empty, update all of the feeds
if (!$which) {
foreach($feeds as $name => $path) { updateFeed($name, $path); }
} else {
if (!array_key_exists($which, $feeds)) {
echo "I don't know the feed: '" . $which . "'" . PHP_EOL;
return false;
} else {
updateFeed($which, $feeds[$which]);
}
}
}
function updateFeed($name, $path) {
$calendars = unserialize(CALENDARS_SERIALIZED)
echo cliColor("Updating", "light blue")
. cliColor(" '{$name}' ", "yellow")
. cliColor("feed ... ", "light blue");
if ($name === "week") {
$start = date('N') == 1 ? "today" : "last monday";
$end = date('N', strtotime("today")) == 7 ? "today" : "next monday";
} elseif ($name === "year") {
$start = date('N') == 1 ? "today" : "last monday";
$end = $start . " + 52 weeks";
} else {
$start = $end = "today";
}
echo file_put_contents(
$path,
build_feed($calendars, $start, $end)
)
? cliColor("success! ^_^", "light green") . "\n"
: cliColor("failure! ;_;", "light red") . "\n"
;
}
function cliColor($input, $color) {
$fgcolors = array(
"dark grey" => "1;30",
"blue" => "0;34",
"light blue" => "1;34",
"green" => "0;32",
"light green" => "1;32",
"cyan" => "0;36",
"light cyan" => "1;36",
"red" => "0;31",
"light red" => "1;31",
"purple" => "0;35",
"light purple" => "1;35",
"brown" => "0;33",
"yellow" => "1;33",
"light gray" => "0;37",
"white" => "1;37"
);
$escape = "\033[0m";
return "\033[" . $fgcolors[$color] . "m" . $input . $escape;
}
?>