Browse Source

Add reason for juvenes if not open

Toni Fadjukoff 7 years ago
parent
commit
99e1e63854
2 changed files with 31 additions and 20 deletions
  1. 5 4
      food.py
  2. 26 16
      juvenes.py

+ 5 - 4
food.py View File

172
         css_class = "left"
172
         css_class = "left"
173
         fout.write("<div class=\"foods\"><div class=\"{css_class}\">\n".format(css_class=css_class))
173
         fout.write("<div class=\"foods\"><div class=\"{css_class}\">\n".format(css_class=css_class))
174
         for r in restaurants:
174
         for r in restaurants:
175
-            title, open_hours, week, week_foods, info = r
175
+            title, open_hours, week, week_foods, info = r[:5]
176
+            exception = r[5].replace("\n", "<br>") if len(r) > 5 and r[5] else "Ruokalistaa ei saatavilla."
176
             title2, url, lazy_allergies, info_class = info[0:4]
177
             title2, url, lazy_allergies, info_class = info[0:4]
177
             if day in week_foods or day < 5:
178
             if day in week_foods or day < 5:
178
                 if info_class != css_class:
179
                 if info_class != css_class:
181
                 url = url.replace("&", "&amp;")
182
                 url = url.replace("&", "&amp;")
182
                 fout.write("<h2><a href=\"{url}\">{title}</a></h2>\n".format(url=url, title=title))
183
                 fout.write("<h2><a href=\"{url}\">{title}</a></h2>\n".format(url=url, title=title))
183
                 if not day in week_foods:
184
                 if not day in week_foods:
184
-                    fout.write("<p class=\"missing\">Ruokalistaa ei saatavilla.</p>")
185
+                    fout.write("<p class=\"missing\">{exception}</p>".format(exception=exception))
185
                     continue
186
                     continue
186
                 if week != "" and week != max_week:
187
                 if week != "" and week != max_week:
187
                     if week > max_week or (week == 1 and max_week == 52):
188
                     if week > max_week or (week == 1 and max_week == 52):
336
         write_prefix_header(fout, prefix, 0, resources_prefix)
337
         write_prefix_header(fout, prefix, 0, resources_prefix)
337
         fout.write("</div><table border=\"1\"><tr><th>Päivä</th>")
338
         fout.write("</div><table border=\"1\"><tr><th>Päivä</th>")
338
         for r in restaurants:
339
         for r in restaurants:
339
-            (title, open_hours, week, week_foods, info) = r
340
+            (title, open_hours, week, week_foods, info) = r[:5]
340
             (title2, url) = info[0:2]
341
             (title2, url) = info[0:2]
341
             url = re.sub("&", "&nbsp;", url)
342
             url = re.sub("&", "&nbsp;", url)
342
             fout.write("<th><a href=\"{url}\">{title}</a></th>".format(url=url, title=title))
343
             fout.write("<th><a href=\"{url}\">{title}</a></th>".format(url=url, title=title))
344
         for day in range(last_day):
345
         for day in range(last_day):
345
             fout.write("<tr><td>{day_name}</td>\n".format(day_name=day_names[day]))
346
             fout.write("<tr><td>{day_name}</td>\n".format(day_name=day_names[day]))
346
             for r in restaurants:
347
             for r in restaurants:
347
-                (title, open_hours, week, week_foods, info) = r
348
+                (title, open_hours, week, week_foods, info) = r[:5]
348
                 if day in week_foods and (week == "" or week == max_week):
349
                 if day in week_foods and (week == "" or week == max_week):
349
                     fout.write("<td><ul>\n")
350
                     fout.write("<td><ul>\n")
350
                     for food in week_foods[day]:
351
                     for food in week_foods[day]:

+ 26 - 16
juvenes.py View File

4
 import re
4
 import re
5
 import json
5
 import json
6
 
6
 
