import pyrebase

config = {
	 "apiKey": "AIzaSyDMbpFGyLizHQ11Su5OnGJ_e4rKHR3mRkY",
	"authDomain": "sal1-5a1a3.firebaseapp.com",
	"databaseURL": "https://sal1-5a1a3.firebaseio.com",
	"projectId": "sal1-5a1a3",
	"storageBucket": "",
	"messagingSenderId": "559686746977"
	}

firebase = pyrebase.initialize_app(config)

import warnings
warnings.filterwarnings('ignore')

db=firebase.database()
user=db.child("SET").get()

def try_to_get(data,remark):
	s="-"
	try: 
		s=data[remark]
	except:
		pass
	return s

cnt=0;
data=user.val()
for i in data:

	
	if len(data[i])>=2:
		zxc=[]
		print("\n")
		print(i)
		
		for time in data[i]['OVAL']:
			
			cveid=try_to_get(data[i]['OVAL'][time],"CVEID")
			
			if cveid!="-":
				
				for k in cveid:
					zxc.append(k)
			

		for time in data[i]['NESSUS']:
			wsx=[]
			
            
			results=data[i]['NESSUS'][time]
             
			
			cveid=try_to_get(results,"CVEID")
			if cveid!='-':
				
				for key,value in cveid.items():
					
					wsx.append(key)
					
			b3 = [val for val in wsx if val in zxc]
			print("INTERSECTION")
			print(b3)
			mean=0
			for wq in b3:
				
				l=cveid[wq]
				print("CVEID="+str(wq))
				print("RISK="+str(l[0]))
				print("SCORE="+str(l[1]))
				mean=mean+l[1]
				print("PORT="+str(l[2]))
				print("SERVICE="+str(l[4])+"\n")
			if len(b3)!=0 and mean!=0:
				print("MEAN="+str(float(mean/len(b3)))+"\n")
			b3 = [val for val in [i.split('-')[2] for i in wsx] if val in [j.split('-')[2] for j in zxc]]
			print("this",b3)
              