Skip to content

Commit 7cbf4a5

Browse files
committed
Change data return format #6 #7
Signed-off-by: Kartik Sibal <kartiksibal@gmail.com>
1 parent e84b43c commit 7cbf4a5

3 files changed

Lines changed: 27 additions & 8 deletions

File tree

scraper/debian.py

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,12 @@ def extract_cves_from_tracker(html):
7474
elif tag.find_all('span', {'class': 'red'}) and tag.text == 'high**' or tag.text == 'high':
7575
vulnerability_status.append(tag.text)
7676

77-
return cve_id, package_name, vulnerability_status
77+
return([{'cve_id': cve_id,
78+
'package_name': name,
79+
'vulnerability_status': status}
80+
for cve_id, name, status in zip(cve_id,
81+
package_name,
82+
vulnerability_status)])
7883

7984

8085
def scrape_cves():

scraper/ubuntu.py

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,10 +33,18 @@
3333
def extract_cves(html):
3434
soup = bs4.BeautifulSoup(html, 'lxml')
3535

36+
count = 0
37+
3638
cve_id = []
3739
package_name = []
3840
vulnerability_status = []
3941

42+
fields = [cve_id, vulnerability_status, package_name]
43+
44+
fieldss = ['cve_id', 'vulnerability_status', 'package_name']
45+
46+
cve = {}
47+
4048
for tag in soup.find_all('tr'):
4149
if re.match('<\w+\s\w+="(\w+)">', str(tag)):
4250
status = re.findall('<\w+\s\w+="(\w+)">', str(tag))
@@ -52,7 +60,12 @@ def extract_cves(html):
5260
pkg = re.findall('pkg/(.+)\.html', href)
5361
package_name.append(pkg[0])
5462

55-
return cve_id, vulnerability_status, package_name
63+
return([{'cve_id': cve_id,
64+
'package_name': name,
65+
'vulnerability_status': status}
66+
for cve_id, name, status in zip(cve_id,
67+
package_name,
68+
vulnerability_status)])
5669

5770

5871
def scrape_cves():

tests/test_scrapers.py

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -46,10 +46,11 @@ def test_ubuntu_extract_cves():
4646
"""
4747

4848
expected = (
49-
['CVE-2002-2439'],
50-
['High'],
51-
['gcc-4.4'],
49+
[{'cve_id': 'CVE-2002-2439',
50+
'package_name': 'gcc-4.4',
51+
'vulnerability_status': 'High'}]
5252
)
53+
5354
assert expected == ubuntu.extract_cves(test_input)
5455

5556

@@ -117,9 +118,9 @@ def test_debian_extract_cves_from_tracker():
117118
"""
118119

119120
expected = (
120-
['CVE-2016-5416'],
121-
['389-ds-base'],
122-
['not yet assigned'],
121+
[{'cve_id': 'CVE-2016-5416',
122+
'package_name': '389-ds-base',
123+
'vulnerability_status': 'not yet assigned'}]
123124
)
124125

125126
assert expected == debian.extract_cves_from_tracker(test_input)

0 commit comments

Comments
 (0)