-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathget_image_hashes.py
executable file
·51 lines (47 loc) · 1.28 KB
/
get_image_hashes.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
48
49
50
51
#!/usr/bin/env python3
import os
import sys
import sqlite3
import plistlib
import datetime as dt
from contextlib import contextmanager
from wf_common import *
@contextmanager
def database(path):
db = sqlite3.connect(path)
yield db
db.close()
def get_image_hashes(atleast=0, num_clips=None):
with database(db_res) as db:
rows = db.execute("SELECT dataHash,dataType from clipboard WHERE dataType IN (1,2) AND ts >= ? ORDER BY rowid DESC", [atleast])
rc = 0
for r in rows:
if num_clips and rc >= num_clips:
break
(fn, dtype) = r
img = os.path.join(i_path, fn)
if dtype == 2:
try:
with open(img, "rb") as fp:
plistobj = plistlib.load(fp)
except:
continue
imgfiles = [i for i in plistobj if os.path.exists(i) and i.split(os.extsep)[-1].lower() in img_exts]
for f in imgfiles:
rc += 1
print(f)
if num_clips and rc >= num_clips:
break
else:
rc += 1
print(fn)
if num_clips and rc >= num_clips:
break
if __name__ == '__main__':
args = sys.argv[1:]
if args[0] == '--atleast':
get_image_hashes(atleast=int(args[1]))
elif args[0] == '--num_clips':
get_image_hashes(num_clips=int(args[1]))
else:
exit(1)