Browse Source

Support Fazer Minerva menu again

Toni Fadjukoff 6 years ago
parent
commit
f602e72a82
1 changed files with 39 additions and 31 deletions
  1. 39 31
      amica.py

+ 39 - 31
amica.py View File

@@ -2,8 +2,8 @@ import pnalib
2 2
 import datetime
3 3
 
4 4
 restaurant_info = [
5
-  [ "(TaY) Amica Minerva", "http://www.amica.fi/minerva", "", "middle", "https://www.amica.fi/modules/json/json/Index?costNumber=0815&language=fi" ],
6
-  [ "(TaY) Tampereen normaalikoulun ravintola", "http://www.amica.fi/tampereennormaalikoulu", "", "middle", "https://www.amica.fi/modules/json/json/Index?costNumber=0811&language=fi" ],
5
+  [ "(TaY) Amica Minerva", "https://www.fazerfoodco.fi/ravintolat/Ravintolat-kaupungeittain/tampere/minerva/", "", "middle", "https://www.fazerfoodco.fi/modules/json/json/Index?costNumber=0815&language=fi" ],
6
+  #[ "(TaY) Tampereen normaalikoulun ravintola", "http://www.amica.fi/tampereennormaalikoulu", "", "middle", "https://www.amica.fi/modules/json/json/Index?costNumber=0811&language=fi" ],
7 7
   [ "(TTY) Ravintola Reaktori", "https://www.fazerfoodco.fi/ravintolat/Ravintolat-kaupungeittain/tampere/reaktori/", "", "middle", "https://www.fazerfoodco.fi/modules/json/json/Index?costNumber=0812&language=fi" ]
8 8
 ]
9 9
 
@@ -20,38 +20,46 @@ def get_restaurants(use_old, week):
20 20
     for count, info in enumerate(restaurant_info):
21 21
         title = info[0]
22 22
         url = info[4]
23
-        temp_fname = "amica_{count}.temp.js".format(count = count)
24
-        data = pnalib.get_json_file(url, temp_fname, use_old)
25
-        if not data:
26
-            continue
27
-
28
-        week_foods = {}
29
-        lunch_menus = data["MenusForDays"]
30
-        if not lunch_menus:
31
-            continue
32
-        for lunch_menu in lunch_menus:
33
-            date = lunch_menu["Date"].split("T")[0]
34
-            try:
35
-                week_day = date_strings.index(date)
36
-            except:
37
-                continue
38
-            current_day_foods = []
39
-            set_menus = lunch_menu["SetMenus"]
40
-            html = lunch_menu.get("Html", "")
41
-            if len(html):
42
-                    current_day_foods.append(handle_html(html))
43
-            else:
44
-                for set_menu in set_menus:
45
-                    meals = set_menu["Components"]
46
-                    food = []
47
-                    for meal in meals:
48
-                        food.append(format_meal_allergies(meal))
49
-                    current_day_foods.append("\n".join(food))
50
-            week_foods[week_day] = current_day_foods
51
-
23
+        week_foods = handle_one(use_old, date_strings, count, url)
52 24
         restaurants.append([title, "", week, week_foods, info])
53 25
     return restaurants
54 26
 
27
+def handle_one(use_old, date_strings, count, url):
28
+    temp_fname = "amica_{count}.temp.json".format(count = count)
29
+
30
+    week_foods = {}
31
+    data = pnalib.get_json_file(url, temp_fname, use_old)
32
+    if not data:
33
+        print("Fazer no data")
34
+        return week_foods
35
+
36
+    lunch_menus = data["MenusForDays"]
37
+    if not lunch_menus:
38
+        print("Fazer no MenusForDays")
39
+        return week_foods
40
+
41
+    for lunch_menu in lunch_menus:
42
+        date = lunch_menu["Date"].split("T")[0]
43
+        try:
44
+            week_day = date_strings.index(date)
45
+        except:
46
+            print("Fazer no date dates=({}), key=({})".format(date_strings, date))
47
+            continue
48
+        current_day_foods = []
49
+        set_menus = lunch_menu["SetMenus"]
50
+        html = lunch_menu.get("Html", "")
51
+        if len(html):
52
+                current_day_foods.append(handle_html(html))
53
+        else:
54
+            for set_menu in set_menus:
55
+                meals = set_menu["Components"]
56
+                food = []
57
+                for meal in meals:
58
+                    food.append(format_meal_allergies(meal))
59
+                current_day_foods.append("\n".join(food))
60
+        week_foods[week_day] = current_day_foods
61
+    return week_foods
62
+
55 63
 # Onko enää tarpeellinen?
56 64
 def handle_html(html):
57 65
     menus = html.split("<p>")