Coverage for index.py: 94%

42 statements  

« prev     ^ index     » next       coverage.py v7.10.6, created at 2025-11-25 17:29 +0000

1import json 1a

2from flask import abort, Flask, Blueprint, jsonify, request 1a

3from flask_cors import cross_origin 1a

4from src.data_manager import DataManager 1a

5from src.const import PREFECTURES 1a

6from src.swagger_settings import set_config 1a

7 

8 

9data_manager = DataManager() 1a

10 

11app = Flask(__name__) 1a

12 

13apiv1 = Blueprint('apiv1', __name__, url_prefix='/api/v1') 1a

14 

15 

16@app.route('/') 1a

17def index(): 1a

18 return jsonify({'message': 'Web API to get COVID-19(coronavirus) information of each prefecture in Japan.'}) 2Bb

19 

20 

21@apiv1.route('/total') 1a

22@cross_origin(apiv1) 1a

23def total(): 1a

24 """ Get the total number of infected people and deaths in Japan 

25 --- 

26 parameters: 

27 - in: query 

28 name: history 

29 type: boolean 

30 - in: query 

31 name: predict 

32 type: boolean 

33 responses: 

34 200: 

35 description: Success to get total 

36 """ 

37 if 'history' in request.args and request.args['history'] == 'true': 2obybpbqbrbsbzbtbubAbvbwbxb

38 return data_manager.history_total_json, 200, {'Content-Type': 'application/json; charset=utf-8'} 2ybzbAb

39 elif 'predict' in request.args and request.args['predict'] == 'true': 2obpbqbrbsbtbubvbwbxb

40 return data_manager.prediction_total_json, 200, {'Content-Type': 'application/json; charset=utf-8'} 2pbub

41 return data_manager.today_total_json, 200, {'Content-Type': 'application/json; charset=utf-8'} 2obqbrbsbtbvbwbxb

42 

43 

44@apiv1.route('/prefectures') 1a

45@cross_origin(apiv1) 1a

46def prefectures(): 1a

47 """Get the COVID-19(coronavirus) information of each prefecture in Japan 

48 --- 

49 responses: 

50 200: 

51 description: Success to get the information of each prefecture 

52 """ 

53 return data_manager.prefectures_json, 200, {'Content-Type': 'application/json; charset=utf-8'} 2CbDb

54 

55 

56@apiv1.route('/positives') 1a

57@cross_origin(apiv1) 1a

58def positives(): 1a

59 """ Get the total number of infected people and deaths in Japan 

60 --- 

61 parameters: 

62 - in: query 

63 name: prefecture 

64 description: Specify the Japanese name. example - 千葉県 

65 type: string 

66 required: true 

67 responses: 

68 200: 

69 description: Success to get positives 

70 400: 

71 description: The prefecture parameter is required 

72 404: 

73 description: Does not find the prefecture 

74 """ 

75 if 'prefecture' in request.args: 2b c d e f g h i j k l m n o p q r s t u v w x y z A B C D E F G H I J K L M N O P Q R S T U V W X Y Z 0 1 2 3 4 5 6 7 8 9 ! # $ % ' ( ) * + , - . / : ; = ? @ [ ] ^ _ ` { | } ~ abbbcbdbebfbgbhbibjbkblbmbnb

76 prefecture = request.args['prefecture'] 2b c d e f g h i k l m n o p q r s t u v w x y z A B C D E F G H I J K L M N O P Q R S T U V W X Y Z 0 1 2 3 4 5 6 7 8 9 ! # $ % ' ( ) * + , - . / : ; = ? @ [ ] ^ _ ` { | } ~ abbbcbdbebfbgbhbibjbkblbmbnb

77 if prefecture in PREFECTURES: 77 ↛ 78line 77 didn't jump to line 78 because the condition on line 77 was never true2b c d e f g h i k l m n o p q r s t u v w x y z A B C D E F G H I J K L M N O P Q R S T U V W X Y Z 0 1 2 3 4 5 6 7 8 9 ! # $ % ' ( ) * + , - . / : ; = ? @ [ ] ^ _ ` { | } ~ abbbcbdbebfbgbhbibjbkblbmbnb

78 response_json = data_manager.get_positive_detail_json(prefecture) 

79 return response_json, 200, {'Content-Type': 'application/json; charset=utf-8'} 

80 else: 

81 return abort(404, {'prefecture': f'Does not find {prefecture}'}) 2b c d e f g h i k l m n o p q r s t u v w x y z A B C D E F G H I J K L M N O P Q R S T U V W X Y Z 0 1 2 3 4 5 6 7 8 9 ! # $ % ' ( ) * + , - . / : ; = ? @ [ ] ^ _ ` { | } ~ abbbcbdbebfbgbhbibjbkblbmbnb

82 message = 'The prefecture parameter is required.\ 1j

83 ex: https://covid19-japan-web-api.now.sh/api/v1/positives?prefecture=東京都' 

84 response_json = json.dumps({'message': message}, ensure_ascii=False) 1j

85 return response_json, 400, {'Content-Type': 'application/json; charset=utf-8'} 1j

86 

87 

88@apiv1.route('/statistics') 1a

89@cross_origin(apiv1) 1a

90def statistics(): 1a

91 """Get the COVID-19(coronavirus) statistics of each prefecture in Japan 

92 --- 

93 responses: 

94 200: 

95 description: Success to get the statistics of each prefecture 

96 """ 

97 return data_manager.statistics_json, 200, {'Content-Type': 'application/json; charset=utf-8'} 2EbFb

98 

99 

100app.register_blueprint(apiv1) 1a

101set_config(app) 1a