This commit is contained in:
jaydee
2024-09-23 15:41:07 +02:00
4 changed files with 336 additions and 138 deletions

79
handle_imported_video.py Normal file
View File

@@ -0,0 +1,79 @@
import os
from posixpath import ismount
import sys
import time
import subprocess
import datetime
import shutil
import json
import getopt
_SOURCE_DIR = "/media/nas/nas-photo/imported/"
_DEV = "gopro9_1"
_DAY_DIR = "2022-08-04 - Bukovec-Jano"
_FULL_PATH = _SOURCE_DIR + "/" + _DEV + "/" + _DAY_DIR
try:
opts, args = getopt.getopt(sys.argv[1:], "hbl:o:s:t:", ["command=", "help", "output=", "backup"])
except getopt.GetoptError as err:
# print help information and exit:
print(str(err)) # will print something like "option -a not recognized"
#usage()
sys.exit(2)
output = None
# QJ : getopts
for o, a in opts:
if o == "-h":
_ACTION = True
elif o in ("-b", "--backup"):
_BACKUP = True
elif o in ("-l", "--level"):
_LOG_LEVEL = a.upper()
elif o in ("-o", "--output"):
OUTPUT_FILE = a
elif o in ("-s", "--schema"):
SCHEMA = a
elif o in ("-t", "--tables"):
TABLES = a
else:
_WIZZARD = True
video_seq = {}
if os.path.exists(_FULL_PATH):
for filename in os.listdir(_FULL_PATH):
if filename.endswith(".MP4"):
part = "GH" + filename[2:4]
seq = filename[4:8]
if not seq in video_seq:
video_seq[seq] = []
video_seq[seq].append(part + seq + ".MP4")
print(filename)
print(seq)
print(part)
print(json.dumps(video_seq,indent=2))
for vid in video_seq:
export_name = "joined_" + vid + ".MP4"
parts = video_seq[vid]
parts.sort()
if len(parts) > 1:
print("This need to be joined!")
# for p in parts:
# join_string =
else:
continue
print(parts)
join_s = "|".join(parts)
print(join_s)
# print(type(parts))
#ffmpeg -i concat:"input1.mp4|input2.mp4" output.mp4
os.chdir(_FULL_PATH)
myCmd = 'ffmpeg -i concat:"' + join_s + '" ' + export_name
status, output = subprocess.getstatusoutput(myCmd)
print(output)

View File

@@ -27,43 +27,49 @@ if curos == "Windows":
import winreg
def uptime():
try:
f = open( "/proc/uptime" )
contents = f.read().split()
f.close()
except:
try:
f = open( "/proc/uptime" )
contents = f.read().split()
f.close()
except:
return "Cannot open uptime file: /proc/uptime"
total_seconds = float(contents[0])
total_seconds = float(contents[0])
# Helper vars:
MINUTE = 60
HOUR = MINUTE * 60
DAY = HOUR * 24
# Helper vars:
MINUTE = 60
HOUR = MINUTE * 60
DAY = HOUR * 24
# Get the days, hours, etc:
days = int( total_seconds / DAY )
hours = int( ( total_seconds % DAY ) / HOUR )
minutes = int( ( total_seconds % HOUR ) / MINUTE )
seconds = int( total_seconds % MINUTE )
# Get the days, hours, etc:
days = int( total_seconds / DAY )
hours = int( ( total_seconds % DAY ) / HOUR )
minutes = int( ( total_seconds % HOUR ) / MINUTE )
seconds = int( total_seconds % MINUTE )
# Build up the pretty string (like this: "N days, N hours, N minutes, N seconds")
string = ""
string = ""
# if days > 0:
# string += str(days) + " " + (days == 1 and "d" or "d" ) + ", "
# if len(string) > 0 or hours > 0:
# string += str(hours) + " " + (hours == 1 and "h" or "h" ) + ", "
# if len(string) > 0 or minutes > 0:
# string += str(minutes) + " " + (minutes == 1 and "m" or "m" ) + ", "
if days > 0:
string += str(days) + " " + (days == 1 and "d" or "d" ) + ", "
if len(string) > 0 or hours > 0:
string += str(hours) + ":"
if len(string) > 0 or minutes > 0:
string += str(minutes) + ":"
string += str(seconds)
if days > 0:
string += str(days) + " " + (days == 1 and "d" or "d" ) + ", "
if len(string) > 0 or hours > 0:
if hours < 10:
hours = "0{}".format(hours)
string += str(hours) + ":"
if len(string) > 0 or minutes > 0:
if minutes < 10:
minutes = "0{}".format(minutes)
string += str(minutes) + ":"
return string;
if seconds < 10:
seconds = "0{}".format(seconds)
string += str(seconds)
return string;
def writeLog(msg, svr="INFO"):
ts = datetime.datetime.now().strftime("%Y-%m-%d %H:%M:%S")
@@ -122,6 +128,7 @@ def check_router():
serv_d[rul[0]] = {"src_port":rul[1],"dest_ip":rul[2],"dest_port":rul[3],"prot":rul[4]}
stats["serv_dest"] = rul[2]
break
stats["status"] = "on"
#stats["serv_dest"] = json.dumps(serv_d)
#stats["serv_dest"] = json.dumps(serv_d)
#out = subprocess.Popen(cmnd.split())
@@ -171,6 +178,10 @@ else:
if int(count) >= 2:
writeLog("script exist")
sys.exit()
# Stops duplicate instance from running
writeLog(count)
@@ -315,7 +326,7 @@ IP = get_ip()
print("OS : " + curos)
writeLog("OS : " + curos)
if curos != "Windows":
import autorandr
import autorandr
else:
import winreg
@@ -917,9 +928,15 @@ def on_message(client, userdata, msg):
print("not a json!")
client = mqtt.Client()
<<<<<<< HEAD
client.username_pw_set("jaydee", password="jaydee1")
client.will_set("home-assistant/" + host + "/hwstats", payload='{"status":"off"}', qos=0, retain=True)
=======
payload = '{"status":"off"}'
client.username_pw_set("jaydee", password="jaydee1")
client.will_set("home-assistant/" + host.lower() + "/hwstats", payload=payload, qos=0, retain=True)
>>>>>>> f8ca3c609387acf650821dc35de80b826724ee5f
client.on_connect = on_connect
client.on_message = on_message
writeLog(MQTT_HOST)

