Remove dict comprehension
import json
from urllib.request import urlopen
+
def data_cve_circl(name, version=None):
"""
Outputs cve-ids, if any, related to a package.
@@ -42,6 +43,7 @@ def data_cve_circl(name, version=None):
return data
+
def extract_fields(data, fields_names, version=False):
"""
Extracts requested data fields using data generated by
@@ -49,15 +51,16 @@ def extract_fields(data, fields_names, version=False):
"""
extracted_data = []
- if version:
- data = data
- else:
+ if not version:
data = data['data']
- for item in data:
results = {}
+ for item in data:
for name in fields_names :
+ try:
results[name] = item[name]
+ except KeyError:
+ results[name] = None
extracted_data.append(results)