7
-# last two in order are $kitchen_info_id, $menu_type_id
7
+# Last three columns are Kitchen Info ID, Menu Type ID and Concept ID. There may be multiple concepts in a single restauranta.
8
+# Juvenes API defines also Restaurant ID but that is not used.
8
 restaurant_info = [
9
 restaurant_info = [
9
-  [ "(TaY) Yliopiston Ravintola", "http://www.juvenes.fi/fi-fi/ravintolatjakahvilat/opiskelijaravintolat/tayp%C3%A4%C3%A4kampus/yliopistonravintola.aspx", "M", "left", 13, 60 ],
10
-  [ "(TaY) Yliopiston Ravintola / VegeBar", "http://www.juvenes.fi/fi-fi/ravintolatjakahvilat/opiskelijaravintolat/tayp%C3%A4%C3%A4kampus/yliopistonravintola.aspx", "", "left", 13, 5 ],
11
-  [ "(TaY) Café Campus", "http://www.juvenes.fi/fi-fi/ravintolatjakahvilat/opiskelijaravintolat/tayp%C3%A4%C3%A4kampus/caf%C3%A9campus.aspx", "", "left", 130019, 23 ],
12
-  [ "(TaY) Café Pinni", "http://www.juvenes.fi/fi-fi/ravintolatjakahvilat/opiskelijaravintolat/tayp%C3%A4%C3%A4kampus/caf%C3%A9lunchpinni.aspx", "M", "middle", 130016, 60 ],
13
-  [ "(TAYS) Arvo", "http://www.juvenes.fi/fi-fi/ravintolatjakahvilat/opiskelijaravintolat/taykaupinkampus/arvo.aspx", "M", "left", 5, 60 ],
14
-  [ "(TAYS) Café Lea (Fusion Kitchen)", "http://www.juvenes.fi/fi-fi/ravintolatjakahvilat/opiskelijaravintolat/taykaupinkampus/cafélea.aspx", "M", "left", 50026, 3 ],
15
-  [ "(TAYS) Café Lea (My Salad)", "http://www.juvenes.fi/fi-fi/ravintolatjakahvilat/opiskelijaravintolat/taykaupinkampus/cafélea.aspx", "M", "left", 50026, 76 ],
16
-  [ "(TTY) Newton", "http://www.juvenes.fi/fi-fi/ravintolatjakahvilat/opiskelijaravintolat/ttykampus/newton.aspx", "", "left", 6, 60],
17
-  [ "(TTY) Café Konehuone / Såås bar", "http://www.juvenes.fi/fi-fi/ravintolatjakahvilat/opiskelijaravintolat/ttykampus/caf%C3%A9konehuone.aspx", "", "left", 60038, 77],
18
-  [ "(TTY) Café Konehuone / Fusion Kitchen", "http://www.juvenes.fi/fi-fi/ravintolatjakahvilat/opiskelijaravintolat/ttykampus/caf%C3%A9konehuone.aspx", "", "middle", 60038, 3 ],
19
-  [ "(TAMK) Ziberia", "http://www.juvenes.fi/fi-fi/ravintolatjakahvilat/henkil%C3%B6st%C3%B6ravintolat/ziberia.aspx", "", "middle", 11, 60 ],
20
-#  [ "(TAMK) Frenckell", "http://www.juvenes.fi/fi-fi/ravintolatjakahvilat/henkil%C3%B6st%C3%B6ravintolat/frenckell.aspx", "", "middle", 33, 60 ],
21
-  [ "(TAMK) Frenckell / Såås bar", "http://www.juvenes.fi/fi-fi/ravintolatjakahvilat/henkil%C3%B6st%C3%B6ravintolat/frenckell.aspx", "", "middle", 33, 77 ]
10
+  [ "(TaY) Yliopiston Ravintola", "http://www.juvenes.fi/fi-fi/ravintolatjakahvilat/opiskelijaravintolat/tayp%C3%A4%C3%A4kampus/yliopistonravintola.aspx", "M", "left", 13, 60, []],
11
+  [ "(TaY) Yliopiston Ravintola / VegeBar", "http://www.juvenes.fi/fi-fi/ravintolatjakahvilat/opiskelijaravintolat/tayp%C3%A4%C3%A4kampus/yliopistonravintola.aspx", "", "left", 13, 5, []],
12
+  [ "(TaY) Café Campus", "http://www.juvenes.fi/fi-fi/ravintolatjakahvilat/opiskelijaravintolat/tayp%C3%A4%C3%A4kampus/caf%C3%A9campus.aspx", "", "left", 130019, 23, []],
13
+  [ "(TaY) Café Pinni", "http://www.juvenes.fi/fi-fi/ravintolatjakahvilat/opiskelijaravintolat/tayp%C3%A4%C3%A4kampus/caf%C3%A9lunchpinni.aspx", "M", "middle", 130016, 60, []],
14
+  [ "(TAYS) Arvo", "http://www.juvenes.fi/fi-fi/ravintolatjakahvilat/opiskelijaravintolat/taykaupinkampus/arvo.aspx", "M", "left", 5, 60, []],
15
+  [ "(TAYS) Café Lea (Fusion Kitchen)", "http://www.juvenes.fi/fi-fi/ravintolatjakahvilat/opiskelijaravintolat/taykaupinkampus/cafélea.aspx", "M", "left", 50026, 3, []],
16
+  [ "(TAYS) Café Lea (My Salad)", "http://www.juvenes.fi/fi-fi/ravintolatjakahvilat/opiskelijaravintolat/taykaupinkampus/cafélea.aspx", "M", "left", 50026, 76, []],
17
+  [ "(TTY) Newton", "http://www.juvenes.fi/fi-fi/ravintolatjakahvilat/opiskelijaravintolat/ttykampus/newton.aspx", "", "left", 6, 60, [1149]],
18
+  [ "(TTY) Café Konehuone / Såås bar", "http://www.juvenes.fi/fi-fi/ravintolatjakahvilat/opiskelijaravintolat/ttykampus/caf%C3%A9konehuone.aspx", "", "left", 60038, 77, [3663]],
19
+  [ "(TTY) Café Konehuone / Fusion Kitchen", "http://www.juvenes.fi/fi-fi/ravintolatjakahvilat/opiskelijaravintolat/ttykampus/caf%C3%A9konehuone.aspx", "", "middle", 60038, 3, [1674]],
20
+  [ "(TAMK) Ziberia", "http://www.juvenes.fi/fi-fi/ravintolatjakahvilat/henkil%C3%B6st%C3%B6ravintolat/ziberia.aspx", "", "middle", 11, 60, []],
21
+  [ "(TAMK) Frenckell / Såås bar", "http://www.juvenes.fi/fi-fi/ravintolatjakahvilat/henkil%C3%B6st%C3%B6ravintolat/frenckell.aspx", "", "middle", 33, 77, []]
22
 ]
22
 ]
