Initial commit
This commit is contained in:
parent
eda8d2ce25
commit
110c010408
5 changed files with 56 additions and 2 deletions
18
docker-compose.yml
Normal file
18
docker-compose.yml
Normal file
|
@ -0,0 +1,18 @@
|
||||||
|
services:
|
||||||
|
mongo:
|
||||||
|
image: mongo:latest
|
||||||
|
restart: always
|
||||||
|
environment:
|
||||||
|
MONGO_INITDB_ROOT_USERNAME: root
|
||||||
|
MONGO_INITDB_ROOT_PASSWORD: example
|
||||||
|
|
||||||
|
mongo-express:
|
||||||
|
image: mongo-express:latest
|
||||||
|
restart: always
|
||||||
|
ports:
|
||||||
|
- "8081:8081"
|
||||||
|
environment:
|
||||||
|
ME_CONFIG_MONGODB_ADMINUSERNAME: root
|
||||||
|
ME_CONFIG_MONGODB_ADMINPASSWORD: example
|
||||||
|
ME_CONFIG_MONGODB_URL: mongodb://root:example@mongo:27017/
|
||||||
|
ME_CONFIG_BASICAUTH: false
|
|
@ -1,2 +1,38 @@
|
||||||
|
import hashlib
|
||||||
|
import os
|
||||||
|
import subprocess
|
||||||
|
import sys
|
||||||
|
|
||||||
|
from pymongo import MongoClient
|
||||||
|
|
||||||
|
|
||||||
|
def _execute_exiftool(img_file: str) -> dict:
|
||||||
|
res = subprocess.run(
|
||||||
|
['exiftool', img_file],
|
||||||
|
capture_output=True,
|
||||||
|
text=True,
|
||||||
|
)
|
||||||
|
|
||||||
|
exif_metadata = {}
|
||||||
|
|
||||||
|
for line in res.stdout.splitlines():
|
||||||
|
parts = line.split(':', 1)
|
||||||
|
exif_metadata[parts[0].strip().lower().replace(' ', '_')] = parts[1].strip()
|
||||||
|
|
||||||
|
return exif_metadata
|
||||||
|
|
||||||
|
|
||||||
if __name__ == '__main__':
|
if __name__ == '__main__':
|
||||||
pass
|
# Authenticate against MongoDB server
|
||||||
|
mongo = MongoClient(os.environ['MONGO_URI'])
|
||||||
|
database = mongo.exif_database
|
||||||
|
collection = database.pictures
|
||||||
|
|
||||||
|
picture_metadata = _execute_exiftool(sys.argv[1])
|
||||||
|
|
||||||
|
# Append MongoDB identifier
|
||||||
|
picture_metadata['_id'] = hashlib.sha256(sys.argv[1].encode('utf-8')).hexdigest()
|
||||||
|
picture_metadata['path'] = sys.argv[1]
|
||||||
|
|
||||||
|
# Insert into MongoDB
|
||||||
|
collection.insert_one(picture_metadata)
|
||||||
|
|
BIN
exif_database/__pycache__/__init__.cpython-311.pyc
Normal file
BIN
exif_database/__pycache__/__init__.cpython-311.pyc
Normal file
Binary file not shown.
BIN
exif_database/__pycache__/__main__.cpython-311.pyc
Normal file
BIN
exif_database/__pycache__/__main__.cpython-311.pyc
Normal file
Binary file not shown.
|
@ -1 +1 @@
|
||||||
exif==1.6.0
|
pymongo==4.10.1
|
Loading…
Add table
Add a link
Reference in a new issue