-
Notifications
You must be signed in to change notification settings - Fork 0
/
MongoConnection.py
49 lines (32 loc) · 1.1 KB
/
MongoConnection.py
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
41
42
43
44
45
46
47
48
49
import re
from pymongo import MongoClient
from index import GetCommand
client = MongoClient()
client = MongoClient('localhost', 27017)
client = MongoClient('mongodb://localhost:27017/')
db = client['Vulns']
#db.CVEs.update({}, {"$set": {"CommitHash001": ""}})
i=0
#coll1 = db.CVEs #selecting the coll1 in myDatabase
#for document in coll1.find():
#print (document)
coll1 = db.CVEs.find({}, {'references':1, 'id': 1, '_id':0})
for document in coll1:
#split= str(document).split(', ')\
Value= list(document.values())[1]
Url= re.findall('https://github\.com(?:/[^/]+)*/commit/[0-9a-f]{40}', Value)
length= len(Url)
if length >1:
for x in Url:
MainUrl= x.replace("'", "").replace("[", "").replace("]", "")
GetCommand(MainUrl, list(document.values())[0])
i=i+1
else:
#print(Url[0].replace("'", "").replace("[", "").replace("]", ""))
#print(list(document.values())[0])
MainUrl2= Url[0].replace("'", "").replace("[", "").replace("]", "")
GetCommand(MainUrl2, list(document.values())[0])
i=i+1
print(i)
#print (Url)
#print(Url)