Add systemd files and passing room-id for matrix
This commit is contained in:
parent
52f935a084
commit
85fd862db4
8 changed files with 96 additions and 16 deletions
9
edit.py
9
edit.py
|
@ -64,7 +64,11 @@ class Image:
|
|||
|
||||
def get_takentime(self):
|
||||
e = self.get_exif()
|
||||
date = e.get('datetime_original')
|
||||
date = None
|
||||
if e == None:
|
||||
date = os.path.basename(self.path)
|
||||
if date == None:
|
||||
date = e.get('datetime_original')
|
||||
if date == None:
|
||||
date = e.get('datetime')
|
||||
if date == None:
|
||||
|
@ -201,7 +205,8 @@ if __name__ == "__main__":
|
|||
else:
|
||||
img_path = sys.argv[1]
|
||||
img = Image(img_path)
|
||||
img.get_takentime()
|
||||
img.crop()
|
||||
img.add_metadata()
|
||||
img.show()
|
||||
#img.show()
|
||||
img.safe("/home/jeena/Downloads/test.jpg")
|
||||
|
|
36
matrix.py
36
matrix.py
|
@ -6,7 +6,7 @@ import os
|
|||
import synology
|
||||
import edit
|
||||
import shutil
|
||||
|
||||
import argparse
|
||||
import matrix_commander
|
||||
from matrix_commander import main
|
||||
|
||||
|
@ -22,31 +22,45 @@ def years_ago(path):
|
|||
ret += " ago."
|
||||
return ret
|
||||
|
||||
def post_photo(path):
|
||||
def post_photo(path, roomid):
|
||||
argv = ["matrix-commander"]
|
||||
argv.extend(["--message", "" + years_ago(path) + ""])
|
||||
argv.extend(["--image", path])
|
||||
argv.extend(["--print-event-id"])
|
||||
argv.extend(["--room", roomid])
|
||||
return matrix_commander.main(argv)
|
||||
|
||||
def get_args():
|
||||
parser = argparse.ArgumentParser(description='Post dates picture(s) to a Matrix room')
|
||||
parser.add_argument('-n', '--names', required=True)
|
||||
parser.add_argument('-e', '--exclude', default=None, required=False)
|
||||
parser.add_argument('-r', '--roomid', required=True)
|
||||
parser.add_argument('-m', '--month', default=datetime.today().month, type=int)
|
||||
parser.add_argument('-d', '--day', default=datetime.today().day, type=int)
|
||||
parser.add_argument('-s', '--size', default=1, type=int)
|
||||
return parser.parse_args()
|
||||
|
||||
if __name__ == "__main__":
|
||||
if len(sys.argv) != 2:
|
||||
print("Usage: matrix.py richard|kaylee")
|
||||
exit(1)
|
||||
|
||||
args = get_args()
|
||||
sy_host = os.getenv('SY_DB_HOST')
|
||||
sy_user = os.getenv('SY_USER')
|
||||
|
||||
# Get img paths from database
|
||||
conn = synology.connect_db(sy_host, os.getenv('SY_DB_USER'), os.getenv('SY_DB_PASSWD'))
|
||||
names = sys.argv[1]
|
||||
month = datetime.today().month
|
||||
day = datetime.today().day
|
||||
pictures = synology.fetch_path_for_names_day_and_month(conn, names, month, day, 1)
|
||||
pictures = synology.fetch_path_for_names_exclude_day_and_month(conn,
|
||||
args.names, args.exclude, args.month, args.day, args.size)
|
||||
synology.close_db(conn)
|
||||
|
||||
# Fetch files from synology to tmp
|
||||
dirpath = synology.fetch_files(sy_user + "@" + sy_host, pictures)
|
||||
|
||||
# Traverse dirs and post picures in matrix room
|
||||
ret = 0
|
||||
with os.scandir(dirpath) as dirs:
|
||||
for i, entry in enumerate(dirs):
|
||||
ret = post_photo(os.path.join(dirpath, entry.name))
|
||||
ret = post_photo(os.path.join(dirpath, entry.name), args.roomid)
|
||||
|
||||
# Cleanup
|
||||
shutil.rmtree(dirpath)
|
||||
exit(ret)
|
||||
|
||||
|
|
|
@ -1,4 +1,5 @@
|
|||
#!/bin/bash
|
||||
|
||||
PATH=$HOME/.local/bin/:$PATH
|
||||
pipenv run python matrix.py "richard|yingfen|kaylee"
|
||||
pipenv run python matrix.py -n "yingfen|richard|kaylee" -e dongyong -r "\!iyDYVdSookjYKhoXuU:jeena.net"
|
||||
pipenv run python matrix.py -n "kinga|lili|karl|richard|georg|christine" -e dongyong -r "\!aPbeAzniGnemrkBcVU:jeena.net"
|
||||
|
|
32
synology.py
32
synology.py
|
@ -35,7 +35,7 @@ LIMIT %s;
|
|||
cur.close()
|
||||
|
||||
return pictures
|
||||
|
||||
|
||||
def fetch_path_for_names_day_and_month(conn, names, month, day, limit=1):
|
||||
sql_query = """
|
||||
SELECT folder.name, unit.filename, user_info.name AS user, EXTRACT(YEAR FROM to_timestamp(unit.takentime)::date) as year
|
||||
|
@ -58,6 +58,34 @@ LIMIT %s;
|
|||
cur.close()
|
||||
|
||||
return pictures
|
||||
|
||||
def fetch_path_for_names_exclude_day_and_month(conn, names, exclude, month, day, limit=1):
|
||||
if exclude == None:
|
||||
return fetch_path_for_names_day_and_month(conn, names, month, day, limit)
|
||||
|
||||
sql_query = """
|
||||
SELECT folder.name, unit.filename, user_info.name AS user, EXTRACT(YEAR FROM to_timestamp(unit.takentime)::date) as year
|
||||
FROM unit
|
||||
LEFT OUTER JOIN face ON face.ref_id_unit = unit.id
|
||||
LEFT OUTER JOIN folder ON folder.id = unit.id_folder
|
||||
LEFT OUTER JOIN user_info ON user_info.id = unit.id_user
|
||||
WHERE
|
||||
face.id_person in (SELECT id FROM person WHERE lower(name) SIMILAR TO %s)
|
||||
AND
|
||||
face.id_person not in (SELECT id FROM person WHERE lower(name) SIMILAR TO %s)
|
||||
AND
|
||||
EXTRACT(MONTH FROM to_timestamp(unit.takentime)::date) = %s
|
||||
AND
|
||||
EXTRACT(DAY FROM to_timestamp(unit.takentime)::date) = %s
|
||||
ORDER BY random()
|
||||
LIMIT %s;
|
||||
"""
|
||||
cur = conn.cursor()
|
||||
cur.execute(sql_query, ('%(' + names + ')%', '%(' + exclude + ')%', month, day, limit))
|
||||
pictures = cur.fetchall()
|
||||
cur.close()
|
||||
|
||||
return pictures
|
||||
|
||||
def fetch_files(remotehost, pictures):
|
||||
dirpath = tempfile.mkdtemp()
|
||||
|
@ -67,7 +95,7 @@ def fetch_files(remotehost, pictures):
|
|||
path = picture[0]
|
||||
name = picture[1]
|
||||
user = picture[2]
|
||||
year = picture[3] + "-" if len(picture) > 3 else ""
|
||||
year = str(picture[3]) + "-" if len(picture) > 3 else ""
|
||||
if user == '/volume1/photo':
|
||||
lib_path = "/photo"
|
||||
else:
|
||||
|
|
8
systemd/synology-ha.service
Normal file
8
systemd/synology-ha.service
Normal file
|
@ -0,0 +1,8 @@
|
|||
[Unit]
|
||||
Description=Synology Pictures on TV
|
||||
|
||||
[Service]
|
||||
User=jeena
|
||||
Type=simple
|
||||
WorkingDirectory=/home/jeena/Projects/synology-pictures/
|
||||
ExecStart=/home/jeena/Projects/synology-pictures/run.sh
|
8
systemd/synology-ha.timer
Normal file
8
systemd/synology-ha.timer
Normal file
|
@ -0,0 +1,8 @@
|
|||
[Unit]
|
||||
Description=Run Synology Photos on TV hourly
|
||||
|
||||
[Timer]
|
||||
OnCalendar=*-*-* *:00:00
|
||||
|
||||
[Install]
|
||||
WantedBy=timers.target
|
8
systemd/synology-matrix.service
Normal file
8
systemd/synology-matrix.service
Normal file
|
@ -0,0 +1,8 @@
|
|||
[Unit]
|
||||
Description=Synology Pictures on TV
|
||||
|
||||
[Service]
|
||||
User=jeena
|
||||
Type=simple
|
||||
WorkingDirectory=/home/jeena/Projects/synology-pictures/
|
||||
ExecStart=/home/jeena/Projects/synology-pictures/run-matrix.sh
|
8
systemd/synology-matrix.timer
Normal file
8
systemd/synology-matrix.timer
Normal file
|
@ -0,0 +1,8 @@
|
|||
[Unit]
|
||||
Description=Run Synology picture of the day in matrix daily
|
||||
|
||||
[Timer]
|
||||
OnCalendar=*-*-* 06:00:00
|
||||
|
||||
[Install]
|
||||
WantedBy=timers.target
|
Loading…
Add table
Add a link
Reference in a new issue