remove "namespace classes" AllTime and Today
This commit is contained in:
		
							parent
							
								
									af00dafb6c
								
							
						
					
					
						commit
						29f02d2545
					
				
					 2 changed files with 86 additions and 90 deletions
				
			
		|  | @ -11,8 +11,6 @@ from .sequence_helpers import Random, set_len, shuffle | |||
| from .webdav import WebDAV | ||||
| 
 | ||||
| 
 | ||||
| class AllTime: | ||||
|     @staticmethod | ||||
| async def shuffle_solution( | ||||
|     cfg: Config = Depends(Config.get_config), | ||||
| ) -> str: | ||||
|  | @ -22,7 +20,7 @@ class AllTime: | |||
| 
 | ||||
|     return "".join(await shuffle(cfg.puzzle.solution)) | ||||
| 
 | ||||
|     @staticmethod | ||||
| 
 | ||||
| async def shuffle_images_auto( | ||||
|     images: list[str] = Depends(list_images_auto), | ||||
| ) -> list[str]: | ||||
|  | @ -34,11 +32,9 @@ class AllTime: | |||
|     return await shuffle(ls) | ||||
| 
 | ||||
| 
 | ||||
| class Today: | ||||
|     @staticmethod | ||||
| async def get_part( | ||||
|     day: int, | ||||
|         shuffled_solution: str = Depends(AllTime.shuffle_solution), | ||||
|     shuffled_solution: str = Depends(shuffle_solution), | ||||
| ) -> str: | ||||
|     """ | ||||
|     Heute angezeigter Teil der Lösung | ||||
|  | @ -46,7 +42,7 @@ class Today: | |||
| 
 | ||||
|     return shuffled_solution[day] | ||||
| 
 | ||||
|     @staticmethod | ||||
| 
 | ||||
| async def get_random( | ||||
|     day: int, | ||||
| ) -> Random: | ||||
|  | @ -56,10 +52,10 @@ class Today: | |||
| 
 | ||||
|     return await Random.get(day) | ||||
| 
 | ||||
|     @staticmethod | ||||
| 
 | ||||
| async def gen_auto_image( | ||||
|     day: int, | ||||
|         images: list[str] = Depends(AllTime.shuffle_images_auto), | ||||
|     auto_images: list[str] = Depends(shuffle_images_auto), | ||||
|     cfg: Config = Depends(Config.get_config), | ||||
|     rnd: Random = Depends(get_random), | ||||
|     part: str = Depends(get_part), | ||||
|  | @ -69,7 +65,7 @@ class Today: | |||
|     """ | ||||
| 
 | ||||
|     # Datei existiert garantiert! | ||||
|         img = await load_image(images[day]) | ||||
|     img = await load_image(auto_images[day]) | ||||
|     image = await AdventImage.from_img(img) | ||||
| 
 | ||||
|     font = ImageFont.truetype( | ||||
|  | @ -87,10 +83,10 @@ class Today: | |||
| 
 | ||||
|     return image.img | ||||
| 
 | ||||
|     @staticmethod | ||||
| 
 | ||||
| async def get_image( | ||||
|     day: int, | ||||
|         images: list[str] = Depends(AllTime.shuffle_images_auto), | ||||
|     auto_images: list[str] = Depends(shuffle_images_auto), | ||||
|     cfg: Config = Depends(Config.get_config), | ||||
|     rnd: Random = Depends(get_random), | ||||
|     part: str = Depends(get_part), | ||||
|  | @ -105,6 +101,6 @@ class Today: | |||
| 
 | ||||
|     except RuntimeError: | ||||
|         # Erstelle automatisch generiertes Bild | ||||
|             return await Today.gen_auto_image( | ||||
|                 day=day, images=images, cfg=cfg, rnd=rnd, part=part | ||||
|         return await gen_auto_image( | ||||
|             day=day, auto_images=auto_images, cfg=cfg, rnd=rnd, part=part | ||||
|         ) | ||||
|  |  | |||
|  | @ -5,7 +5,7 @@ from fastapi.responses import StreamingResponse | |||
| from PIL import Image | ||||
| 
 | ||||
| from ..core.config import Config | ||||
| from ..core.depends import AllTime, Today | ||||
| from ..core.depends import get_image, get_part, shuffle_solution | ||||
| from ..core.image_helpers import api_return_image | ||||
| from .user import user_is_admin | ||||
| 
 | ||||
|  | @ -17,15 +17,10 @@ async def startup() -> None: | |||
|     cfg = await Config.get_config() | ||||
|     print(cfg.puzzle.solution) | ||||
| 
 | ||||
|     shuffled_solution = await AllTime.shuffle_solution(cfg) | ||||
|     shuffled_solution = await shuffle_solution(cfg) | ||||
|     print(shuffled_solution) | ||||
| 
 | ||||
| 
 | ||||
| @router.get("/part/{day}") | ||||
| async def get_part(part: str = Depends(Today.get_part)) -> str: | ||||
|     return part | ||||
| 
 | ||||
| 
 | ||||
| @router.get("/date") | ||||
| async def get_date() -> str: | ||||
|     return date.today().isoformat() | ||||
|  | @ -50,12 +45,17 @@ async def user_can_view( | |||
|     return day < await get_visible_days() | ||||
| 
 | ||||
| 
 | ||||
| @router.get("/part/{day}") | ||||
| async def get_part_for_day(part: str = Depends(get_part)) -> str: | ||||
|     return part | ||||
| 
 | ||||
| 
 | ||||
| @router.get( | ||||
|     "/image/{day}", | ||||
|     response_class=StreamingResponse, | ||||
| ) | ||||
| async def get_image_for_day( | ||||
|     image: Image.Image = Depends(Today.get_image), | ||||
|     image: Image.Image = Depends(get_image), | ||||
|     can_view: bool = Depends(user_can_view), | ||||
|     is_admin: bool = Depends(user_is_admin), | ||||
| ) -> StreamingResponse: | ||||
|  |  | |||
		Loading…
	
		Reference in a new issue