import sys import re def main(): file_path = sys.argv[1] after_list = [] with open(file_path) as f: before_list = f.readlines() for before in before_list: items = get_value(before) id = get_item(items, 'id') severity = get_item(items, 'severity') after_list.append('{0},{1}'.format(id, severity)) after_list = list(set(after_list)) after_list.sort() with open(file_path, mode='w') as f: f.write('\n'.join(after_list)) def get_value(line, start='\[', end='\]'): "get_severity.py" 44L, 975C 1,1 Top import sys import re def main(): file_path = sys.argv[1] after_list = [] with open(file_path) as f: before_list = f.readlines() for before in before_list: items = get_value(before) id = get_item(items, 'id') severity = get_item(items, 'severity') after_list.append('{0},{1}'.format(id, severity)) after_list = list(set(after_list)) after_list.sort() with open(file_path, mode='w') as f: f.write('\n'.join(after_list)) def get_value(line, start='\[', end='\]'): "get_severity.py" 44L, 975C 1,1 Top import sys import re def main(): file_path = sys.argv[1] after_list = [] with open(file_path) as f: before_list = f.readlines() for before in before_list: items = get_value(before) id = get_item(items, 'id') severity = get_item(items, 'severity') after_list.append('{0},{1}'.format(id, severity)) after_list = list(set(after_list)) after_list.sort() with open(file_path, mode='w') as f: f.write('\n'.join(after_list)) def get_value(line, start='\[', end='\]'): "get_severity.py" 44L, 975C 1,1 Top import sys import re def main(): file_path = sys.argv[1] after_list = [] with open(file_path) as f: before_list = f.readlines() for before in before_list: items = get_value(before) id = get_item(items, 'id') severity = get_item(items, 'severity') after_list.append('{0},{1}'.format(id, severity)) after_list = list(set(after_list)) after_list.sort() with open(file_path, mode='w') as f: f.write('\n'.join(after_list)) after_list = list(set(after_list)) after_list.sort() with open(file_path, mode='w') as f: f.write('\n'.join(after_list)) def get_value(line, start='\[', end='\]'): p = r'{0}(.+?){1}'.format(start, end) items = re.findall(p, line) return items def get_item(target_list, param_name): for target in target_list: ret = target.split(' ') if ret[0] == param_name: return ret[1].replace( '"', '' ) return '?' # util def stdout(str): print(str) ## main if __name__ == "__main__": try: main() except Exception as e: stdout(e) 44,9 Bot import sys import re def main(): file_path = sys.argv[1] after_list = [] with open(file_path) as f: before_list = f.readlines() for before in before_list: items = get_value(before) id = get_item(items, 'id') severity = get_item(items, 'severity') after_list.append('{0},{1}'.format(id, severity)) after_list = list(set(after_list)) def get_value(line, start='\[', end='\]'): p = r'{0}(.+?){1}'.format(start, end) items = re.findall(p, line) return items def get_item(target_list, param_name): for target in target_list: ret = target.split(' ') if ret[0] == param_name: return ret[1].replace( '"', '' ) return '?' # util def stdout(str): print(str) ## main if __name__ == "__main__": try: main() except Exception as e: stdout(e)
コメント