From 44aa4989daa2daf33c15f9eba9584a8081d783f7 Mon Sep 17 00:00:00 2001 From: Jeena Date: Mon, 23 Aug 2021 05:37:35 +0200 Subject: [PATCH] Add Home Assistant upload and convert --- Pipfile.lock | 39 ++++++++++++--------------------------- README.md | 1 + ha.py | 37 +++++++++++++++++++++++++++++++++++++ run.sh | 2 +- 4 files changed, 51 insertions(+), 28 deletions(-) create mode 100755 ha.py diff --git a/Pipfile.lock b/Pipfile.lock index 8250ca6..d565a89 100644 --- a/Pipfile.lock +++ b/Pipfile.lock @@ -41,27 +41,27 @@ }, "google-api-core": { "hashes": [ - "sha256:108cf94336aed7e614eafc53933ef02adf63b9f0fd87e8f8212acaa09eaca456", - "sha256:1d63e2b28057d79d64795c9a70abcecb5b7e96da732d011abf09606a39b48701" + "sha256:428805de17b48ca1af2fdb5bbfc2334e1bbcb0ea4a16506fa1337fb29c8f37c8", + "sha256:bd9eb0709f4e10dd6fddb32fd0788a190b434426c258be6e00ef40da136d768d" ], - "markers": "python_version >= '2.7' and python_version not in '3.0, 3.1, 3.2, 3.3, 3.4, 3.5'", - "version": "==1.31.1" + "markers": "python_version >= '3.6'", + "version": "==2.0.0" }, "google-api-python-client": { "hashes": [ - "sha256:8375489232823f44c601196a960505e03ec58c95ddb6415c6b1d1d76b468f8ba", - "sha256:87af2462b922c976291fcd0d062a0011d4ac41b11cee04089aa9577dd7b44ae3" + "sha256:20bc8f711883f9f8f96d96bc44b40ad0e2b0a9ef7df53e7c738948584fddd1c2", + "sha256:26402b51b21480e5f2de2650f4dc41d19db031ce28d26047f30dad0803fbf27d" ], "index": "pypi", - "version": "==2.15.0" + "version": "==2.17.0" }, "google-auth": { "hashes": [ - "sha256:bd6aa5916970a823e76ffb3d5c3ad3f0bedafca0a7fa53bc15149ab21cb71e05", - "sha256:f1094088bae046fb06f3d1a3d7df14717e8d959e9105b79c57725bd4e17597a2" + "sha256:c012c8be7c442c8309ca8fa0876fef33f5fd977c467be1e1c1c2f721e8ebd73c", + "sha256:ea1af050b3e06eb73e4470f704d23007307bc0e87c13e015f6b90460f1407bd3" ], - "markers": "python_version >= '2.7' and python_version not in '3.0, 3.1, 3.2, 3.3, 3.4, 3.5'", - "version": "==1.34.0" + "markers": "python_version >= '3.6'", + "version": "==2.0.1" }, "google-auth-httplib2": { "hashes": [ @@ -109,14 +109,6 @@ "markers": "python_version >= '3.6'", "version": "==3.1.1" }, - "packaging": { - "hashes": [ - "sha256:7dc96269f53a4ccec5c0670940a4281106dd0bb343f47b7471f779df49c2fbe7", - "sha256:c86254f9220d55e31cc94d69bade760f0847da8000def4dfe1c6b872fd14ff14" - ], - "markers": "python_version >= '3.6'", - "version": "==21.0" - }, "protobuf": { "hashes": [ "sha256:13ee7be3c2d9a5d2b42a1030976f760f28755fcf5863c55b1460fd205e6cd637", @@ -228,13 +220,6 @@ "markers": "python_version >= '2.6' and python_version not in '3.0, 3.1, 3.2, 3.3'", "version": "==2.4.7" }, - "pytz": { - "hashes": [ - "sha256:83a4a90894bf38e243cf052c8b58f381bfe9a7a483f6a9cab140bc7f702ac4da", - "sha256:eb10ce3e7736052ed3623d49975ce333bcd712c7bb19a58b9e2089d4057d0798" - ], - "version": "==2021.1" - }, "requests": { "hashes": [ "sha256:6c1246513ecd5ecd4528a0906f910e8f0f9c6b8ec72030dc9fd154dc1a6efd24", @@ -256,7 +241,7 @@ "sha256:78f9a9bf4e7be0c5ded4583326e7461e3a3c5aae24073648b4bdfa797d78c9d2", "sha256:9d689e6ca1b3038bc82bf8d23e944b6b6037bc02301a574935b2dd946e0353b9" ], - "markers": "python_version >= '3.6'", + "markers": "python_version >= '3.5' and python_version < '4'", "version": "==4.7.2" }, "six": { diff --git a/README.md b/README.md index 5caded9..7959af6 100644 --- a/README.md +++ b/README.md @@ -9,6 +9,7 @@ Installation ------------ ``` +sudo apt-get install ufraw-batch imagemagick pipenv install pipenv shell diff --git a/ha.py b/ha.py new file mode 100755 index 0000000..2d039b3 --- /dev/null +++ b/ha.py @@ -0,0 +1,37 @@ +#!/usr/bin/env python3 + +import synology +# from wand.image import Image +import os +import shutil + +def prepare_photo(i, path): + # sudo apt-get install ufraw-batch + # convert 13895032967_642e23af42_o.jpg -adaptive-resize 1920x1080\> -size 1920x1080 xc:black +swap -gravity center -composite 01.jpg + # filename, file_extension = os.path.splitext(path) + new_path = os.path.join(os.path.dirname(path), str(i) + '.jpg') + cmd = 'convert "' + path + '" -adaptive-resize 1920x1080\> -size 1920x1080 xc:black +swap -gravity center -composite ' + new_path + print(cmd) + os.system(cmd) + # os.rename(path, new_path) + return new_path + +def upload_photo(remotepath, path): + cmd = 'scp ' + path + ' ' + remotepath + os.system(cmd) + +if __name__ == "__main__": + ha_path = os.getenv('HA_PATH') + ha_path = "root@bundang.swierczyniec.info:/media/Synology" + host_ip = os.getenv('DB_HOST') + conn = synology.connect_db(host_ip, os.getenv('DB_USER'), os.getenv('DB_PASSWD')) + names = "richard|yingfen" + pictures = synology.fetch_paths_for_names(conn, names, 20) + synology.close_db(conn) + dirpath = synology.fetch_files("jeena@" + host_ip, "/var/services/homes/jeena/Drive", pictures) + + with os.scandir(dirpath) as dirs: + for i, entry in enumerate(dirs): + upload_photo(ha_path, prepare_photo(i, os.path.join(dirpath, entry.name))) + shutil.rmtree(dirpath) + diff --git a/run.sh b/run.sh index 44371de..0cfbea8 100755 --- a/run.sh +++ b/run.sh @@ -2,4 +2,4 @@ PATH=/home/jeena/.local/bin/:$PATH cd /home/jeena/Projects/synology-pictures/ -pipenv run python3 google-photos.py +pipenv run python3 ha.py