From 5cfd690c03d1035448be6068ae291a891a95edfd Mon Sep 17 00:00:00 2001 From: Raktbastr Date: Tue, 30 Dec 2025 12:57:17 -0600 Subject: [PATCH] Made the thing --- README.md | 5 +++++ install.sh | 30 ++++++++++++++++++++++++++++++ laserproxy.py | 35 +++++++++++++++++++++++++++++++++++ laserproxy.service | 12 ++++++++++++ laserproxy.sh | 6 ++++++ requirements.txt | 16 ++++++++++++++++ 6 files changed, 104 insertions(+) create mode 100644 README.md create mode 100644 install.sh create mode 100644 laserproxy.py create mode 100644 laserproxy.service create mode 100644 laserproxy.sh create mode 100644 requirements.txt diff --git a/README.md b/README.md new file mode 100644 index 0000000..9f8410a --- /dev/null +++ b/README.md @@ -0,0 +1,5 @@ +# Laser Proxy + +A thing to simplify using Laser Scouter. Horray! + +It forwards all requests to TBA using the API key provided during install. \ No newline at end of file diff --git a/install.sh b/install.sh new file mode 100644 index 0000000..e318a2a --- /dev/null +++ b/install.sh @@ -0,0 +1,30 @@ +#! /bin/bash + +if [ "$(whoami)" != "root" ]; then + echo Run as sudo! + exit +fi + +echo Please enter your Blue Alliance API key to be used +read -r key +echo "$key" >> key.txt +python3 -m venv env +mkdir /opt/laserproxy +cp ./key.txt /opt/laserproxy +cp ./requirements.txt /opt/laserproxy +cp ./laserproxy.py /opt/laserproxy +cp ./laserproxy.service /opt/laserproxy +cp ./laserproxy.sh /opt/laserproxy +cp -r ./env /opt/laserproxy +chown -R root /opt/laserproxy +chmod -R 755 /opt/laserproxy +ln -sf /opt/laserproxy/laserproxy.sh /usr/bin/ +chown root /usr/bin/laserproxy.sh +chmod 755 /usr/bin/laserproxy.sh +ln -sf /opt/laserproxy/laserproxy.service /etc/systemd/system/ +chown root /etc/systemd/system/laserproxy.service +chmod 755 /etc/systemd/system/laserproxy.service +systemctl enable laserproxy +systemctl start laserproxy +echo All done! +echo To change the API key edit /opt/laserproxy/key.txt diff --git a/laserproxy.py b/laserproxy.py new file mode 100644 index 0000000..97ca42d --- /dev/null +++ b/laserproxy.py @@ -0,0 +1,35 @@ +import socket +import sys +from flask import Flask +import requests +from datetime import datetime + +TEAM_URL = "https://www.thebluealliance.com/api/v3/team/frc$teamNumber$/events/$year$" +EVENT_URL = "https://www.thebluealliance.com/api/v3/event/$eventCode$/teams" +with open('key.txt', 'r') as f: + API_KEY = f.read() +HEADERS = {'X-TBA-Auth-Key': API_KEY.strip()} + +app = Flask(__name__) + +@app.route('/', methods=['GET']) +def home(): + return "hi" + +@app.route('/teamsearch/', methods=['GET']) +def team(num): + u = TEAM_URL.replace('$teamNumber$', str(num)) + if datetime.now().month >= 9: + u = u.replace('$year$', str((datetime.now().year)+1)) + else: + u = u.replace('$year$', str(datetime.now().year)) + response = requests.get(u, headers=HEADERS) + return response.json() + +@app.route('/eventsearch/', methods=['GET']) +def event(code): + u = EVENT_URL.replace('$eventCode$', code) + response = requests.get(u, headers=HEADERS) + return response.json() + +app.run(port=2077) \ No newline at end of file diff --git a/laserproxy.service b/laserproxy.service new file mode 100644 index 0000000..db90db5 --- /dev/null +++ b/laserproxy.service @@ -0,0 +1,12 @@ +[Unit] +Description=Laser Scouter API Proxy +After=network.target + +[Service] +ExecStart=/usr/bin/laserproxy.sh +Type=simple +Restart=always +RestartSec = 5 + +[Install] +WantedBy=multi-user.target \ No newline at end of file diff --git a/laserproxy.sh b/laserproxy.sh new file mode 100644 index 0000000..578dc49 --- /dev/null +++ b/laserproxy.sh @@ -0,0 +1,6 @@ +#! /bin/bash + +cd /opt/laserproxy || exit +source env/bin/activate +pip install -r requirements.txt +exec python3 laserproxy.py \ No newline at end of file diff --git a/requirements.txt b/requirements.txt new file mode 100644 index 0000000..20cfc7b --- /dev/null +++ b/requirements.txt @@ -0,0 +1,16 @@ +aniso8601==10.0.1 +blinker==1.9.0 +certifi==2025.11.12 +charset-normalizer==3.4.4 +click==8.3.1 +Flask==3.1.2 +Flask-RESTful==0.3.10 +idna==3.11 +itsdangerous==2.2.0 +Jinja2==3.1.6 +MarkupSafe==3.0.3 +pytz==2025.2 +requests==2.32.5 +six==1.17.0 +urllib3==2.6.2 +Werkzeug==3.1.4