Bladeren bron

Add reason for juvenes if not open

Toni Fadjukoff 7 jaren geleden
bovenliggende
commit
99e1e63854
2 gewijzigde bestanden met toevoegingen van 31 en 20 verwijderingen
  1. 5 4
      food.py
  2. 26 16
      juvenes.py

+ 5 - 4
food.py Bestand weergeven

@@ -172,7 +172,8 @@ def write_day(day, header, outfname, last_day, restaurants, prefix, resources_pr
172 172
         css_class = "left"
173 173
         fout.write("<div class=\"foods\"><div class=\"{css_class}\">\n".format(css_class=css_class))
174 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 177
             title2, url, lazy_allergies, info_class = info[0:4]
177 178
             if day in week_foods or day < 5:
178 179
                 if info_class != css_class:
@@ -181,7 +182,7 @@ def write_day(day, header, outfname, last_day, restaurants, prefix, resources_pr
181 182
                 url = url.replace("&", "&amp;")
182 183
                 fout.write("<h2><a href=\"{url}\">{title}</a></h2>\n".format(url=url, title=title))
183 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 186
                     continue
186 187
                 if week != "" and week != max_week:
187 188
                     if week > max_week or (week == 1 and max_week == 52):
@@ -336,7 +337,7 @@ def write_table(restaurants, prefix, title, resources_prefix):
336 337
         write_prefix_header(fout, prefix, 0, resources_prefix)
337 338
         fout.write("</div><table border=\"1\"><tr><th>Päivä</th>")
338 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 341
             (title2, url) = info[0:2]
341 342
             url = re.sub("&", "&nbsp;", url)
342 343
             fout.write("<th><a href=\"{url}\">{title}</a></th>".format(url=url, title=title))
@@ -344,7 +345,7 @@ def write_table(restaurants, prefix, title, resources_prefix):
344 345
         for day in range(last_day):
345 346
             fout.write("<tr><td>{day_name}</td>\n".format(day_name=day_names[day]))
346 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 349
                 if day in week_foods and (week == "" or week == max_week):
349 350
                     fout.write("<td><ul>\n")
350 351
                     for food in week_foods[day]:

+ 26 - 16
juvenes.py Bestand weergeven

@@ -4,21 +4,21 @@ import datetime
4 4
 import re
5 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 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,15 +27,25 @@ def get_restaurants(use_old, week):
27 27
     for count, info in enumerate(restaurant_info):
28 28
         kitchen = info[4]
29 29
         menutype = info[5]
30
+        concepts = info[6]
30 31
         title = info[0]
31 32
         cur_title = title
32 33
         open_hours = ""
34
+        exception = None
33 35
         week_foods = {}
34 36
         for weekday in range(1,7):
35 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 38
             temp_fname = "juvenes_{count}-{weekday}.temp.js".format(count=count, weekday=weekday)
37 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 49
                 data = json.loads(data["d"])
40 50
                 cur_day_foods = []
41 51
                 mealoptions = data["MealOptions"]
@@ -55,5 +65,5 @@ def get_restaurants(use_old, week):
55 65
                     if cur_food != ["-"]:
56 66
                         cur_day_foods.append("\n".join(cur_food))
57 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 69
     return restaurants