Kaynağa Gözat

Remove PERL scripts

Toni Fadjukoff 6 yıl önce
ebeveyn
işleme
11c1b91764
5 değiştirilmiş dosya ile 0 ekleme ve 931 silme
  1. 0 101
      amica.pl
  2. 0 470
      food.pl
  3. 0 102
      juvenes.pl
  4. 0 169
      pky.pl
  5. 0 89
      sodexo.pl

+ 0 - 101
amica.pl Dosyayı Görüntüle

@@ -1,101 +0,0 @@
1
-use vars qw(@day_names);
2
-use JSON;
3
-
4
-my @restaurant_info = (
5
-  [ "(TaY) Amica Minerva", "http://www.amica.fi/minerva", "", "middle", "http://www.amica.fi/api/restaurant/menu/week?language=fi&restaurantPageId=7381" ],
6
-  [ "(TaY) Tampereen normaalikoulun ravintola", "http://www.amica.fi/tampereennormaalikoulu", "", "middle", "http://www.amica.fi/api/restaurant/menu/week?language=fi&restaurantPageId=6655" ],
7
-  [ "(TTY) Ravintola Reaktori", "http://www.amica.fi/reaktori", "", "middle", "http://www.amica.fi/api/restaurant/menu/week?language=fi&restaurantPageId=69171" ]
8
-);
9
-
10
-sub utf8_to_8859 {
11
-  $_ = shift;
12
-
13
-  s/ä/ä/g;
14
-  s/ö/ö/g;
15
-  s/Ä/Ä/g;
16
-  s/Ö/Ö/g;
17
-  return $_;
18
-}
19
-
20
-sub parse_amica {
21
-  my ($fname, $info_ref) = @_;
22
-  open(FILE, $fname);
23
-  my $json = do { local $/; <FILE> };
24
-  close(FILE);
25
-  
26
-  my $title = @{$info_ref}[0];
27
-  my $week = `date +%V`;
28
-  my @cur_day_foods = ();
29
-  my @week_foods = ();
30
-
31
-  my $data = from_json($json);
32
-  my $LunchMenus = $data->{'LunchMenus'};
33
-  foreach my $LunchMenu (@$LunchMenus) {
34
-    my $SetMenus = $LunchMenu->{'SetMenus'};
35
-    my $Html = $LunchMenu->{'Html'};
36
-    if (length($Html) > 0) {
37
-      my @Menus = split('<p>', $Html);
38
-      foreach my $SetMenu (@Menus) {
39
-        my @Meals = split('<br />', $SetMenu);
40
-	foreach my $Meal (@Meals) {
41
-	  my @parts = split('\\(', $Meal);
42
-	  $cur_food .= "\n" if $cur_food ne "";
43
-	  $cur_food .= @parts[0];
44
-	  my @Diets = split(",\s*", substr(@parts[1], 0, index(@parts[1], ')')));
45
-	  $cur_food .= ' (' . join(', ', @Diets) . ')' if @Diets;
46
-	}
47
-        push @cur_day_foods, utf8_to_8859($cur_food) if ($cur_food ne "");
48
-        $cur_food = "";
49
-      }
50
-    } else {
51
-      foreach my $SetMenu (@$SetMenus) {
52
-        my $Meals = $SetMenu->{'Meals'};
53
-        foreach my $Meal (@$Meals) {
54
-          $cur_food .= "\n" if $cur_food ne "";
55
-          $cur_food .= $Meal->{'Name'};
56
-          my $Diets = $Meal->{'Diets'};
57
-          $cur_food .= ' (' . join(', ', @$Diets) . ')';
58
-        }
59
-        push @cur_day_foods, utf8_to_8859($cur_food) if ($cur_food ne "");
60
-        $cur_food = "";
61
-      }
62
-    }
63
-
64
-    push @week_foods, [@cur_day_foods];
65
-    @cur_day_foods = ();
66
-  }
67
-
68
-  return [ $title, "", $week, [ @week_foods ], $info_ref ];
69
-}
70
-
71
-sub get_amica_restaurant {
72
-  my $use_old = shift;
73
-  my $count = 0;
74
-  my @restaurants = ();
75
-  my $weekDay = `date +%w`;
76
-  chomp($weekDay);
77
-  my $first_day = $weekDay == 1 
78
-    ? `date --date="today" +%Y-%m-%d`
79
-    : `date --date="last monday" +%Y-%m-%d`;
80
-  chomp($first_day);
81
-  my $last_day = $weekDay == 0
82
-    ? `date --date="today" +%Y-%m-%d`
83
-    : `date --date="next sunday" +%Y-%m-%d`;
84
-  chomp($last_day);
85
-  foreach my $i (@restaurant_info) {
86
-    my @info = @{$i};
87
-    my $temp_fname = "amica$count.temp.html";
88
-    my $url = "${info[4]}&weekDate=$first_day";
89
-    if (!-f $temp_fname || !$use_old) {
90
-      system("wget -q --timeout=10 -O $temp_fname.tmp '$url' && mv $temp_fname.tmp $temp_fname") if ($url ne "");
91
-    }
92
-    if (-f $temp_fname) {
93
-      $info[4] = $url;
94
-      push @restaurants, parse_amica($temp_fname, \@info);
95
-    }
96
-    $count++;
97
-  }
98
-  return @restaurants;
99
-}
100
-
101
-1;

+ 0 - 470
food.pl Dosyayı Görüntüle