62
pg_backup.py Normal file
View File

@@ -0,0 +1,62 @@
import re
import subprocess
import os
import json
import sys
import time
import json
import datetime
import getopt
import requests
import logging
try:
opts, args = getopt.getopt(sys.argv[1:], "hbl:o:s:t:", ["command=", "help", "output=", "backup"])
except getopt.GetoptError as err:
# print help information and exit:
print(str(err)) # will print something like "option -a not recognized"
#usage()
sys.exit(2)
output = None
# QJ : getopts
OUTPUT_FILE = "pg_backup.sql"
for o, a in opts:
if o == "-h":
_ACTION = True
elif o in ("-b", "--backup"):
_BACKUP = True
elif o in ("-l", "--level"):
_LOG_LEVEL = a.upper()
elif o in ("-o", "--output"):
OUTPUT_FILE = a
elif o in ("-s", "--schema"):
SCHEMA = a
elif o in ("-t", "--tables"):
TABLES = a
else:
_WIZZARD = True
LOG_FILE = "/tmp/pg_backup.log"
if _LOG_LEVEL == "DEBUG":
logging.basicConfig(filename=LOG_FILE, level=logging.DEBUG, format='%(asctime)s : %(levelname)s : %(message)s', datefmt='%m/%d/%Y %I:%M:%S %p')
logging.debug('using debug loging')
elif _LOG_LEVEL == "ERROR":
logging.basicConfig(filename=LOG_FILE, level=logging.ERROR, format='%(asctime)s : %(levelname)s : %(message)s', datefmt='%m/%d/%Y %I:%M:%S %p')
logging.info('using error loging')
elif _LOG_LEVEL == "SCAN":
logging.basicConfig(filename=LOG_FILE, level=logging.DEBUG, format='%(asctime)s : %(levelname)s : %(message)s', datefmt='%m/%d/%Y %I:%M:%S %p')
logging.info('using error loging')
else:
logging.basicConfig(filename=LOG_FILE, level=logging.INFO, format='%(asctime)s : %(levelname)s : %(message)s', datefmt='%m/%d/%Y %I:%M:%S %p')
cmnd = "sudo -u postgres pg_dump {} {} > {}".format(TABLES, SCHEMA, OUTPUT_FILE)
print(cmnd)
#status, output = subprocess.getstatusoutput(cmnd)

View File

@@ -14,9 +14,9 @@ import ctypes
import getopt
import requests
CHECK_MARK = "\033[0;32m\xE2\x9C\x94\033[0m"
_MQTT_SETUP = _BACKUP = _APPLY = _WIFI_SETUP = False
_MQTT_SETUP = _BACKUP = _APPLY = _WIFI_SETUP = _UPGRADE_FW = False
try:
opts, args = getopt.getopt(sys.argv[1:], "wh:bm", ["command=", "help", "output=", "backup"])
opts, args = getopt.getopt(sys.argv[1:], "wh:bmu", ["command=", "help", "output=", "backup"])
except getopt.GetoptError as err:
# print help information and exit:
print(str(err)) # will print something like "option -a not recognized"
@@ -36,6 +36,8 @@ for o, a in opts:
_WIFI_SETUP = True
elif o in ("-a", "--apply"):
_APPLY = True
elif o in ("-u", "--upgrade_fw"):
_UPGRADE_FW = True
else:
_WIZZARD = True
@@ -90,6 +92,40 @@ def create_backup():
#print(sys_ip + " : Not a listening")
pass
def upgrade_fw():
cmnd = "nmap -sP 192.168.77.*|grep \"Nmap scan report\"|egrep -o \"[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\""
#print(cmnd)
status, output = subprocess.getstatusoutput(cmnd)
# print(output)
ips = output.splitlines()
for sys_ip in ips:
print("Thsis is ip : " + sys_ip)
cmnd = "nmap " + sys_ip + " -p80|grep \"80/tcp open http\""
status, output = subprocess.getstatusoutput(cmnd)
# print("status of 80 : " + str(status))
if status == 0:
try:
# url = "http://" + sys_ip + "/cm?user=admin&password=l4c1j4yd33Du5l0&cmnd=STATUS+5"
url = "http://" + sys_ip + "/cm?user=admin&password=l4c1j4yd33Du5l0&cmnd=STATUS+1"
#print(url)
resp = requests.get(url)
json_str = resp.content.decode('utf-8')
#print(json_str)
tasm_data = json.loads(json_str)
#print(tasm_data)
print(tasm_data["StatusPRM"]["OtaUrl"])
except:
#print(sys_ip + " : Not a tasmota!")
pass
else:
#print(sys_ip + " : Not a listening")
pass
def wifi_setup():
SSID1 = input(">> SID1 ? (default=jaydee) : ") or "jaydee"
@@ -170,3 +206,7 @@ if _MQTT_SETUP:
if _WIFI_SETUP:
wifi_setup()
if _UPGRADE_FW:
upgrade_fw()