all working i think
This commit is contained in:
78
archive/app.py
Normal file
78
archive/app.py
Normal file
@ -0,0 +1,78 @@
|
||||
# app.py
|
||||
from flask import Flask, request, jsonify
|
||||
import subprocess
|
||||
import requests
|
||||
import psycopg2
|
||||
import os
|
||||
import re
|
||||
from datetime import datetime, timedelta
|
||||
import io
|
||||
import json
|
||||
|
||||
app = Flask(__name__)
|
||||
|
||||
# API endpoint for charge
|
||||
@app.route('/test', methods=['GET'])
|
||||
def test():
|
||||
return jsonify({"message": "Hello there"}), 200
|
||||
|
||||
# API endpoint for service status
|
||||
@app.route('/get-info', methods=['GET'])
|
||||
def get_info():
|
||||
result = service_status()
|
||||
print(result)
|
||||
return jsonify(result)
|
||||
|
||||
# # Stop Service
|
||||
# @app.route('/stop', methods=['GET'])
|
||||
# def stop_service():
|
||||
# result = stop_timelapse()
|
||||
# print(result)
|
||||
# return jsonify(result)
|
||||
#
|
||||
# # Start Service
|
||||
# @app.route('/start', methods=['GET'])
|
||||
# def start_service():
|
||||
# result = start_timelapse()
|
||||
# print(result)
|
||||
# return jsonify(result)
|
||||
|
||||
# get service status
|
||||
|
||||
def service_status():
|
||||
service_name = "timelapse.service"
|
||||
try:
|
||||
# Check the status of the service using systemctl
|
||||
result = subprocess.run(['systemctl', 'is-active', service_name], check=True, capture_output=True, text=True)
|
||||
|
||||
if result.returncode == 0:
|
||||
active_status = "running" if result.stdout.strip() == b'active\n' else "not running"
|
||||
|
||||
# Get the last message from the system log for this service
|
||||
logs_result = subprocess.run(['journalctl', '-u', service_name, '-xe'], check=True, capture_output=True, text=True)
|
||||
last_message = logs_result.stdout
|
||||
|
||||
response = {
|
||||
"service_status": active_status,
|
||||
"service_message": last_message.strip() if last_message else "No message available"
|
||||
}
|
||||
|
||||
return json.dumps(response)
|
||||
else:
|
||||
raise Exception("Service is not running")
|
||||
except subprocess.CalledProcessError as e:
|
||||
response = {
|
||||
"service_status": "error",
|
||||
"service_message": str(e)
|
||||
}
|
||||
return json.dumps(response)
|
||||
except Exception as e:
|
||||
response = {
|
||||
"service_status": "error",
|
||||
"service_message": str(e)
|
||||
}
|
||||
return json.dumps(response)
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
app.run(debug=True, host='0.0.0.0', port=5000)
|
||||
11
archive/docker-compose-node.yaml.j2
Normal file
11
archive/docker-compose-node.yaml.j2
Normal file
@ -0,0 +1,11 @@
|
||||
services:
|
||||
|
||||
photo_refresh:
|
||||
container_name: photo_refresh
|
||||
image: photo_refresh
|
||||
ports:
|
||||
- 3000:3000
|
||||
volumes:
|
||||
- {{ working_folder }}/small_thumbs:/usr/src/app/public
|
||||
network_mode: bridge
|
||||
restart: always
|
||||
80
archive/gsysctl.yaml
Normal file
80
archive/gsysctl.yaml
Normal file
@ -0,0 +1,80 @@
|
||||
---
|
||||
|
||||
###############################################
|
||||
# Prepare for docker container
|
||||
# https://github.com/shakg/g-systemctl
|
||||
###############################################
|
||||
|
||||
|
||||
|
||||
- name: set docker folder variable
|
||||
set_fact:
|
||||
docker_root: "/opt/cosmos/gsc"
|
||||
|
||||
# clear folder first
|
||||
- name: gsc - delete old folder
|
||||
shell: "rm -R {{ docker_root }}"
|
||||
|
||||
# Create docker Folder
|
||||
- name: g-systemctl - create docker_root folder
|
||||
file:
|
||||
path: "{{ docker_root }}"
|
||||
state: directory
|
||||
mode: '0755'
|
||||
owner: root
|
||||
group: root
|
||||
|
||||
- name: g-systemctl - clone the git
|
||||
git:
|
||||
repo: "https://github.com/shakg/g-systemctl"
|
||||
dest: "{{ docker_root }}"
|
||||
|
||||
###############################################
|
||||
# Start docker container
|
||||
###############################################
|
||||
|
||||
|
||||
- name: Replace golang version number
|
||||
ansible.builtin.replace:
|
||||
path: "{{ docker_root }}/backend/Dockerfile"
|
||||
regexp: '^FROM golang:.*-alpine as development'
|
||||
replace: 'FROM golang:1.24-alpine as development'
|
||||
|
||||
# Replace g-systemctl docker-compose file
|
||||
- name: g-systemctl - replace docker-compose
|
||||
copy:
|
||||
dest: "{{ docker_root }}/docker-compose.yaml"
|
||||
content: |
|
||||
version: '3.8'
|
||||
|
||||
services:
|
||||
frontend:
|
||||
container_name: gsc-frontend
|
||||
network_mode: bridge
|
||||
restart: always
|
||||
build:
|
||||
context: ./frontend
|
||||
target: production
|
||||
ports:
|
||||
- "80:80"
|
||||
|
||||
backend:
|
||||
container_name: gsc-backend
|
||||
network_mode: bridge
|
||||
restart: always
|
||||
build:
|
||||
context: ./backend
|
||||
target: production
|
||||
ports:
|
||||
- "8080:8080"
|
||||
privileged: true
|
||||
|
||||
- name: "g-systemctl - build and run containers"
|
||||
shell: "docker-compose -f {{ docker_root }}/docker-compose.yaml up -d"
|
||||
register: local_index_output
|
||||
- debug: |
|
||||
msg="{{ local_index_output.stdout_lines }}"
|
||||
msg="{{ local_index_output.stderr_lines }}"
|
||||
|
||||
|
||||
...
|
||||
23
archive/image_refresh_node/Dockerfile
Normal file
23
archive/image_refresh_node/Dockerfile
Normal file
@ -0,0 +1,23 @@
|
||||
# Use an official Node runtime as a parent image
|
||||
FROM node:14
|
||||
|
||||
# Create and change to the app directory
|
||||
WORKDIR /usr/src/app
|
||||
|
||||
# Copy package.json and package-lock.json
|
||||
COPY package*.json ./
|
||||
|
||||
# Install any needed packages specified in package.json
|
||||
RUN npm install
|
||||
|
||||
# Bundle app source inside Docker container
|
||||
COPY . .
|
||||
|
||||
# Make port 3000 available to the world outside this container
|
||||
EXPOSE 3000
|
||||
|
||||
# Define environment variable
|
||||
ENV NAME World
|
||||
|
||||
# Run app.py when the container launches
|
||||
CMD ["node", "server.js"]
|
||||
12
archive/image_refresh_node/package.json
Normal file
12
archive/image_refresh_node/package.json
Normal file
@ -0,0 +1,12 @@
|
||||
{
|
||||
"name": "docker_web_app",
|
||||
"version": "1.0.0",
|
||||
"description": "A simple Docker Web app",
|
||||
"main": "server.js",
|
||||
"scripts": {
|
||||
"start": "node server.js"
|
||||
},
|
||||
"dependencies": {
|
||||
"express": "^4.17.1"
|
||||
}
|
||||
}
|
||||
39
archive/image_refresh_node/server.js
Normal file
39
archive/image_refresh_node/server.js
Normal file
@ -0,0 +1,39 @@
|
||||
const express = require('express');
|
||||
const fs = require('fs');
|
||||
const path = require('path');
|
||||
const app = express();
|
||||
const port = 3000;
|
||||
|
||||
app.use(express.static('public')); // Serve static files from the 'public' directory
|
||||
|
||||
// Endpoint to get the most recent image
|
||||
app.get('/most-recent-image', (req, res) => {
|
||||
const imagesDirectory = path.join(__dirname, 'images');
|
||||
fs.readdir(imagesDirectory, (err, files) => {
|
||||
if (err) {
|
||||
return res.status(500).send('Unable to scan directory');
|
||||
}
|
||||
let mostRecentImage = null;
|
||||
let maxDate = Date.now();
|
||||
files.forEach(file => {
|
||||
const filePath = path.join(imagesDirectory, file);
|
||||
const stats = fs.statSync(filePath);
|
||||
if (stats.isFile() && /\.(jpg|jpeg|png|gif)$/i.test(file)) {
|
||||
const currentDate = new Date(stats.mtime).getTime();
|
||||
if (currentDate < maxDate) {
|
||||
mostRecentImage = file;
|
||||
maxDate = currentDate;
|
||||
}
|
||||
}
|
||||
});
|
||||
if (mostRecentImage) {
|
||||
res.json({ imagePath: `/images/${mostRecentImage}` });
|
||||
} else {
|
||||
res.status(404).send('No images found');
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
app.listen(port, () => {
|
||||
console.log(`Server running at http://localhost:${port}`);
|
||||
});
|
||||
39
archive/index.php.old
Normal file
39
archive/index.php.old
Normal file
@ -0,0 +1,39 @@
|
||||
<!DOCTYPE html>
|
||||
<html lang="en">
|
||||
<head>
|
||||
<meta charset="UTF-8">
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
||||
<title>API Call Example</title>
|
||||
<link rel="stylesheet" href="styles.css">
|
||||
</head>
|
||||
<body>
|
||||
|
||||
<p id="time"></p>
|
||||
<p id="apiData"></p>
|
||||
|
||||
<div id="content">
|
||||
<!-- The data will be displayed here -->
|
||||
Loading...
|
||||
</div>
|
||||
|
||||
<script>
|
||||
// JavaScript to fetch and display API data every second
|
||||
function fetchData() {
|
||||
fetch('http://172.17.0.1:5000/status')
|
||||
.then(response => response.json())
|
||||
.then(data => {
|
||||
// Display the fetched data in the div with id 'content'
|
||||
document.getElementById('content').innerHTML = JSON.stringify(data, null, 2);
|
||||
})
|
||||
.catch(error => console.error('Error:', error));
|
||||
}
|
||||
|
||||
// Fetch data on page load
|
||||
fetchData();
|
||||
|
||||
// Set an interval to fetch data every second
|
||||
setInterval(fetchData, 1000);
|
||||
</script>
|
||||
|
||||
</body>
|
||||
</html>
|
||||
58
archive/js_site/app.js
Normal file
58
archive/js_site/app.js
Normal file
@ -0,0 +1,58 @@
|
||||
document.addEventListener('DOMContentLoaded', function () {
|
||||
// Initially set button state to "Loading..."
|
||||
updateButtonState("Loading...");
|
||||
|
||||
// Set an interval to check the API every second
|
||||
setInterval(checkAPIStatus, 1000); // 1000 ms = 1 second
|
||||
});
|
||||
|
||||
// Function to update the button text based on the API state
|
||||
function updateButtonState(status) {
|
||||
const button = document.getElementById('statusButton');
|
||||
|
||||
if (status === "active") {
|
||||
button.innerHTML = "Stop Service";
|
||||
button.style.backgroundColor = "#FF6347"; // Red for stopping
|
||||
button.onclick = stopService;
|
||||
} else if (status === "inactive") {
|
||||
button.innerHTML = "Start Service";
|
||||
button.style.backgroundColor = "#32CD32"; // Green for starting
|
||||
button.onclick = startService;
|
||||
} else if (status === "failed") {
|
||||
button.innerHTML = "Service Failed!";
|
||||
button.style.backgroundColor = "#FF6347"; // Red for failed
|
||||
button.onclick = null;
|
||||
}else {
|
||||
button.innerHTML = "Unknown";
|
||||
button.style.backgroundColor = "#808080"; // Gray for error
|
||||
button.onclick = null;
|
||||
}
|
||||
}
|
||||
|
||||
// Simulate API call and handle response
|
||||
function checkAPIStatus() {
|
||||
// Replace with your actual API endpoint
|
||||
fetch('http://172.17.0.1:5000/status')
|
||||
.then(response => response.json())
|
||||
.then(data => {
|
||||
const apiStatus = data.Status;
|
||||
updateButtonState(apiStatus);
|
||||
})
|
||||
.catch(error => {
|
||||
console.error('Error fetching API status:', error);
|
||||
updateButtonState('error');
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
// Function to start the service (this would make the API call to start it)
|
||||
function startService() {
|
||||
console.log('Starting service...');
|
||||
// You can call an API to start the service here
|
||||
}
|
||||
|
||||
// Function to stop the service (this would make the API call to stop it)
|
||||
function stopService() {
|
||||
console.log('Stopping service...');
|
||||
// You can call an API to stop the service here
|
||||
}
|
||||
19
archive/js_site/index.php
Normal file
19
archive/js_site/index.php
Normal file
@ -0,0 +1,19 @@
|
||||
<!DOCTYPE html>
|
||||
<html lang="en">
|
||||
<head>
|
||||
<meta charset="UTF-8">
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
||||
<title>API Status Button</title>
|
||||
<link rel="stylesheet" href="styles.css">
|
||||
</head>
|
||||
<body>
|
||||
<div id="app">
|
||||
<button id="statusButton" onclick="handleButtonClick()">Loading...</button>
|
||||
</div>
|
||||
<?php
|
||||
$status = file_get_contents("http://172.17.0.1:5000/status");
|
||||
echo $status;
|
||||
?>
|
||||
<script src="app.js"></script>
|
||||
</body>
|
||||
</html>
|
||||
26
archive/js_site/style.css
Normal file
26
archive/js_site/style.css
Normal file
@ -0,0 +1,26 @@
|
||||
body {
|
||||
font-family: Arial, sans-serif;
|
||||
display: flex;
|
||||
justify-content: center;
|
||||
align-items: center;
|
||||
height: 100vh;
|
||||
margin: 0;
|
||||
background-color: #f4f4f9;
|
||||
}
|
||||
|
||||
#app {
|
||||
text-align: center;
|
||||
}
|
||||
|
||||
button {
|
||||
padding: 15px 30px;
|
||||
font-size: 18px;
|
||||
cursor: pointer;
|
||||
border: none;
|
||||
border-radius: 5px;
|
||||
transition: background-color 0.3s ease;
|
||||
}
|
||||
|
||||
button:active {
|
||||
transform: scale(0.98);
|
||||
}
|
||||
59
archive/photo_refresh copy.yaml
Normal file
59
archive/photo_refresh copy.yaml
Normal file
@ -0,0 +1,59 @@
|
||||
---
|
||||
|
||||
|
||||
- name: photo_refresh - set folder variable
|
||||
set_fact:
|
||||
docker_source: "/opt/cosmos/photo_refresh"
|
||||
|
||||
# Create docker Folder
|
||||
- name: photo_refresh - create photo_refresh folder
|
||||
file:
|
||||
path: "{{ docker_source }}"
|
||||
state: directory
|
||||
mode: '0755'
|
||||
owner: timelapse
|
||||
group: timelapse
|
||||
|
||||
|
||||
- name: photo_refresh - copy files for docker container
|
||||
copy:
|
||||
src: "image_refresh_php/"
|
||||
dest: "{{ docker_source }}/"
|
||||
mode: 0755
|
||||
owner: root
|
||||
group: root
|
||||
|
||||
- name: photo_refresh - Build image
|
||||
shell: "docker build -t photo_refresh {{ docker_source }}/."
|
||||
|
||||
# docker_image:
|
||||
# name: photo_refresh # Name of the Docker image
|
||||
# source: build
|
||||
# build:
|
||||
# path: "{{ docker_source }}" # Path to the directory containing your Dockerfile
|
||||
# state: present
|
||||
# tag: latest
|
||||
|
||||
|
||||
###############################################
|
||||
# Start photo_refresh
|
||||
###############################################
|
||||
|
||||
- name: start photo_refresh
|
||||
block:
|
||||
|
||||
- name: photo_refresh - template config
|
||||
template:
|
||||
src: docker-compose-node.yaml.j2
|
||||
dest: "{{ docker_source }}/docker-compose.yaml"
|
||||
mode: 0644
|
||||
|
||||
- name: photo_refresh - Start container at 0.0.0.0:3000
|
||||
shell: "docker-compose -f {{ docker_source }}/docker-compose.yaml up -d"
|
||||
register: local_index_output
|
||||
- debug: |
|
||||
msg="{{ local_index_output.stdout_lines }}"
|
||||
msg="{{ local_index_output.stderr_lines }}"
|
||||
|
||||
|
||||
...
|
||||
63
archive/record_snapshots.sh.j2
Normal file
63
archive/record_snapshots.sh.j2
Normal file
@ -0,0 +1,63 @@
|
||||
#!/bin/bash
|
||||
# this saves a snapshot of the camera every second or so depending on how long all the other crap takes
|
||||
# let's hope the vars make it otherwise imma need to parse a bollocksing file
|
||||
|
||||
i=1
|
||||
while [ -f "$WORKING_DIR/run" ]
|
||||
do
|
||||
FILENAME=$(printf "img-%05d" "$i")
|
||||
LATLON=$(curl -s http://10.18.1.1:8184/where_is?api_key={{ tesla_api_key }} )
|
||||
LON=$(echo $LATLON | jq .lon)
|
||||
LAT=$(echo $LATLON | jq .lat)
|
||||
COORDINATES="$LAT, $LON"
|
||||
curl http://127.0.0.1:7123/snapshot --output $WORKING_DIR/$FILENAME.jpg
|
||||
|
||||
# This variable is for the timestamp
|
||||
TIME=$(date +%c)
|
||||
|
||||
# Save the initial image in a temp file
|
||||
convert $WORKING_DIR/$FILENAME.jpg -gravity SouthWest -pointsize 44 \
|
||||
-fill yellow -annotate +30+30 "$TIME" $WORKING_DIR/$FILENAME-temp1.jpg
|
||||
|
||||
# Add the second annotation to the temp file
|
||||
convert $WORKING_DIR/$FILENAME-temp1.jpg -gravity SouthEast -pointsize 44 \
|
||||
-fill yellow -annotate +30+30 "$COORDINATES" $WORKING_DIR/$FILENAME-temp2.jpg
|
||||
|
||||
# Append the two images and save the final result
|
||||
convert $WORKING_DIR/$FILENAME-temp2.jpg -append $WORKING_DIR/$FILENAME.jpg
|
||||
|
||||
# Optionally, remove intermediate files if you don't need them
|
||||
rm $WORKING_DIR/$FILENAME-temp1.jpg $WORKING_DIR/$FILENAME-temp2.jpg
|
||||
|
||||
|
||||
# this big boi should add both the timestamp and the coordinates
|
||||
#convert $WORKING_DIR/$FILENAME.jpg \( +clone -gravity NorthWest -pointsize 44 -fill yellow -annotate +30+30 "$TIME" $WORKING_DIR/$FILENAME-time.jpg\) \
|
||||
#\( +clone -gravity NorthEast -pointsize 44 -fill yellow -annotate +30+30 "$COORDINATES" $WORKING_DIR/$FILENAME-final.jpg\)
|
||||
#-append $WORKING_DIR/$FILENAME.jpg
|
||||
|
||||
# This should add the current time to the image and save it
|
||||
#convert $WORKING_DIR/$FILENAME.jpg -gravity SouthWest -pointsize 44 \
|
||||
#-fill yellow -annotate +30+30 $TIME $WORKING_DIR/$FILENAME-temp.jpg
|
||||
# Delete original
|
||||
#rm $WORKING_DIR/$FILENAME.jpg
|
||||
|
||||
# This should add the current latlon to the image and save it
|
||||
#convert $WORKING_DIR/$FILENAME-temp.jpg -gravity SouthEast -pointsize 44 \
|
||||
#-fill yellow -annotate +30+30 $COORDINATES $WORKING_DIR/$FILENAME-final.jpg
|
||||
# Delete temp
|
||||
#rm $WORKING_DIR/$FILENAME-temp.jpg
|
||||
|
||||
# This is for the tiny pic
|
||||
# I'll make one every 5 seconds
|
||||
# I have 1340x580. i think i will truncate the top
|
||||
# Calculate the height to trim based on the aspect ratios of the input and output images
|
||||
if (( $i % 5 == 0 )); then
|
||||
NOW=$(date +%Y%m%d%H%M%S)
|
||||
convert $WORKING_DIR/$FILENAME.jpg -gravity North -crop 1920x830+0+260 +repage -resize 1340x580 {{ working_folder }}/small_thumbs/$NOW.jpg
|
||||
fi
|
||||
|
||||
sleep 1
|
||||
|
||||
((i++))
|
||||
|
||||
done
|
||||
Reference in New Issue
Block a user