@@ -1,470 +0,0 @@
1
-#!/usr/bin/env perl
2
-
3
-# Ruokalistaparseri v1.5.4
4
-# Copyright (c) 2007-2010 Timo Sirainen
5
-#               2011-2013 Toni Fadjukoff
6
-# This is Public Domain
7
-
8
-use strict;
9
-use POSIX qw(strftime mktime);
10
-use HTML::TokeParser;
11
-use HTML::Entities;
12
-
13
-use vars qw(@day_names);
14
-@day_names = ( "Maanantai", "Tiistai", "Keskiviikko", "Torstai", 
15
-	       "Perjantai", "Lauantai", "Sunnuntai" );
16
-
17
-require 'amica.pl';
18
-require 'sodexo.pl';
19
-require 'juvenes.pl';
20
-require 'pky.pl';
21
-
22
-my @allergies = ( "M", "L", "VL", "G", "K", "Ve" );
23
-my %allergy_descriptions = (
24
-  "M" => "Maidoton",
25
-  "L" => "Laktoositon",
26
-  "VL" => "Vähälaktoosinen",
27
-  "G" => "Gluteiiniton",
28
-  "K" => "Kasvis",
29
-  "Ve" => "Vegaani"
30
-);
31
-
32
-my $global_prefix = "";
33
-my $use_old = 0; # 1 is good for testing, 0 for production system!
34
-my @unordered;
35
-
36
-my @l = localtime;
37
-my $this_week = strftime("%V", @l);
38
-
39
-push @unordered, get_amica_restaurant($use_old);
40
-push @unordered, get_juvenes_restaurants($use_old);
41
-push @unordered, get_sodexo_restaurants($use_old);
42
-push @unordered, get_pky_restaurants($use_old, $l[6] == 0 || $l[6] == 6);
43
-
44
-my $max_week = 0;
45
-foreach my $r (@unordered) {
46
-  my $week = @{$r}[2];
47
-  $max_week = $week if ($week > $max_week || $week == 1);
48
-}
49
-
50
-if ($l[6] != 0 && $this_week != $max_week) {
51
-  # it's not sunday, don't force next week's menu yet
52
-  $max_week = $this_week;
53
-}
54
-
55
-my $stamp = time() - 3600*24*7;
56
-my $max_week_daterange = "";
57
-if ($max_week >= 1 && $max_week <= 52) {
58
-  # figure out the date range
59
-  for (;;) {
60
-    my $stamp_week = strftime("%V", localtime($stamp));
61
-    last if ($stamp_week == $max_week);
62
-    $stamp += 3600*24;
63
-  }
64
-  my @l1 = localtime($stamp);
65
-  my @l2 = localtime($stamp + 3600*24*6);
66
-  if ($l1[4] == $l2[4]) {
67
-    # same month
68
-    $max_week_daterange = $l1[3]."-".$l2[3].".".($l1[4]+1).".";
69
-  } else {
70
-    # different months
71
-    $max_week_daterange = $l1[3].".".($l1[4]+1)."-".$l2[3].".".($l2[4]+1).".";
72
-  }
73
-  $max_week_daterange = " ($max_week_daterange)"
74
-}
75
-
76
-my $file_header = '<?xml version="1.0" encoding="iso-8859-1"?>
77
-<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
78
-<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="fi" lang="fi">
79
-<head>
80
-  <title>Ruokalistat</title>
81
-  <link rel="stylesheet" type="text/css" href="'.$global_prefix.'/ruoka.css" />
82
-</head>
83
-<body>
84
-
85
-<div id="notice" style="border: 1px solid black; border-radius: 5px; padding: 5px;">
86
-PNA.fi on kolmannen osapuolen tarjoama palvelu. En voi taata ruokalistojen oikeellisuutta.  Virallisen ruokalistan saat näkyviin siirtymällä ravintolan omille sivuille painamalla sen nimestä. Jos huomaat ruokalistassa virheen, nopeiten virhe saadaan pois näkyvistä kun lähetät minulle siitä sähköpostia: <a href="mailto:lamperi+pna@gmail.com">lamperi+pna@gmail.com</a>
87
-</div>
88
-
89
-<form method="get" action="/cgi-bin/food.cgi">
90
-';
91
-my $file_footer = "<div class=\"footer\">Päivitetty ".
92
-    strftime("%d.%m.%Y %H:%M:%S", localtime).
93
-    " <input type=\"submit\" value=\"Päivitä nyt\" />".
94
-    " / Palaute <a href=\"mailto:lamperi+pna\@gmail.com\">lamperi+pna\@gmail.com</a>".
95
-    " / <a href=\"$global_prefix/code.html\">Koodit täältä</a>".
96
-    " / <a href=\"$global_prefix/pna.html\">Mikä on PNA?</a>".
97
-    "</div>\n</form>\n</body></html>\n";
98
-
99
-sub find_last_day_with_foods {
100
-  my $restaurants_ref = shift;
101
-
102
-  my $last_day = 0;
103
-  foreach my $r (@${restaurants_ref}) {
104
-    my ($title, $open_hours, $week, $week_foods_ref) = @{$r};
105
-    my @week_foods = @{$week_foods_ref};
106
-    for (my $day = 0; $day < 7; $day++) {
107
-      if (defined($week_foods[$day])) {
108
-	$last_day = $day if ($day > $last_day);
109
-      }
110
-    }
111
-  }
112
-  return $last_day;
113
-}
114
-
115
-sub write_days_header {
116
-  my ($fout, $day, $last_day) = @_;
117
-  
118
-  print $fout "  <span class=\"days\">";
119
-  for (my $i = 0; $i <= $last_day; $i++) {
120
-    if ($i == $day) {
121
-      print $fout $day_names[$i]." ";
122
-    } else {
123
-      print $fout "<a href=\"".($i+1).".html\">".$day_names[$i]."</a> ";
124
-    }
125
-  }
126
-  if ($day < 0) {
127
-    print $fout "Taulukko";
128
-  } else {
129
-    print $fout "<a href=\"table.html\">Taulukko</a>";
130
-  }
131
-  print $fout "</span>\n";
132
-}
133
-
134
-sub write_prefix_header {
135
-  my ($fout, $prefix, $day) = @_;
136
-  
137
-  $day = "table" if ($day == 0);
138
-  print $fout "<span class=\"location\">";
139
-  if ($prefix eq "") {
140
-    print $fout "Kaikki ";
141
-  } else {
142
-    print $fout "<a href=\"$global_prefix/$day.html\">Kaikki</a> ";
143
-  }
144
-  if ($prefix eq "tay/") {
145
-    print $fout "TaY ";
146
-  } else {
147
-    print $fout "<a href=\"$global_prefix/tay/$day.html\">TaY</a> ";
148
-  }
149
-  if ($prefix eq "tays/") {
150
-    print $fout "TAYS ";
151
-  } else {
152
-    print $fout "<a href=\"$global_prefix/tays/$day.html\">TAYS</a> ";
153
-  }
154
-  if ($prefix eq "tty/") {
155
-    print $fout "TTY ";
156
-  } else {
157
-    print $fout "<a href=\"$global_prefix/tty/$day.html\">TTY</a> ";
158
-  }
159
-  print $fout "</span>\n";
160
-}
161
-
162
-sub write_day {
163
-  my ($day, $header, $outfname, $last_day, $restaurants_ref, $prefix) = @_;
164
-  my @restaurants = @{$restaurants_ref};
165
-
166
-  open(my $fout, ">$outfname") || die ("Can't create file $outfname");
167
-  print $fout "$file_header<h1>$header</h1>\n";
168
-  # print weekday links
169
-  print $fout "<div class=\"title\">\n";
170
-  write_days_header($fout, $day, $last_day);
171
-  print $fout "  <span class=\"allergy\">Näytä: ";
172
-  foreach my $a (@allergies) {
173
-    print $fout "<input type=\"checkbox\" name=\"allergy_$a\" id=\"allergy_$a\" onclick=\"highlight()\" />";
174
-    print $fout "<span title=\"".$allergy_descriptions{$a}."\">$a</span>";
175
-  }
176
-  print $fout "</span>\n";
177
-  write_prefix_header($fout, $prefix, $day+1);
178
-  print $fout "</div>\n";
179
-
180
-  # print foods
181
-  my $foodnum = 0;
182
-  my %eatable_food_numbers;
183
-  my %maybe_eatable_food_numbers;
184
-  my $class = "left";
185
-  print $fout "<div class=\"foods\"><div class=\"$class\">\n";
186
-  foreach my $r (@restaurants) {
187
-    my ($title, $open_hours, $week, $week_foods_ref, $info_ref) = @{$r};
188
-    my ($title2, $url, $lazy_allergies, $info_class) = @{$info_ref};
189
-    my @week_foods = @{$week_foods_ref};
190
-    if (defined($week_foods[$day]) || $day < 5) {
191
-
192
-      if ($info_class ne $class) {
193
-	$class = $info_class;
194
-	print $fout "</div><div class=\"$class\">\n";
195
-      }
196
-      $url =~ s/&/&amp;/g;
197
-      print $fout "<h2><a href=\"$url\">$title</a></h2>\n";
198
-      
199
-      if (!defined($week_foods[$day])) {
200
-	print $fout "<p class=\"missing\">Ruokalistaa ei saatavilla.</p>";
201
-	next;
202
-      }
203
-      if ($week ne "" && $week != $max_week) {
204
-	if ($week > $max_week || ($week == 1 && $max_week == 52)) {
205
-	  # early..
206
-	  print $fout "<p class=\"nextweek\">Viikon $week ruokalista:</p>";
207
-	} else {
208
-	  print $fout "<p class=\"missing\">Saatavilla vain viikon $week ruokalista.</p>";
209
-	  next;
210
-	}
211
-      }
212
-      if (scalar(@{$week_foods[$day]}) == 0) {
213
-	print $fout "<p class=\"missing\">Ei ruokatietoja päivälle.</p>";
214
-	next;
215
-      }
216
-      
217
-      print $fout "<ul class=\"food\">\n";
218
-      foreach my $food (@{$week_foods[$day]}) {
219
-	my $output = "";
220
-	my %total_allergies;
221
-	my %maybe_allergies;
222
-	my $part_count = 0;
223
-	foreach my $part (split("\n", $food)) {
224
-	  next if ($part =~ /^(Peruna|Riisi) /); # who cares?
225
-	  # fries: well, maybe we do care, but we don't care about allergy stuff
226
-	  # and keep it in the same line as the previous food so as not to
227
-	  # waste visible space
228
-	  my $fries = ($part =~ /^(Tikkuperunat|Ranskalaiset perunat)/);
229
-	  $part_count++;
230
-	  
231
-	  # add missing () around allergies
232
-	  $part =~ s/ (([MLGK]|VL|Ve|Veg|Hot)(,([MLGK]|VL|Ve|Veg|Hot|))+)$/ ($1)/;
233
-	  
234
-	  if ($part =~ /^(.*) \(([^\)]+)\)$/) {
235
-	    # fix allergy issues
236
-	    my ($food, $allergy) = ($1, $2);
237
-	    # standardization
238
-	    $allergy =~ s/Kasvis/K/g;
239
-	    $allergy =~ s/([MLGK]|VL)([MLGK]|VL)/$1,$2/g;
240
-	    # spaces to commas
241
-	    $allergy =~ s/saatavana[: ]+(.*)$/eriks: $1/;
242
-	    $allergy =~ s/ +/,/g;
243
-	    # remove double commas
244
-	    $allergy =~ s/,+/,/g;
245
-	    # eriks: standardization
246
-	    $allergy =~ s/,?eriks:,?/, eriks: /g;
247
-	    # remove extra commas/spaces from beginning/end
248
-	    $allergy =~ s/^[, ]+//;
249
-	    $allergy =~ s/[, ]+$//;
250
-	    $part = "$food ($allergy)";
251
-	  }
252
-	  
253
-	  $output .= "<br />\n" if ($output ne "" && !$fries);
254
-	  if ($part =~ /Saatavana myös: (.*)/) {
255
-	    # standardize allergy stuff
256
-	    my $alt = $1;
257
-	    $alt =~ s/^\((.*)\)$/$1/;
258
-	    $alt =~ s/[, ]+/,/g;
259
-	    $alt =~ s/^,+//;
260
-	    $alt =~ s/,+$//;
261
-	    $part =~ s/\)[- ]*Saatavana myös:.*/, eriks: $alt)/;
262
-	    $part =~ s/[- ]*Saatavana myös:.*/ (eriks: $alt)/;
263
-	  }
264
-	  if ($part =~ /^(.*)(\([^\)]+\))$/) {
265
-	    my ($text, $allergy) = ($1, $2);
266
-	    if ($fries) {
267
-	      $output .= ", $text";
268
-	    } else {
269
-	      $output .= "$text <span class=\"allergy\">$allergy</span>";
270
-	    }
271
-	    $allergy =~ s/^\((.*)\)$/$1/;
272
-	    $allergy =~ s/ *eriks: //;
273
-	    my %this_allergies;
274
-	    foreach my $a (split(/[, ]/, $allergy)) {
275
-	      foreach my $al (@allergies) {
276
-		if ($a eq $al) {
277
-		  $this_allergies{$a} = 1;
278
-		  last;
279
-		}
280
-	      }
281
-	    }
282
-	    # is M=L always correct? not at least in all restaurants..
283
-	    #$this_allergies{"L"} = 1 if ($this_allergies{"M"});
284
-	    $this_allergies{"VL"} = 1 if ($this_allergies{"L"});
285
-	    foreach my $a (keys %this_allergies) {
286
-	      $total_allergies{$a}++;
287
-	      $maybe_allergies{$a}++;
288
-	    }
289
-	    if ($lazy_allergies =~ /M/) {
290
-	      # L might mean M
291
-	      if ($this_allergies{"L"} && !$this_allergies{"M"}) {
292
-		$maybe_allergies{"M"}++;
293
-	      }
294
-	    }
295
-	  } else {
296
-	    if ($lazy_allergies eq "all") {
297
-	      # no allergy info, make everything maybe
298
-	      foreach my $a (@allergies) {
299
-		$maybe_allergies{$a}++;
300
-	      }
301
-	    }
302
-	    $output .= $part;
303
-	  }
304
-	}
305
-	my $allergy_output = "";
306
-	foreach my $a (@allergies) {
307
-	  if ($total_allergies{$a} == $part_count) {
308
-	    if (!defined($eatable_food_numbers{$a})) {
309
-	      $eatable_food_numbers{$a} = "";
310
-	    } else {
311
-	      $eatable_food_numbers{$a} .= ",";
312
-	    }
313
-	    $eatable_food_numbers{$a} .= $foodnum;
314
-	  } elsif ($maybe_allergies{$a} == $part_count) {
315
-	    if (!defined($maybe_eatable_food_numbers{$a})) {
316
-	      $maybe_eatable_food_numbers{$a} = "";
317
-	    } else {
318
-	      $maybe_eatable_food_numbers{$a} .= ",";
319
-	    }
320
-	    $maybe_eatable_food_numbers{$a} .= $foodnum;
321
-	  }
322
-	}
323
-	print $fout "  <li id=\"f$foodnum\">$output</li>\n";
324
-	$foodnum++;
325
-      }
326
-      print $fout "</ul>\n";
327
-    }
328
-  }
329
-  # write allergy scripts
330
-  print $fout '<script type="text/javascript" src="'.$global_prefix.'/ruoka.js"></script>';
331
-  print $fout '<script type="text/javascript">';
332
-  print $fout "var eatable_foods = [];";
333
-  print $fout "var maybe_eatable_foods = [];";
334
-  foreach my $a (@allergies) {
335
-    print $fout "eatable_foods[\"$a\"] = [".$eatable_food_numbers{$a}."];\n";
336
-    print $fout "maybe_eatable_foods[\"$a\"] = [".$maybe_eatable_food_numbers{$a}."];\n";
337
-  }
338
-  my @allergy_strings = map('"'.$_.'"', @allergies);
339
-  print $fout "var allergies = [".join(",", @allergy_strings)."];\n";
340
-  print $fout "var food_count = $foodnum\n";
341
-  print $fout "window.onload = function() { set_allergies(); show_warning(); };\n";
342
-  print $fout "</script>\n";
343
-
344
-  print $fout "</div></div>$file_footer";
345
-  close $fout;
346
-}
347
-
348
-sub write_all_days {
349
-  my ($restaurants_ref, $prefix, $title) = @_;
350
-  my $last_day = find_last_day_with_foods($restaurants_ref);
351
-  
352
-  for (my $day = 0; $day < 7; $day++) {
353
-    my $outfname = $prefix.($day+1).".html";
354
-    if ($day > $last_day) {
355
-      unlink($outfname);
356
-      next;
357
-    }
358
-    my $header = $day_names[$day]." - $title vko $max_week$max_week_daterange";
359
-    write_day($day, $header, $outfname, $last_day, $restaurants_ref, $prefix);
360
-  }
361
-}
362
-
363
-sub write_table {
364
-  my ($restaurants_ref, $prefix, $title) = @_;
365
-  my @restaurants = @{$restaurants_ref};
366
-  my $last_day = find_last_day_with_foods($restaurants_ref);
367
-
368
-  my $outfname = $prefix."table.html";
369
-  open(my $fout, ">$outfname") || die ("Can't create file $outfname");
370
-  my $header = "$title vko $max_week$max_week_daterange";
371
-  print $fout "$file_header<h1>$header</h1>\n";
372
-  print $fout "<div class=\"title\">\n";
373
-  write_days_header($fout, -1, $last_day);
374
-  write_prefix_header($fout, $prefix, 0);
375
-  print $fout "</div><table border=\"1\"><tr><th>Päivä</th>";
376
-  foreach my $r (@restaurants) {
377
-    my ($title, $open_hours, $week, $week_foods_ref, $info_ref) = @{$r};
378
-    my ($title2, $url) = @{$info_ref};
379
-    $url =~ s/&/&nbsp;/g;
380
-    print $fout "<th><a href=\"$url\">$title</a></th>";
381
-  }
382
-  print $fout "</tr>\n";
383
-  for (my $day = 0; $day <= $last_day; $day++) {
384
-    print $fout "<tr><td>".$day_names[$day]."</td>\n";
385
-    foreach my $r (@restaurants) {
386
-      my ($title, $open_hours, $week, $week_foods_ref, $info_ref) = @{$r};
387
-      my @week_foods = @{$week_foods_ref};
388
-      if (defined($week_foods[$day]) && ($week eq "" || $week == $max_week)) {
389
-	print $fout "<td><ul>\n";
390
-	foreach my $food (@{$week_foods[$day]}) {
391
-	  print $fout "<li>$food</li>";
392
-	}
393
-	print $fout "</ul></td>\n";
394
-      } else {
395
-	print $fout "<td></td>\n";
396
-      }
397
-    }
398
-    print $fout "</tr>\n";
399
-  }
400
-  print $fout "</table>$file_footer";
401
-  close $fout;
402
-}
403
-
404
-sub get_restaurants_sorted {
405
-  my @restaurants = @_;
406
-  my @out;
407
-  foreach my $r (@restaurants) {
408
-    push @out, $r if (@{@{$r}[4]}[3] eq "left");
409
-  }
410
-  foreach my $r (@restaurants) {
411
-    push @out, $r if (@{@{$r}[4]}[3] eq "right");
412
-  }
413
-  foreach my $r (@restaurants) {
414
-    my @e = @{@{$r}[4]};
415
-    push @out, $r if ($e[3] eq "middle" && $e[1] !~ /TAMK/);
416
-  }
417
-  foreach my $r (@restaurants) {
418
-    my @e = @{@{$r}[4]};
419
-    push @out, $r if ($e[3] eq "middle" && $e[1] =~ /TAMK/);
420
-  }
421
-  return @out;
422
-}
423
-
424
-sub get_restaurants_with_prefix {
425
-  my $prefix = shift;
426
-  my @out;
427
-  foreach my $r (@_) {
428
-    my $name = @{$r}[0];
429
-    if ($name =~ /^\($prefix\)/) {
430
-      push @out, $r;
431
-    }
432
-  }
433
-  return get_restaurants_sorted(@out);
434
-}
435
-
436
-my $tty_title = "TTY:n ruokalistat";
437
-my @tty = get_restaurants_with_prefix("TTY", @unordered);
438
-write_all_days(\@tty, "tty/", $tty_title);
439
-write_table(\@tty, "tty/", $tty_title);
440
-
441
-my $tay_title = "Tampereen yliopiston ruokalistat";
442
-my @tay = get_restaurants_with_prefix("TaY", @unordered);
443
-write_all_days(\@tay, "tay/", $tay_title);
444
-write_table(\@tay, "tay/", $tay_title);
445
-
446
-my $tays_title = "TAYS:n ruokalistat";
447
-my @tays = get_restaurants_with_prefix("TAYS", @unordered);
448
-write_all_days(\@tays, "tays/", $tays_title);
449
-write_table(\@tays, "tays/", $tays_title);
450
-
451
-foreach my $r (@unordered) {
452
-  if (@{$r}[0] =~ /^\(TaY\)/) {
453
-    @{@{$r}[4]}[3] = "left";
454
-  }
455
-  if (@{$r}[0] =~ /^\(TTY\)/) {
456
-    @{@{$r}[4]}[3] = "right";
457
-  }
458
-  if (@{$r}[0] =~ /^\(TAYS\)/) {
459
-    @{@{$r}[4]}[3] = "middle";
460
-  }
461
-}
462
-
463
-my $all_title = "Tampereen yliopistojen ruokalistat";
464
-my @all_restaurants = get_restaurants_sorted(@unordered);
465
-# move fusion kitchen last
466
-my @fusion = splice(@all_restaurants, 1, 1);
467
-splice(@all_restaurants, 4, 0, @fusion);
468
-
469
-write_all_days(\@all_restaurants, "", $all_title);
470
-write_table(\@all_restaurants, "", $all_title);

