Made the thing
This commit is contained in:
commit
5cfd690c03
6 changed files with 104 additions and 0 deletions
5
README.md
Normal file
5
README.md
Normal file
|
|
@ -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.
|
||||||
30
install.sh
Normal file
30
install.sh
Normal file
|
|
@ -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
|
||||||
35
laserproxy.py
Normal file
35
laserproxy.py
Normal file
|
|
@ -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/<int:num>', 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/<string:code>', methods=['GET'])
|
||||||
|
def event(code):
|
||||||
|
u = EVENT_URL.replace('$eventCode$', code)
|
||||||
|
response = requests.get(u, headers=HEADERS)
|
||||||
|
return response.json()
|
||||||
|
|
||||||
|
app.run(port=2077)
|
||||||
12
laserproxy.service
Normal file
12
laserproxy.service
Normal file
|
|
@ -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
|
||||||
6
laserproxy.sh
Normal file
6
laserproxy.sh
Normal file
|
|
@ -0,0 +1,6 @@
|
||||||
|
#! /bin/bash
|
||||||
|
|
||||||
|
cd /opt/laserproxy || exit
|
||||||
|
source env/bin/activate
|
||||||
|
pip install -r requirements.txt
|
||||||
|
exec python3 laserproxy.py
|
||||||
16
requirements.txt
Normal file
16
requirements.txt
Normal file
|
|
@ -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
|
||||||
Loading…
Add table
Add a link
Reference in a new issue