123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103 |
- use vars qw(@day_names);
- use JSON;
-
- # last two in order are $kitchen_info_id, $menu_type_id
- my @restaurant_info = (
- [ "(TaY) Yliopiston Ravintola", "http://www.juvenes.fi/fi-fi/ravintolatjakahvilat/opiskelijaravintolat/tayp%C3%A4%C3%A4kampus/yliopistonravintola.aspx", "M", "left", 13, 60 ],
- [ "(TaY) Yliopiston Ravintola / VegeBar", "http://www.juvenes.fi/fi-fi/ravintolatjakahvilat/opiskelijaravintolat/tayp%C3%A4%C3%A4kampus/yliopistonravintola.aspx", "", "left", 13, 5 ],
- [ "(TaY) Café Campus", "http://www.juvenes.fi/fi-fi/ravintolatjakahvilat/opiskelijaravintolat/tayp%C3%A4%C3%A4kampus/caf%C3%A9campus.aspx", "", "left", 130019, 23 ],
- [ "(TaY) Café Pinni", "http://www.juvenes.fi/fi-fi/ravintolatjakahvilat/opiskelijaravintolat/tayp%C3%A4%C3%A4kampus/caf%C3%A9lunchpinni.aspx", "M", "middle", 130016, 60 ],
- [ "(TAYS) Arvo", "http://www.juvenes.fi/fi-fi/ravintolatjakahvilat/opiskelijaravintolat/taykaupinkampus/arvo.aspx", "M", "left", 5, 60 ],
- [ "(TAYS) Café Lea (Fusion Kitchen)", "http://www.juvenes.fi/fi-fi/ravintolatjakahvilat/opiskelijaravintolat/taykaupinkampus/cafélea.aspx", "M", "left", 50026, 3 ],
- [ "(TAYS) Café Lea (My Salad)", "http://www.juvenes.fi/fi-fi/ravintolatjakahvilat/opiskelijaravintolat/taykaupinkampus/cafélea.aspx", "M", "left", 50026, 76 ],
- [ "(TTY) Newton", "http://www.juvenes.fi/fi-fi/ravintolatjakahvilat/opiskelijaravintolat/ttykampus/newton.aspx", "", "left", 6, 60],
- [ "(TTY) Café Konehuone / Såås bar", "http://www.juvenes.fi/fi-fi/ravintolatjakahvilat/opiskelijaravintolat/ttykampus/caf%C3%A9konehuone/s%C3%A5%C3%A5sbar.aspx", "", "left", 60038, 77],
- [ "(TTY) Café Konehuone / Fusion Kitchen", "http://www.juvenes.fi/fi-fi/ravintolatjakahvilat/opiskelijaravintolat/ttykampus/caf%C3%A9konehuone/fusionkitchen.aspx", "", "middle", 60038, 3 ],
- [ "(TAMK) Ziberia", "http://www.juvenes.fi/fi-fi/ravintolatjakahvilat/henkil%C3%B6st%C3%B6ravintolat/ziberia.aspx", "", "middle", 11, 60 ],
- # [ "(TAMK) Frenckell", "http://www.juvenes.fi/fi-fi/ravintolatjakahvilat/henkil%C3%B6st%C3%B6ravintolat/frenckell.aspx", "", "middle", 33, 60 ],
- [ "(TAMK) Frenckell / Såås bar", "http://www.juvenes.fi/fi-fi/ravintolatjakahvilat/henkil%C3%B6st%C3%B6ravintolat/frenckell.aspx", "", "middle", 33, 77 ]
- );
-
- my @restaurants;
- my ($open_hours, $day_id, $cur_title);
- my ($cur_food, @cur_day_foods, @week_foods);
-
- sub finish_food {
- chomp $cur_food;
- if ($cur_food =~ /Liha paniini.*tai Kasvis paniini/i && $cur_title eq $pinni_title) {
- # you get this every day, ignore
- } else {
- push @cur_day_foods, utf8_to_8859($cur_food) if ($cur_food ne "");
- }
- $cur_food = "";
- }
-
- sub finish_day {
- push @week_foods, [@cur_day_foods];
- @cur_day_foods = ();
- $day_id = $day_id + 1;
- }
-
- sub get_juvenes_restaurants {
- my $use_old = shift;
- my $count = 0;
- # Loops restraurants
- foreach my $i (@restaurant_info) {
- my @info = @{$i};
- my $kitchen = $info[4];
- my $menutype = $info[5];
- $title = $info[0];
- $cur_title = $title;
- $open_hours = "";
- @week_foods = ();
- my $week = `date +%V`;
- chomp($week);
- # Loop weekdays
- for (my $weekday = 1; $weekday < 7; $weekday++) {
- my $temp_fname = "juvenes$count-$weekday.temp.js";
- my $url = "http://www.juvenes.fi/DesktopModules/Talents.LunchMenu/LunchMenuServices.asmx/GetMenuByWeekday?KitchenId=$kitchen&MenuTypeId=$menutype&Week=$week&Weekday=$weekday&lang='fi'&format=json";
- if (!-f $temp_fname || !$use_old) {
- system("rm -f $temp_fname && wget -q --timeout=10 -O $temp_fname.tmp \"$url\" && mv $temp_fname.tmp $temp_fname");
- }
- if (-f $temp_fname) {
- open(FILE, $temp_fname);
- my $jsonp = do { local $/; <FILE> };
- close(FILE);
- # the file is encapsulated in ({"d": json}); so we have to double parse it
- my $data = from_json(substr($jsonp, 1, -2));
- unless ($data->{'d'} eq 'null') {
- $data = from_json($data->{'d'});
- my $mealoptions = $data->{'MealOptions'};
- # loop different meals
- foreach my $meal_info (@$mealoptions) {
- if ($meal_info->{'ForceMajeure'} ne '') {
- $cur_food = $meal_info->{'ForceMajeure'};
- } else {
- my $menuitems = $meal_info->{'MenuItems'};
- # loops different foods in a meal
- foreach my $food_info (@$menuitems) {
- $cur_food .= "\n" if $cur_food ne "";
- my $name = $food_info->{'Name'};
- $name =~ s/^\*//;
- $cur_food .= $name;
- $cur_food .= " (" . $food_info->{'Diets'} . ")" if $food_info->{'Diets'};
- }
- }
- if ($cur_food ne "-") {
- finish_food();
- } else {
- $cur_food = "";
- }
- }
- }
- finish_day();
- }
- }
- push @restaurants, [ $title, $open_hours, $week, [ @week_foods ], \@info ];
- $count++;
- }
- return @restaurants;
- }
-
- 1;
|