+ 0 - 102
juvenes.pl Dosyayı Görüntüle

@@ -1,102 +0,0 @@
1
-use vars qw(@day_names);
2
-use JSON;
3
-
4
-# last two in order are $kitchen_info_id, $menu_type_id
5
-my @restaurant_info = (
6
-  [ "(TaY) Yliopiston Ravintola", "http://www.juvenes.fi/fi-fi/ravintolatjakahvilat/opiskelijaravintolat/tayp%C3%A4%C3%A4kampus/yliopistonravintola.aspx", "M", "left", 13, 60 ],
7
-  [ "(TaY) Yliopiston Ravintola / VegeBar", "http://www.juvenes.fi/fi-fi/ravintolatjakahvilat/opiskelijaravintolat/tayp%C3%A4%C3%A4kampus/yliopistonravintola.aspx", "", "left", 13, 5 ],
8
-  [ "(TaY) Café Campus", "http://www.juvenes.fi/fi-fi/ravintolatjakahvilat/opiskelijaravintolat/tayp%C3%A4%C3%A4kampus/caf%C3%A9campus.aspx", "", "left", 130019, 23 ],
9
-  [ "(TaY) Café Pinni", "http://www.juvenes.fi/fi-fi/ravintolatjakahvilat/opiskelijaravintolat/tayp%C3%A4%C3%A4kampus/caf%C3%A9lunchpinni.aspx", "M", "middle", 130016, 60 ],
10
-  [ "(TAYS) Arvo", "http://www.juvenes.fi/fi-fi/ravintolatjakahvilat/opiskelijaravintolat/taykaupinkampus/arvo.aspx", "M", "left", 5, 60 ],
11
-  [ "(TAYS) Café Lea (Fusion Kitchen)", "http://www.juvenes.fi/fi-fi/ravintolatjakahvilat/opiskelijaravintolat/taykaupinkampus/cafélea.aspx", "M", "left", 50026, 3 ],
12
-  [ "(TAYS) Café Lea (My Salad)", "http://www.juvenes.fi/fi-fi/ravintolatjakahvilat/opiskelijaravintolat/taykaupinkampus/cafélea.aspx", "M", "left", 50026, 76 ],
13
-  [ "(TTY) Newton", "http://www.juvenes.fi/fi-fi/ravintolatjakahvilat/opiskelijaravintolat/ttykampus/newton.aspx", "", "left", 6, 60],
14
-  [ "(TTY) Café Konehuone / Såås bar", "http://www.juvenes.fi/fi-fi/ravintolatjakahvilat/opiskelijaravintolat/ttykampus/caf%C3%A9konehuone.aspx", "", "left", 60038, 77],
15
-  [ "(TTY) Café Konehuone / Fusion Kitchen", "http://www.juvenes.fi/fi-fi/ravintolatjakahvilat/opiskelijaravintolat/ttykampus/caf%C3%A9konehuone.aspx", "", "middle", 60038, 3 ],
16
-  [ "(TAMK) Ziberia", "http://www.juvenes.fi/fi-fi/ravintolatjakahvilat/henkil%C3%B6st%C3%B6ravintolat/ziberia.aspx", "", "middle", 11, 60 ],
17
-#  [ "(TAMK) Frenckell", "http://www.juvenes.fi/fi-fi/ravintolatjakahvilat/henkil%C3%B6st%C3%B6ravintolat/frenckell.aspx", "", "middle", 33, 60 ],
18
-  [ "(TAMK) Frenckell / Såås bar", "http://www.juvenes.fi/fi-fi/ravintolatjakahvilat/henkil%C3%B6st%C3%B6ravintolat/frenckell.aspx", "", "middle", 33, 77 ]
19
-);
20
-
21
-my @restaurants;
22
-my ($open_hours, $day_id, $cur_title);
23
-my ($cur_food, @cur_day_foods, @week_foods);
24
-
25
-sub finish_food {
26
-  chomp $cur_food;
27
-  if ($cur_food =~ /Liha paniini.*tai Kasvis paniini/i && $cur_title eq $pinni_title) {
28
-    # you get this every day, ignore
29
-  } else {
30
-    push @cur_day_foods, utf8_to_8859($cur_food) if ($cur_food ne "");
31
-  }
32
-  $cur_food = "";
33
-}
34
-
35
-sub finish_day {
36
-  push @week_foods, [@cur_day_foods];
37
-  @cur_day_foods = ();
38
-  $day_id = $day_id + 1;
39
-}
40
-
41
-sub get_juvenes_restaurants {
42
-  my $use_old = shift;
43
-  my $count = 0;
44
-  # Loops restraurants
45
-  foreach my $i (@restaurant_info) {
46
-    my @info = @{$i};
47
-    my $kitchen = $info[4];
48
-    my $menutype = $info[5];
49
-    $title = $info[0];
50
-    $cur_title = $title;
51
-    $open_hours = "";
52
-    @week_foods = ();
53
-    my $week = `date +%V`;
54
-    chomp($week);
55
-    # Loop weekdays
56
-    for (my $weekday = 1; $weekday < 7; $weekday++) {
57
-      my $temp_fname = "juvenes$count-$weekday.temp.js";
58
-      my $url = "http://www.juvenes.fi/DesktopModules/Talents.LunchMenu/LunchMenuServices.asmx/GetMenuByWeekday?KitchenId=$kitchen&MenuTypeId=$menutype&Week=$week&Weekday=$weekday&lang='fi'&format=json";
59
-      if (!-f $temp_fname || !$use_old) {
60
-        system("rm -f $temp_fname && wget -q --timeout=10 -O $temp_fname.tmp \"$url\" && mv $temp_fname.tmp $temp_fname");
61
-      }
62
-      if (-f $temp_fname) {
63
-        open(FILE, $temp_fname);
64
-        my $jsonp = do { local $/; <FILE> };
65
-        close(FILE);
66
-        # the file is encapsulated in ({"d": json}); so we have to double parse it
67
-        my $data = from_json(substr($jsonp, 1, -2));
68
-        unless ($data->{'d'} eq 'null') {
69
-          $data = from_json($data->{'d'});
70
-          my $mealoptions = $data->{'MealOptions'};
71
-          # loop different meals
72
-          foreach my $meal_info (@$mealoptions) {
73
-            if ($meal_info->{'ForceMajeure'} ne '') {
74
-              $cur_food = $meal_info->{'ForceMajeure'}; 
75
-            } else {
76
-              my $menuitems = $meal_info->{'MenuItems'};
77
-              # loops different foods in a meal
78
-              foreach my $food_info (@$menuitems) {
79
-                $cur_food .= "\n" if $cur_food ne ""; 
80
-                my $name = $food_info->{'Name'};
81
-                $name =~ s/^\*//;
82
-                $cur_food .= $name;
83
-                $cur_food .= " (" . $food_info->{'Diets'} . ")" if $food_info->{'Diets'};
84
-              }
85
-            }
86
-            if ($cur_food ne "-") {
87
-              finish_food();
88
-            } else {
89
-              $cur_food = "";
90
-            }
91
-          }
92
-        }
93
-        finish_day();
94
-      }
95
-    }
96
-    push @restaurants, [ $title, $open_hours, $week, [ @week_foods ], \@info ];
97
-    $count++;
98
-  }
99
-  return @restaurants;
100
-}
101
-
102
-1;

