-
Notifications
You must be signed in to change notification settings - Fork 0
/
list_subtypes.py
47 lines (38 loc) · 1.5 KB
/
list_subtypes.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
import argparse
from database import connect_to_database
if __name__ == "__main__":
parser = argparse.ArgumentParser()
parser.add_argument('device_name', type=str, help='the name of the device you want to scan')
parser.add_argument('--filetype', type=str, default='image', help='the MIME-type of the files to consider')
parser.add_argument('--db_url', type=str, default=None, help='the location of the database file')
args = parser.parse_args()
print(args.filetype)
sql_select_subtypes = """
SELECT DISTINCT files.type, files.subtype, count(*)
FROM files
INNER JOIN devices
ON files.device_id=devices.id
WHERE files.type='{type}'
AND devices.name='{device_name}'
GROUP BY files.type, files.subtype;
""".format(type=args.filetype, device_name=args.device_name)
sql_select_examples = """
SELECT relpath
FROM files
INNER JOIN devices
ON files.device_id=devices.id
WHERE files.type=?
AND files.subtype=?
AND devices.name='{device_name}'
LIMIT 3;
""".format(device_name=args.device_name)
try:
conn = connect_to_database(db_url=args.db_url)
cur = conn.execute(sql_select_subtypes)
for c in cur:
print("type: '{}' subtype: '{}' count: {}".format(*c))
cursor = conn.execute(sql_select_examples,c[:2])
for c1 in cursor:
print('\t{}'.format(c1[0]))
finally:
conn.close()