Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
help clarify web / mobile API
#3
Thanks, but I didn't find that sufficient for my use case. I'd really prefer there was a way to programmatically get the log from SIP.

I didn't want to mess with your code, don't want to complicate the process of upgrading to a new version of SIP. So I wrote a little app which runs alongside and exposes the log via scraping SIP's webpage. In case this is helpful to anyone else...

Code:
import requests
from bs4 import BeautifulSoup
from datetime import datetime
from flask import Flask
import json

SIP_SERVER = "http://10.0.0.128"

def get_log_from_SIP():
    resp = requests.get(SIP_SERVER + "/vl")
    soup = BeautifulSoup(resp.text, features="html.parser")
    return soup.find(id="log")

def get_days_since_last_SIP_run():
    try:
        log = get_log_from_SIP()
        sip_last_run = log.table.tbody.td.text
    except:
        return -1

    return (datetime.now() - datetime.fromisoformat(sip_last_run)).days


app = Flask(__name__)

@app.route('/log')
def log():
    try:
        log = get_log_from_SIP()
        headers = log.table.thead.tr.find_all("th")
        keys = [h.string.replace(' ', '_') for h in headers]
        rows = log.table.tbody.find_all("tr")
    except:
        return "[]"

    result = []
    for row in rows:
        cols = row.find_all("td")
        result.append({keys[i]:cols[i].string for i in range(len(cols))})
    return json.dumps(result)

@app.route('/lastrun')
def last_run():
    return json.dumps(get_days_since_last_SIP_run())
Reply


Messages In This Thread
help clarify web / mobile API - by msambol - 2023 Jun 30, 01:33 PM
RE: help clarify web / mobile API - by dan - 2023 Jun 30, 05:51 PM
RE: help clarify web / mobile API - by msambol - 2023 Jul 07, 12:17 PM
RE: help clarify web / mobile API - by astrogerard - 2023 Jul 07, 06:59 PM

Forum Jump:


Users browsing this thread: 1 Guest(s)