+ 0 - 169
pky.pl Dosyayı Görüntüle

@@ -1,169 +0,0 @@
1
-use vars qw(@day_names);
2
-
3
-my @short_day_names = ( "ma", "ti", "ke", "to", "pe", "la", "su" );
4
-
5
-#my $pky_url = "http://www.pky.fi/lounaslistat";
6
-my $pky_url = "http://www.pikante.fi/lounaslistat-pdf";
7
-
8
-my @restaurant_info = (
9
-  [ "(TAYS) Finn-Medi", "$pky_url", "all", "middle" ],
10
-  [ "(TAYS) Café Olive", "$pky_url", "all", "middle" ],
11
-  [ "(TAYS) Ellipsi", "$pky_url", "all", "middle" ]
12
-);
13
-
14
-my ($parse_func, $day_id, $week);
15
-my (@cur_day_foods, @week_foods);
16
-my ($show_next_week, $content_title);
17
-
18
-sub utf8_to_8859 {
19
-  $_ = shift;
20
-
21
-  s/ //g;
22
-  s/é/é/g;
23
-  s/ä/ä/g;
24
-  s/ö/ö/g;
25
-  s/Ä/Ä/g;
26
-  s/Ö/Ö/g;
27
-  return $_;
28
-}
29
-
30
-sub pky_finish_day {
31
-  push @week_foods, [@cur_day_foods];
32
-  @cur_day_foods = ();
33
-  $day_id = $day_id + 1;
34
-}
35
-
36
-sub pky_parse_more_food {
37
-  my $token = shift;
38
-  
39
-  if ($token->[0] eq 'T') {
40
-    my $text = utf8_to_8859($token->[1]);
41
-    foreach my $text (split("/", $text)) {
42
-      push @cur_day_foods, $text if ($text ne "");
43
-    }
44
-  } elsif ($token->[0] eq 'E') {
45
-    if ($token->[1] eq 'tr') {
46
-      pky_finish_day();
47
-      $parse_func = \&pky_parse_day_td;
48
-    }
49
-  }
50
-}
51
-
52
-sub pky_parse_day_td {
53
-  my $token = shift;
54
-  
55
-  if ($token->[0] eq 'E') {
56
-    if ($token->[1] eq 'td') {
57
-      $parse_func = \&pky_parse_more_food;
58
-    } elsif ($token->[1] eq 'table') {
59
-      $parse_func = \&pky_parse_to_week;
60
-    }
61
-  } elsif ($token->[0] eq 'T') {
62
-    my $text = $token->[1];
63
-    my $i = 0;
64
-    foreach my $day (@short_day_names) {
65
-      if ($text =~ /$day$/i) {
66
-	while ($day_id < $i) {
67
-	  push @week_foods, [ ];
68
-	  $day_id++;
69
-	}
70
-	last;
71
-      }
72
-      $i++;
73
-    }
74
-  }
75
-}
76
-
77
-sub pky_parse_to_monday {
78
-  my $token = shift;
79
-  
80
-  if ($token->[0] eq 'S' && $token->[1] eq 'tr') {
81
-    $parse_func = \&pky_parse_day_td;
82
-  } elsif ($token->[0] eq 'E' && $token->[1] eq 'table') {
83
-    $parse_func = \&pky_parse_to_week;
84
-  }
85
-}
86
-
87
-sub want_second_week {
88
-  my $week = shift;
89
-
90
-  return 1 if $day_id == 0; # week didn't start from beginning
91
-  
92
-  my @l = localtime;
93
-  my $this_week = strftime("%V", @l);
94
-  return $week == $this_week || ($l[6] == 6 && ($week%52)+1 == $this_week);
95
-}
96
-
97
-sub pky_parse_to_eof {
98
-}
99
-
100
-sub pky_parse_to_week {
101
-  my $token = shift;
102
-  
103
-  if ($token->[0] eq 'T' && $token->[1] =~ /Viikko (\d+)/) {
104
-    my $parsed_week = $1;
105
-    # earlier version could have shown two tables for two weeks
106
-    # sometimes. but the new version? dunno yet..
107
-    #if ($week == 0 || $show_next_week) {
108
-    if ($week == 0) {
109
-      $week = $parsed_week;
110
-      $day_id = 0;
111
-      @cur_day_foods = ();
112
-      @week_foods = ();
113
-      $parse_func = \&pky_parse_to_monday;
114
-    } else {
115
-      $parse_func = \&pky_parse_to_eof;
116
-    }
117
-  }
118
-}
119
-
120
-sub pky_parse_to_title {
121
-  my $token = shift;
122
-  
123
-  if ($token->[0] eq 'T') {
124
-    my $text = utf8_to_8859($token->[1]);
125
-    if ($text =~ /$content_title.*lounasaika/) {
126
-      $parse_func = \&pky_parse_to_week;
127
-    }
128
-  }
129
-}
130
-
131
-sub parse_pky {
132
-  my ($fname, $info_ref) = @_;
133
-  my $p = HTML::TokeParser->new($fname) or die("Can't open file $fname");
134
-  
135
-  my $title = @{$info_ref}[0];
136
-  $week = 0;
137
-  
138
-  $content_title = $title;
139
-  $content_title =~ s/^\(TAYS\) //;
140
-
141
-  $parse_func = \&pky_parse_to_title;
142
-  while (my $token = $p->get_token) {
143
-    &$parse_func($token);
144
-  }
145
-  return [ $title, "", $week, [ @week_foods ], $info_ref ];
146
-}
147
-
148
-sub get_pky_restaurants {
149
-  my $use_old;
150
-  ($use_old, $show_next_week) = @_;
151
-
152
-  my $temp_fname = "pky.temp.html";
153
-  if (!-f $temp_fname || !$use_old) {
154
-    system("wget -q --timeout=10 -O $temp_fname.tmp '$pky_url' && mv $temp_fname.tmp $temp_fname");
155
-  }
156
-  
157
-  my @restaurants = ();
158
-  if (-f $temp_fname) {
159
-    my $count = 0;
160
-    foreach my $i (@restaurant_info) {
161
-      my @info = @{$i};
162
-      push @restaurants, parse_pky($temp_fname, \@info);
163
-      $count++;
164
-    }
165
-  }
166
-  return @restaurants;
167
-}
168
-
169
-1;

