forked from beamzer/ScirtScan
-
Notifications
You must be signed in to change notification settings - Fork 0
/
sql2csv.py
executable file
·33 lines (24 loc) · 918 Bytes
/
sql2csv.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
#!/usr/bin/env python3
import sqlite3
import argparse
# Create argument parser
parser = argparse.ArgumentParser(description='Output the contents of a SQLite database.')
parser.add_argument('database', help='The SQLite database file to open')
# Parse arguments
args = parser.parse_args()
# Connect to the SQLite database
connection = sqlite3.connect(args.database)
# Create a cursor object
cursor = connection.cursor()
# Execute the SQL statement
cursor.execute("SELECT * FROM website_checks")
# Print the column names as a header, separated by semicolons
print(';'.join([column[0] for column in cursor.description]))
# Fetch all rows from the result of the SQL statement
rows = cursor.fetchall()
# Iterate through each row
for row in rows:
# Print the row, with each field separated by a semicolon
print(';'.join([str(item) for item in row]))
# Close the connection to the database
connection.close()