Skip to content

Commit

Permalink
Changed auth method
Browse files Browse the repository at this point in the history
Single auth made to /login, and existing sid used until script is killed.
  • Loading branch information
itsmebcc authored Oct 11, 2023
1 parent 639b3c5 commit 3e29684
Showing 1 changed file with 24 additions and 4 deletions.
28 changes: 24 additions & 4 deletions backend.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
import requests
import base64
from getpass import getpass
import time # <-- Added for timing

app = Flask(__name__)

Expand All @@ -19,7 +20,18 @@
PASSWORD = getpass("Enter your password: ")
ENCODED_PASSWORD = base64.b64encode(PASSWORD.encode()).decode()

sid = None
DEBUG_MODE = True

def login():
global sid
if sid:
if DEBUG_MODE:
print("[DEBUG] Using existing SID:", sid)
return sid

if DEBUG_MODE:
print("[DEBUG] Logging in to retrieve a new SID...")
payload = {
"version": "1.0",
"sid": "00000000000000000000000000000000",
Expand All @@ -32,21 +44,24 @@ def login():
}
response = requests.post(BASE_URL, headers=HEADERS, json=payload)
data = response.json()
return data.get('result', {}).get('sid')
sid = data.get('result', {}).get('sid')
return sid

@app.route('/')
def index():
return render_template('index.html')

@app.route('/data', methods=['GET'])
def get_signal_data():
sid = login()
if not sid:
start_time = time.time() # <-- Record start time

sid_value = login()
if not sid_value:
return jsonify({"error": "Failed to log in."}), 500

data = {
"version": "1.0",
"sid": sid,
"sid": sid_value,
"mid": 0,
"module": "lte",
"api": "at_cmd",
Expand All @@ -68,6 +83,11 @@ def get_signal_data():
if "\"NR5G-NSA\"," in line:
nr5g_data = line.split(",")

# Calculate and print the elapsed time
elapsed_time = time.time() - start_time
if DEBUG_MODE:
print(f"[DEBUG] Request took {elapsed_time:.4f} seconds")

return jsonify({
"LTE": {
"rsrp": int(lte_data[11]) if lte_data else None,
Expand Down

0 comments on commit 3e29684

Please sign in to comment.