+ 0 - 89
sodexo.pl Dosyayı Görüntüle

@@ -1,89 +0,0 @@
1
-use vars qw(@day_names);
2
-use POSIX qw(strftime);
3
-
4
-
5
-my @restaurant_info = (
6
-  [ "(TaY) Sodexo Linna", "http://www.sodexo.fi/linna", "", "right", 92],
7
-  #[ "(TTY) Sodexo Erkkeri", "http://www.sodexo.fi/erkkeri", "", "left", 100]
8
-  [ "(TTY) Sodexo Hertsi", "http://www.sodexo.fi/tty-tietotalo", "", "right", 12812]
9
-);
10
-
11
-my ($cur_text, $cur_title, $parse_func, $day_id, $week);
12
-my (@cur_day_foods, @week_foods);
13
-
14
-sub sodexo_finish_food {
15
-  chomp $cur_food;
16
-  push @cur_day_foods, utf8_to_8859($cur_food) if ($cur_food ne "");
17
-  $cur_food = "";
18
-}
19
-
20
-sub sodexo_finish_day {
21
-  push @week_foods, [@cur_day_foods];
22
-  @cur_day_foods = ();
23
-  $day_id = $day_id + 1;
24
-}
25
-
26
-
27
-sub utf8_to_8859 {
28
-  $_ = shift;
29
-
30
-  s/ä/ä/g;
31
-  s/ö/ö/g;
32
-  s/Ä/Ä/g;
33
-  s/Ö/Ö/g;
34
-  return $_;
35
-}
36
-
37
-sub get_sodexo_restaurants {
38
-  my $use_old = shift;
39
-  my $count = 0;
40
-  # Loops restraurants
41
-  foreach my $i (@restaurant_info) {
42
-    my @info = @{$i};
43
-    my $kitchen = $info[4];
44
-    $title = $info[0];
45
-    $cur_title = $title;
46
-    $open_hours = "";
47
-    @week_foods = ();
48
-    my $week = `date +%V`;
49
-    chomp($week);
50
-    # Loop weekdays
51
-    for (my $weekday = 1; $weekday < 7; $weekday++) {
52
-
53
-      # Get current unix timestamp and week day
54
-      $s = strftime "%s", localtime;
55
-      $v = strftime "%w", localtime;
56
-      # Calculate current weekday 
57
-      $s = $s + ($weekday - $v)  * 86400;
58
-      $timestr = strftime "%Y/%m/%d", localtime($s);
59
-
60
-      my $url = "http://www.sodexo.fi/ruokalistat/output/daily_json/$kitchen/$timestr/fi";
61
-      my $temp_fname = "sodexo$count-$weekday.temp.js";  
62
-      if (!-f $temp_fname || !$use_old) {
63
-        system("wget -q --timeout=10 -O $temp_fname.tmp \"$url\" && mv $temp_fname.tmp $temp_fname");
64
-      }
65
-      if (-f $temp_fname) {
66
-        open(FILE, $temp_fname);
67
-        my $json = do { local $/; <FILE> };
68
-        close(FILE);
69
-        # the file is encapsulated in ({"d": json}); so we have to double parse it
70
-        my $data = from_json($json);
71
-        my $courses = $data->{'courses'};
72
-        # loop different meals
73
-        foreach my $course_info (@$courses) {
74
-          if ($course_info->{'category'} ne 'Aamupala') {
75
-            $cur_food = $course_info->{'title_fi'};
76
-            $cur_food .= " (" . $course_info->{'properties'} . ")" if $course_info->{'properties'};
77
-          }
78
-          sodexo_finish_food();
79
-        }
80
-        sodexo_finish_day();
81
-      }
82
-    }
83
-    push @restaurants, [ $title, $open_hours, $week, [ @week_foods ], \@info ];
84
-    $count++;
85
-  }
86
-  return @restaurants;
87
-}
88
-
89
-1;