| 
				
			 | 
			
			
				@@ -2,9 +2,9 @@ import pnalib 
			 | 
		
	
		
			
			| 
				2
			 | 
			
				2
			 | 
			
			
				 import datetime 
			 | 
		
	
		
			
			| 
				3
			 | 
			
				3
			 | 
			
			
				  
			 | 
		
	
		
			
			| 
				4
			 | 
			
				4
			 | 
			
			
				 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" ] 
			 | 
		
	
		
			
			| 
				
			 | 
			
				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" ], 
			 | 
		
	
		
			
			| 
				
			 | 
			
				7
			 | 
			
			
				+  [ "(TTY) Ravintola Reaktori", "http://www.amica.fi/reaktori", "", "middle", "https://www.amica.fi/modules/json/json/Index?costNumber=0812&language=fi" ] 
			 | 
		
	
		
			
			| 
				8
			 | 
			
				8
			 | 
			
			
				 ] 
			 | 
		
	
		
			
			| 
				9
			 | 
			
				9
			 | 
			
			
				  
			 | 
		
	
		
			
			| 
				10
			 | 
			
				10
			 | 
			
			
				 def get_restaurants(use_old, week): 
			 | 
		
	
	
		
			
			| 
				
			 | 
			
			
				@@ -17,41 +17,45 @@ def get_restaurants(use_old, week): 
			 | 
		
	
		
			
			| 
				17
			 | 
			
				17
			 | 
			
			
				         title = info[0] 
			 | 
		
	
		
			
			| 
				18
			 | 
			
				18
			 | 
			
			
				         url = info[4] 
			 | 
		
	
		
			
			| 
				19
			 | 
			
				19
			 | 
			
			
				         temp_fname = "amica_{count}.temp.js".format(count = count) 
			 | 
		
	
		
			
			| 
				20
			 | 
			
				
			 | 
			
			
				-        url = "{url}&weekDate={week_date}".format(url=url, week_date=week_date) 
			 | 
		
	
		
			
			| 
				21
			 | 
			
				20
			 | 
			
			
				         data = pnalib.get_json_file(url, temp_fname, use_old) 
			 | 
		
	
		
			
			| 
				22
			 | 
			
				21
			 | 
			
			
				         if not data: 
			 | 
		
	
		
			
			| 
				23
			 | 
			
				22
			 | 
			
			
				             continue 
			 | 
		
	
		
			
			| 
				24
			 | 
			
				23
			 | 
			
			
				  
			 | 
		
	
		
			
			| 
				25
			 | 
			
				24
			 | 
			
			
				         week_foods = {} 
			 | 
		
	
		
			
			| 
				26
			 | 
			
				
			 | 
			
			
				-        lunch_menus = data["LunchMenus"] 
			 | 
		
	
		
			
			| 
				
			 | 
			
				25
			 | 
			
			
				+        lunch_menus = data["MenusForDays"] 
			 | 
		
	
		
			
			| 
				27
			 | 
			
				26
			 | 
			
			
				         for week_day, lunch_menu in enumerate(lunch_menus): 
			 | 
		
	
		
			
			| 
				28
			 | 
			
				27
			 | 
			
			
				             current_day_foods = [] 
			 | 
		
	
		
			
			| 
				29
			 | 
			
				28
			 | 
			
			
				             set_menus = lunch_menu["SetMenus"] 
			 | 
		
	
		
			
			| 
				30
			 | 
			
				
			 | 
			
			
				-            html = lunch_menu["Html"] 
			 | 
		
	
		
			
			| 
				
			 | 
			
				29
			 | 
			
			
				+            html = lunch_menu.get("Html", "") 
			 | 
		
	
		
			
			| 
				31
			 | 
			
				30
			 | 
			
			
				             if len(html): 
			 | 
		
	
		
			
			| 
				32
			 | 
			
				
			 | 
			
			
				-                menus = html.split("<p>") 
			 | 
		
	
		
			
			| 
				33
			 | 
			
				
			 | 
			
			
				-                for set_menu in menus: 
			 | 
		
	
		
			
			| 
				34
			 | 
			
				
			 | 
			
			
				-                    meals = set_menu.split("<br />") 
			 | 
		
	
		
			
			| 
				35
			 | 
			
				
			 | 
			
			
				-                    food = [] 
			 | 
		
	
		
			
			| 
				36
			 | 
			
				
			 | 
			
			
				-                    for meal in meals: 
			 | 
		
	
		
			
			| 
				37
			 | 
			
				
			 | 
			
			
				-                        parts = meal.split("(") 
			 | 
		
	
		
			
			| 
				38
			 | 
			
				
			 | 
			
			
				-                        current_food = parts[0] 
			 | 
		
	
		
			
			| 
				39
			 | 
			
				
			 | 
			
			
				-                        diets = [s.strip() for s in parts.split(")")[0].split(",")] 
			 | 
		
	
		
			
			| 
				40
			 | 
			
				
			 | 
			
			
				-                        if diets: 
			 | 
		
	
		
			
			| 
				41
			 | 
			
				
			 | 
			
			
				-                            current_food += " ({allergies})".format(allergies=", ".join(diets)) 
			 | 
		
	
		
			
			| 
				42
			 | 
			
				
			 | 
			
			
				-                        food.append(current_food) 
			 | 
		
	
		
			
			| 
				43
			 | 
			
				
			 | 
			
			
				-                    current_day_foods.append("\n".join(food)) 
			 | 
		
	
		
			
			| 
				
			 | 
			
				31
			 | 
			
			
				+                    current_day_foods.append(handle_html(html)) 
			 | 
		
	
		
			
			| 
				44
			 | 
			
				32
			 | 
			
			
				             else: 
			 | 
		
	
		
			
			| 
				45
			 | 
			
				33
			 | 
			
			
				                 for set_menu in set_menus: 
			 | 
		
	
		
			
			| 
				46
			 | 
			
				
			 | 
			
			
				-                    meals = set_menu["Meals"] 
			 | 
		
	
		
			
			| 
				
			 | 
			
				34
			 | 
			
			
				+                    meals = set_menu["Components"] 
			 | 
		
	
		
			
			| 
				47
			 | 
			
				35
			 | 
			
			
				                     food = [] 
			 | 
		
	
		
			
			| 
				48
			 | 
			
				36
			 | 
			
			
				                     for meal in meals: 
			 | 
		
	
		
			
			| 
				49
			 | 
			
				
			 | 
			
			
				-                        current_food = meal["Name"] 
			 | 
		
	
		
			
			| 
				50
			 | 
			
				
			 | 
			
			
				-                        if "Diets" in meal: 
			 | 
		
	
		
			
			| 
				51
			 | 
			
				
			 | 
			
			
				-                            current_food += " ({allergies})".format(allergies=", ".join(meal["Diets"])) 
			 | 
		
	
		
			
			| 
				52
			 | 
			
				
			 | 
			
			
				-                        food.append(current_food) 
			 | 
		
	
		
			
			| 
				
			 | 
			
				37
			 | 
			
			
				+                        food.append(format_meal_allergies(meal)) 
			 | 
		
	
		
			
			| 
				53
			 | 
			
				38
			 | 
			
			
				                     current_day_foods.append("\n".join(food)) 
			 | 
		
	
		
			
			| 
				54
			 | 
			
				39
			 | 
			
			
				             week_foods[week_day] = current_day_foods 
			 | 
		
	
		
			
			| 
				55
			 | 
			
				40
			 | 
			
			
				  
			 | 
		
	
		
			
			| 
				56
			 | 
			
				41
			 | 
			
			
				         restaurants.append([title, "", week, week_foods, info]) 
			 | 
		
	
		
			
			| 
				57
			 | 
			
				42
			 | 
			
			
				     return restaurants 
			 | 
		
	
		
			
			| 
				
			 | 
			
				43
			 | 
			
			
				+ 
			 | 
		
	
		
			
			| 
				
			 | 
			
				44
			 | 
			
			
				+# Onko enää tarpeellinen? 
			 | 
		
	
		
			
			| 
				
			 | 
			
				45
			 | 
			
			
				+def handle_html(html): 
			 | 
		
	
		
			
			| 
				
			 | 
			
				46
			 | 
			
			
				+    menus = html.split("<p>") 
			 | 
		
	
		
			
			| 
				
			 | 
			
				47
			 | 
			
			
				+    for set_menu in menus: 
			 | 
		
	
		
			
			| 
				
			 | 
			
				48
			 | 
			
			
				+        meals = set_menu.split("<br />") 
			 | 
		
	
		
			
			| 
				
			 | 
			
				49
			 | 
			
			
				+        food = [] 
			 | 
		
	
		
			
			| 
				
			 | 
			
				50
			 | 
			
			
				+        for meal in meals: 
			 | 
		
	
		
			
			| 
				
			 | 
			
				51
			 | 
			
			
				+            food.append(format_meal_allergies(meal)) 
			 | 
		
	
		
			
			| 
				
			 | 
			
				52
			 | 
			
			
				+    return "\n".join(food) 
			 | 
		
	
		
			
			| 
				
			 | 
			
				53
			 | 
			
			
				+ 
			 | 
		
	
		
			
			| 
				
			 | 
			
				54
			 | 
			
			
				+def format_meal_allergies(meal): 
			 | 
		
	
		
			
			| 
				
			 | 
			
				55
			 | 
			
			
				+    parts = meal.split("(") 
			 | 
		
	
		
			
			| 
				
			 | 
			
				56
			 | 
			
			
				+    current_food = parts[0] 
			 | 
		
	
		
			
			| 
				
			 | 
			
				57
			 | 
			
			
				+    diets = [s.strip() for s in parts[1].split(")")[0].split(",")] 
			 | 
		
	
		
			
			| 
				
			 | 
			
				58
			 | 
			
			
				+    if diets: 
			 | 
		
	
		
			
			| 
				
			 | 
			
				59
			 | 
			
			
				+        current_food += " ({allergies})".format(allergies=", ".join(diets)) 
			 | 
		
	
		
			
			| 
				
			 | 
			
				60
			 | 
			
			
				+    return current_food 
			 | 
		
	
		
			
			| 
				
			 | 
			
				61
			 | 
			
			
				+ 
			 |