I have 2 functions in one script that are called from another file. I want to pass the variable 'active_vuln_type' and its contents to the second function 'Download'.
The file with the scripts is:- projectfolder/vuln_backend/download.py
import requests
import eventlet
import os
import sqlite3
#Get the active vulnerability sets
def GetActiveVulnSets() :
active_vuln_type = con = sqlite3.connect('data/vuln_sets.db')
cur = con.cursor()
cur.execute('''SELECT vulntype FROM vuln_sets WHERE active=1''')
active_vuln_type = cur.fetchall()
print(active_vuln_type)
return active_vuln_type
#Download the relevant collections
def Download(active_vuln_type) :
response = requests.get('https://vulners.com/api/v3/archive/collection/?type=' + active_vuln_type)
with open('vuln_files/' + active_vuln_type + '.zip' , 'wb') as f:
f.write(response.content)
f.close()
return active_vuln_type + " - " + str(os.path.getsize('vuln_files/' + active_vuln_type + '.zip'))
The main file in / projectfolder/vuln_backend.py:-
from vuln_backend import vuln_sets, download, test
test.update_vuln_sets()
#vuln_sets.update_vuln_sets()
download.GetActiveVulnSets()
download.Download()
I am adapting the following script:-
import requests
import json
import eventlet
import os
response = requests.get('https://vulners.com/api/v3/search/stats/')
objects = json.loads(response.text)
object_names = set()
for name in objects['data']['type_results']:
object_names.add(name)
def download(name):
response = requests.get('https://vulners.com/api/v3/archive/collection/?type=' + name)
with open('vulners_collections/' + name + '.zip' , 'wb') as f:
f.write(response.content)
f.close()
return name + " - " + str(os.path.getsize('vulners_collections/' + name + '.zip'))
pool = eventlet.GreenPool()
for name in pool.imap(download, object_names):
print(name)
So far, I have got the values from ['data']['type_results'] into a SQLite DB, and some of these are marked with a '1' in the 'active' column. The first function then returns only the ones marked as active.
It is the download part I am having issues getting to work correctly.