Coverage for otaku_info/utils/urls.py: 56%

Shortcuts on this page

r m x p   toggle line displays

j k   next/prev highlighted chunk

0   (zero) top of page

1   (one) first highlighted chunk

9 statements  

1"""LICENSE 

2Copyright 2020 Hermann Krumrey <hermann@krumreyh.com> 

3 

4This file is part of otaku-info. 

5 

6otaku-info is free software: you can redistribute it and/or modify 

7it under the terms of the GNU General Public License as published by 

8the Free Software Foundation, either version 3 of the License, or 

9(at your option) any later version. 

10 

11otaku-info is distributed in the hope that it will be useful, 

12but WITHOUT ANY WARRANTY; without even the implied warranty of 

13MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 

14GNU General Public License for more details. 

15 

16You should have received a copy of the GNU General Public License 

17along with otaku-info. If not, see <http://www.gnu.org/licenses/>. 

18LICENSE""" 

19 

20from flask import url_for 

21from otaku_info.enums import ListService, MediaType 

22from otaku_info.mappings import list_service_url_formats 

23 

24 

25def generate_service_url( 

26 service: ListService, 

27 media_type: MediaType, 

28 service_id: str 

29) -> str: 

30 """ 

31 :return: The URL to the series for the given service 

32 """ 

33 url_format = list_service_url_formats[service] 

34 url = url_format \ 

35 .replace("@{media_type}", f"{media_type.value}") \ 

36 .replace("@{id}", service_id) 

37 return url 

38 

39 

40def generate_service_icon_url(service: ListService) -> str: 

41 """ 

42 :return: The path to the service's icon file 

43 """ 

44 return url_for( 

45 "static", 

46 filename=f"images/service_logos/{service.value}.png" 

47 )