23
 
23
 
24
 
24
 
27
     for count, info in enumerate(restaurant_info):
27
     for count, info in enumerate(restaurant_info):
28
         kitchen = info[4]
28
         kitchen = info[4]
29
         menutype = info[5]
29
         menutype = info[5]
30
+        concepts = info[6]
30
         title = info[0]
31
         title = info[0]
31
         cur_title = title
32
         cur_title = title
32
         open_hours = ""
33
         open_hours = ""
34
+        exception = None
33
         week_foods = {}
35
         week_foods = {}
34
         for weekday in range(1,7):
36
         for weekday in range(1,7):
35
             url = "http://www.juvenes.fi/DesktopModules/Talents.LunchMenu/LunchMenuServices.asmx/GetMenuByWeekday?KitchenId={kitchen}&MenuTypeId={menutype}&Week={week}&Weekday={weekday}&lang='fi'&format=json".format(kitchen=kitchen, menutype=menutype, week=week, weekday=weekday)
37
             url = "http://www.juvenes.fi/DesktopModules/Talents.LunchMenu/LunchMenuServices.asmx/GetMenuByWeekday?KitchenId={kitchen}&MenuTypeId={menutype}&Week={week}&Weekday={weekday}&lang='fi'&format=json".format(kitchen=kitchen, menutype=menutype, week=week, weekday=weekday)
36
             temp_fname = "juvenes_{count}-{weekday}.temp.js".format(count=count, weekday=weekday)
38
             temp_fname = "juvenes_{count}-{weekday}.temp.js".format(count=count, weekday=weekday)
37
             data = pnalib.get_jsonp_file(url, temp_fname, use_old, allow_old=False)
39
             data = pnalib.get_jsonp_file(url, temp_fname, use_old, allow_old=False)
38
-            if data and data["d"] != "null":
40
+            if not data:
41
+                # Try to find problem
42
+                for concept in concepts:
43
+                    url = "http://www.juvenes.fi/DesktopModules/Talents.Restaurants/RestaurantsService.svc/GetConcept?menuId={concept}&lang=fi".format(concept=concept)
44
+                    temp_fname = "juvenes_{count}-{weekday}-{concept}.temp.js".format(count=count, weekday=weekday, concept=concept)
45
+                    data = pnalib.get_json_file(url, temp_fname, use_old, allow_old=False)
46
+                    if data and data["d"]:
47
+                        exception = data["d"]["OpenInfo"]["Exeption1InfoText"]
48
+            elif data and data["d"] != "null":
39
                 data = json.loads(data["d"])
49
                 data = json.loads(data["d"])
40
                 cur_day_foods = []
50
                 cur_day_foods = []
41
                 mealoptions = data["MealOptions"]
51
                 mealoptions = data["MealOptions"]
55
                     if cur_food != ["-"]:
65
                     if cur_food != ["-"]:
56
                         cur_day_foods.append("\n".join(cur_food))
66
                         cur_day_foods.append("\n".join(cur_food))
57
                 week_foods[weekday-1] = cur_day_foods
67
                 week_foods[weekday-1] = cur_day_foods
58
-        restaurants.append([title, open_hours, week, week_foods, info])
68
+        restaurants.append([title, open_hours, week, week_foods, info, exception])
59
     return restaurants
69
     return restaurants