5
5
import argparse
6
6
import logging
7
7
import time
8
+ import uuid
8
9
from typing import Any , Dict , List , Optional , Tuple , Union
9
10
10
11
import requests
11
- import uuid
12
+
12
13
import annofabapi
13
14
import annofabapi .utils
14
-
15
- from example_utils import read_lines , ExamplesWrapper
15
+ from example_utils import ExamplesWrapper , read_lines
16
16
17
17
logging_formatter = '%(levelname)s : %(asctime)s : %(name)s : %(funcName)s : %(message)s'
18
18
logging .basicConfig (format = logging_formatter )
21
21
logger = logging .getLogger (__name__ )
22
22
logger .setLevel (level = logging .DEBUG )
23
23
24
- def add_inspection_comment (project_id : str , task : Dict [str , Any ], inspection_comment : str , commenter_account_id : str ):
24
+
25
+ def add_inspection_comment (project_id : str , task : Dict [str , Any ],
26
+ inspection_comment : str , commenter_account_id : str ):
25
27
"""
26
28
先頭画像の左上に検査コメントを付与する
27
29
Args:
@@ -53,14 +55,17 @@ def add_inspection_comment(project_id: str, task: Dict[str, Any], inspection_com
53
55
"created_datetime" : annofabapi .utils .str_now ()
54
56
},
55
57
"_type" : "Put" ,
56
-
57
58
}]
58
59
59
- return service .api .batch_update_inspections (project_id , task ["task_id" ], first_input_data_id , request_body = req_inspection )[0 ]
60
-
60
+ return service .api .batch_update_inspections (project_id ,
61
+ task ["task_id" ],
62
+ first_input_data_id ,
63
+ request_body = req_inspection )[0 ]
61
64
62
65
63
- def reject_tasks_with_adding_comment (project_id : str , task_id_list : List [str ], inspection_comment : str , commenter_user_id : str ):
66
+ def reject_tasks_with_adding_comment (project_id : str , task_id_list : List [str ],
67
+ inspection_comment : str ,
68
+ commenter_user_id : str ):
64
69
"""
65
70
検査コメントを付与して、タスクを差し戻す
66
71
Args:
@@ -70,21 +75,25 @@ def reject_tasks_with_adding_comment(project_id: str, task_id_list: List[str], i
70
75
commenter_user_id: 検査コメントを付与して、タスクを差し戻すユーザのuser_id
71
76
"""
72
77
73
- commenter_account_id = examples_wrapper .get_account_id_from_user_id (project_id , commenter_user_id )
78
+ commenter_account_id = examples_wrapper .get_account_id_from_user_id (
79
+ project_id , commenter_user_id )
74
80
75
81
for task_id in task_id_list :
76
82
task , _ = service .api .get_task (project_id , task_id )
77
83
logger .debug (f"task_id = { task_id } , { task ['status' ]} , { task ['phase' ]} " )
78
84
if task ["phase" ] == "annotation" :
79
- logger .warning (f"task_id = { task_id } はannofation phaseのため、差し戻しできません。" )
85
+ logger .warning (
86
+ f"task_id = { task_id } はannofation phaseのため、差し戻しできません。" )
80
87
continue
81
88
82
89
try :
83
90
# 担当者を変更して、作業中にする
84
- examples_wrapper .change_operator_of_task (project_id , task_id , commenter_account_id )
91
+ examples_wrapper .change_operator_of_task (project_id , task_id ,
92
+ commenter_account_id )
85
93
logger .debug (f"task_id = { task_id } , { commenter_user_id } に担当者変更 完了" )
86
94
87
- examples_wrapper .change_to_working_phase (project_id , task_id , commenter_account_id )
95
+ examples_wrapper .change_to_working_phase (project_id , task_id ,
96
+ commenter_account_id )
88
97
logger .debug (f"task_id = { task_id } , working statusに変更 完了" )
89
98
except requests .exceptions .HTTPError as e :
90
99
logger .error (e )
@@ -95,7 +104,8 @@ def reject_tasks_with_adding_comment(project_id: str, task_id_list: List[str], i
95
104
time .sleep (3 )
96
105
try :
97
106
# 検査コメントを付与する
98
- add_inspection_comment (project_id , task , inspection_comment , commenter_account_id )
107
+ add_inspection_comment (project_id , task , inspection_comment ,
108
+ commenter_account_id )
99
109
logger .debug (f"task_id = { task_id } , 検査コメントの付与 完了" )
100
110
except requests .exceptions .HTTPError as e :
101
111
logger .error (e )
@@ -104,7 +114,8 @@ def reject_tasks_with_adding_comment(project_id: str, task_id_list: List[str], i
104
114
105
115
try :
106
116
# タスクを差し戻す
107
- rejected_task = examples_wrapper .reject_task (project_id , task_id , commenter_account_id )
117
+ rejected_task = examples_wrapper .reject_task (
118
+ project_id , task_id , commenter_account_id )
108
119
109
120
except requests .exceptions .HTTPError as e :
110
121
logger .error (e )
@@ -115,17 +126,18 @@ def reject_tasks_with_adding_comment(project_id: str, task_id_list: List[str], i
115
126
return
116
127
117
128
118
-
119
-
120
129
def main (args ):
121
130
task_id_list = read_lines (args .task_id_file )
122
131
user_id = service .api .login_user_id
123
- reject_tasks_with_adding_comment (args .project_id , task_id_list , args .comment , user_id )
132
+ reject_tasks_with_adding_comment (args .project_id , task_id_list ,
133
+ args .comment , user_id )
124
134
125
135
126
136
if __name__ == "__main__" :
127
137
parser = argparse .ArgumentParser (
128
- description = "検査コメントを付与してタスクを差し戻します。検査コメントは先頭の画像の左上(0,0)に付与します。AnnoFab認証情報は`.netrc`に記載すること" )
138
+ description =
139
+ "検査コメントを付与してタスクを差し戻します。検査コメントは先頭の画像の左上(0,0)に付与します。AnnoFab認証情報は`.netrc`に記載すること"
140
+ )
129
141
parser .add_argument ('--project_id' ,
130
142
metavar = 'project_id' ,
131
143
type = str ,
@@ -137,8 +149,7 @@ def main(args):
137
149
metavar = 'file' ,
138
150
type = str ,
139
151
required = True ,
140
- help =
141
- 'task_idの一覧が記載されたファイル。task_idは改行(LF or CRLF)で区切る。' )
152
+ help = 'task_idの一覧が記載されたファイル。task_idは改行(LF or CRLF)で区切る。' )
142
153
143
154
parser .add_argument ('--comment' ,
144
155
metavar = 'comment' ,
0 commit comments