You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
24 lines
611 B
Python
24 lines
611 B
Python
import os, json
|
|
from funcs import generate_phash
|
|
|
|
count = 0
|
|
cacheDir = 'cache'
|
|
dataPath = 'pins.json'
|
|
|
|
os.makedirs(cacheDir, exist_ok=True)
|
|
|
|
medias = json.load(open(dataPath))
|
|
|
|
for item in medias:
|
|
count += 1
|
|
if item['type'] == 'image':
|
|
filepath = item['filepath']
|
|
if not os.path.exists(filepath):
|
|
print(f"File {filepath} does not exist, skipping.")
|
|
continue
|
|
phash = generate_phash(filepath)
|
|
item['phash'] = phash
|
|
print(f"Processed {count}/{len(medias)}: with pHash {phash}")
|
|
|
|
with open(dataPath, 'w') as f:
|
|
json.dump(medias, f) |