|
|
|
|
51
|
# Loop weekdays
|
51
|
# Loop weekdays
|
52
|
for (my $weekday = 1; $weekday < 7; $weekday++) {
|
52
|
for (my $weekday = 1; $weekday < 7; $weekday++) {
|
53
|
|
53
|
|
54
|
- # Get current unix timestamp and week
|
|
|
|
|
54
|
+ # Get current unix timestamp and week day
|
55
|
$s = strftime "%s", localtime;
|
55
|
$s = strftime "%s", localtime;
|
56
|
$v = strftime "%w", localtime;
|
56
|
$v = strftime "%w", localtime;
|
57
|
# Calculate current weekday
|
57
|
# Calculate current weekday
|
58
|
- $s = $s - ($v - 2 + $weekday) * 84600;
|
|
|
|
|
58
|
+ $s = $s + ($weekday - $v) * 86400;
|
59
|
$timestr = strftime "%Y/%m/%d", localtime($s);
|
59
|
$timestr = strftime "%Y/%m/%d", localtime($s);
|
60
|
|
60
|
|
61
|
my $url = "http://www.sodexo.fi/ruokalistat/output/daily_json/$kitchen/$timestr/fi";
|
61
|
my $url = "http://www.sodexo.fi/ruokalistat/output/daily_json/$kitchen/$timestr/fi";
|
62
|
my $temp_fname = "sodexo$count-$weekday.temp.js";
|
62
|
my $temp_fname = "sodexo$count-$weekday.temp.js";
|
63
|
if (!-f $temp_fname || !$use_old) {
|
63
|
if (!-f $temp_fname || !$use_old) {
|
|
|
64
|
+ print $url . " -> " . $temp_fname . "\n";
|
64
|
system("wget -q --timeout=10 -O $temp_fname.tmp \"$url\" && mv $temp_fname.tmp $temp_fname");
|
65
|
system("wget -q --timeout=10 -O $temp_fname.tmp \"$url\" && mv $temp_fname.tmp $temp_fname");
|
65
|
}
|
66
|
}
|
66
|
if (-f $temp_fname) {
|
67
|
if (-f $temp_fname) {
|