'Add a new sqllite3 column from list in python

HI i have a list as follow:-

{'id': '568695a6e', 'has_agent': False, 'last_seen': '2022-03-22T12:55:20.822Z',
 'last_scan_target': '1.1.1.1',
 'sources': \[{'name': 'NESSUS_SCAN', 'first_seen': '2021-10-24T19:34:51.328Z', 'last_seen': '2022-03-22T12:55:20.822Z'}\],
 'acr_score': x,
 'acr_drivers': \[{'driver_name': 'device_type', 'driver_value': \['general_purpose'\]},
 {'driver_name': 'device_capability', 'driver_value': \[\]},
 {'driver_name': 'internet_exposure',
 'driver_value': \['internal'\]}\], 'exposure_score': 627,
 'scan_frequency': \[{'interval': 90, 'frequency': 2.142857074737549, 'licensed': False},
 {'interval': 30, 'frequency': 1.4285714626312256, 'licensed': False},
 {'interval': 60, 'frequency': 2.6086957454681396, 'licensed': False}\],
 'ipv4': \['172.24.23.98'\], 'ipv6': \[\], 'fqdn': \['test'\],
 'mac_address': \['xxxxx'\], 'netbios_name': \['xxxxx'\], 
'operating_system': \['Microsoft Windows 10 Pro'\], 'hostname': \['xxxx'\],
 'agent_name': \[\], 'aws_ec2_name': \[\],
 'security_protection_level': 1, 'security_protections': \[{'id': 'xxxx',
 'cpe': 'cpe:2.3:a:microsoft:windows_defender:4.18.1909.6:-:-:-:-:-:-:-',
 'version': '4.18.1909.6', 'vendor_name': 'Microsoft', 'product_name': 'Windows Defender',
 'form_factor': 'EPP_EDR', 'disposition': 'SYSTEM_DEFINED', 'updated_at': 1647890500379}\],
 'exposure_confidence_value': 1}

and i need a way to create a column in sqllite3 into "Tenable" table by the list Keys mentioned above. any suggestion???

the sqllite tenable table as follow:-

CREATE TABLE "TENABLE" (
"id"    INTEGER,
PRIMARY KEY("id")
)

this is my code :-

import requests
import sqlite3

url = "``https://xxxxxxxxxx``"

headers = {
"Accept": "application/json",
"X-ApiKeys": "accessKey=xxxxxxxxxxxxx;secretKey=xxxxxxxxxxxxx"
}`

response = requests.request("GET", url, headers=headers)
query = "ALTER TABLE TENABLE ADD COLUMN values (?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?)"
a = response.json()
b = a['assets'][0]
connection_obj = sqlite3.connect('tenable.db3')
cursor_obj = connection_obj.cursor()
lll = list(b.keys())
dd = (", ".join(lll))
cursor_obj.execute(query, [dd])


Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source