forked from RuncibleSpoon/SCAScripts
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathapi_data_parser.py
More file actions
40 lines (32 loc) · 1.4 KB
/
Copy pathapi_data_parser.py
File metadata and controls
40 lines (32 loc) · 1.4 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
import json
import csv
import sys
def process_dependencies(input_filename, output_filename):
# Load the JSON data
with open(input_filename, 'r') as file:
data = json.load(file)
# Open CSV file for writing
with open(output_filename, 'w', newline='') as csvfile:
writer = csv.writer(csvfile)
# Navigate to the list of objects
objects = data.get('list', {}).get('objects', [])
for obj in objects:
dependencies = obj.get('spec', {}).get('resolved_dependencies', {}).get('dependencies', [])
for dep in dependencies:
name_field = dep.get('name', '')
if name_field.startswith('c://'):
name_field = name_field[len('c://'):] # Remove 'c://'
if '@' in name_field:
name, version = name_field.split('@', 1)
name = name.lower()
name = name.rstrip('/') # Strip any trailing '/' characters
version = version.lower()
writer.writerow([name, version])
print(f"Processed data written to '{output_filename}'.")
if __name__ == "__main__":
if len(sys.argv) != 3:
print("Usage: api_data_parser.py <input_json_file> <output_csv_file>")
sys.exit(1)
input_filename = sys.argv[1]
output_filename = sys.argv[2]
process_dependencies(input_filename, output_filename)