minor fix
This commit is contained in:
52
index.html
52
index.html
@@ -129,27 +129,21 @@
|
||||
</form>
|
||||
|
||||
<script type="text/javascript">
|
||||
const $ = (selectors, fn) => {
|
||||
let e = document.querySelector(selectors);
|
||||
return fn && e ? fn(e) : e;
|
||||
const $ = (selectors) => {
|
||||
return document.querySelector(selectors);
|
||||
};
|
||||
|
||||
const $$ = (selectors, fn) => {
|
||||
let e = document.querySelectorAll(selectors);
|
||||
return fn && e ? fn(e) : e;
|
||||
const $$ = (selectors) => {
|
||||
return document.querySelectorAll(selectors);
|
||||
};
|
||||
|
||||
const $$$ = (selectors, event, listener) => {
|
||||
$(selectors).addEventListener(event, listener);
|
||||
};
|
||||
|
||||
let Profiles = new Array();
|
||||
let Latest = null;
|
||||
let Status = null;
|
||||
|
||||
function main(profiles, args) {
|
||||
function main(profiles, args, status=null, error=null) {
|
||||
$$$('#begin', 'click', async () => {
|
||||
switch (Status) {
|
||||
switch (status) {
|
||||
case 'READY':
|
||||
let name = $('#name').value;
|
||||
let options = { profile: name };
|
||||
@@ -177,19 +171,19 @@ function main(profiles, args) {
|
||||
}
|
||||
});
|
||||
|
||||
$$$('#begin', 'click', (e) => {
|
||||
$$$('#begin', 'click', () => {
|
||||
$('#begin > span.icon').removeAttribute('hidden');
|
||||
$('#begin > span.text').innerText = '';
|
||||
$('#begin').classList.remove('pulse');
|
||||
$('#begin').disabled = true;
|
||||
});
|
||||
|
||||
$$$('#cancel', 'click', async (e) => {
|
||||
$$$('#cancel', 'click', async () => {
|
||||
$('#cancel').disabled = true;
|
||||
await Rpc2.invoke('cancel');
|
||||
});
|
||||
|
||||
$$$('#skip', 'click', async (e) => {
|
||||
$$$('#skip', 'click', async () => {
|
||||
$('#skip').disabled = true;
|
||||
await Rpcs.invoke('skip');
|
||||
});
|
||||
@@ -200,16 +194,15 @@ function main(profiles, args) {
|
||||
});
|
||||
|
||||
$$$('#name', 'change', (e) => {
|
||||
let p = Profiles.find(o => o.name === e.target.value);
|
||||
for (let k of Object.keys(p)) $(`#${k}`, e => e.value = p[k] ?? '');
|
||||
let p = profiles.find(o => o.name === e.target.value);
|
||||
for (let k of Object.keys(p)) $(`#${k}`)?.setAttribute('value', p[k] ?? '');
|
||||
});
|
||||
|
||||
$$$('#all', 'change', (e) => {
|
||||
$('#name').disabled = e.target.checked;
|
||||
});
|
||||
|
||||
for (let item of JSON.parse(profiles)) {
|
||||
Profiles.push(item);
|
||||
for (let item of profiles) {
|
||||
$('#name').add(new Option(item.name, item.name));
|
||||
$('#name').dispatchEvent(new Event('change'));
|
||||
}
|
||||
@@ -236,17 +229,17 @@ function main(profiles, args) {
|
||||
let logs = Array.from(history);
|
||||
|
||||
for (let record of logs) {
|
||||
if (record.levelno >= 40) Latest = record;
|
||||
if (record.levelno >= 40) error = record;
|
||||
let message = LogRecord.format(record);
|
||||
let node = document.createTextNode(new String(message).concat('\n'));
|
||||
$('#messages').appendChild(node);
|
||||
$('#messages').scrollTop = $('#messages').scrollHeight;
|
||||
}
|
||||
|
||||
Status = await Rpc2.invoke('status');
|
||||
$('#statusLabel').innerText = Status.charAt(0).toUpperCase() + Status.slice(1).toLowerCase();
|
||||
status = await Rpc2.invoke('status');
|
||||
$('#statusLabel').innerText = status.charAt(0).toUpperCase() + status.slice(1).toLowerCase();
|
||||
|
||||
switch (Status) {
|
||||
switch (status) {
|
||||
case 'IDLE':
|
||||
return;
|
||||
case 'READY':
|
||||
@@ -267,16 +260,13 @@ function main(profiles, args) {
|
||||
let [t1, t2] = await Rpc2.invoke('uptime').catch(() => []);
|
||||
$('#uptimeLabel').innerText = Temporal.Duration.from({ seconds: t1 ?? 0 }).round({ largestUnit: 'hours' }).toLocaleString('en', { style: 'digital' });
|
||||
|
||||
if (index && limit && t2) {
|
||||
let rate = index / t2;
|
||||
let remaining = Math.floor((limit - index) / rate);
|
||||
$('#remainingLabel').innerHTML = Temporal.Duration.from({ seconds: remaining }).round({ largestUnit: 'hours' }).toLocaleString('en');
|
||||
}
|
||||
let remaining = index && limit && t2 ? Math.floor((limit - index) / (index / t2)) : 0;
|
||||
$('#remainingLabel').innerHTML = remaining ? Temporal.Duration.from({ seconds: remaining }).round({ largestUnit: 'hours' }).toLocaleString('en') : '';
|
||||
break;
|
||||
case 'STANDBY':
|
||||
if (Latest !== null) {
|
||||
alert(`(${Latest.levelname}) ${Latest.msg}\n${Latest.exc_text ?? ''}`);
|
||||
Latest = null;
|
||||
if (error !== null) {
|
||||
alert(`(${error.levelname}) ${error.msg}\n${error.exc_text ?? ''}`);
|
||||
error = null;
|
||||
}
|
||||
$('#begin > span.text').innerText = 'Resume';
|
||||
$('#begin').classList.remove('pulse');
|
||||
|
||||
44
main.py
44
main.py
@@ -63,11 +63,10 @@ def main(driver: WebDriver, logger = logging.getLogger('main')):
|
||||
t1 = Timer()
|
||||
t2 = Timer()
|
||||
options = dict()
|
||||
profiles: list[Profile] = list()
|
||||
status = Status.IDLE
|
||||
|
||||
def begin(opts: dict, args: dict):
|
||||
nonlocal options, status
|
||||
nonlocal status
|
||||
options.update(opts)
|
||||
status = Status.RUNNING
|
||||
parameters.update(args)
|
||||
@@ -94,20 +93,17 @@ def main(driver: WebDriver, logger = logging.getLogger('main')):
|
||||
jsonrpc2.define('uptime', lambda: [t1.delta()])
|
||||
|
||||
try:
|
||||
for source, profile in zip(parameters.get('profile'), repeat(dict())):
|
||||
for key, value in map(lambda o: str.split(o, '=', 2), source):
|
||||
profile[key.lower().strip()] = value.strip()
|
||||
|
||||
item = Profile(**profile)
|
||||
profiles.append(item)
|
||||
profiles = [
|
||||
Profile(**{ k.lower().strip(): v.strip() for k, v in map(lambda o: str.split(o, '=', 2), p) })
|
||||
for p in parameters.get('profile')
|
||||
]
|
||||
except Exception as e:
|
||||
logger.critical('Unable to load profiles', exc_info=e)
|
||||
return 2
|
||||
|
||||
try:
|
||||
manifest = json.dumps(profiles, default=vars)
|
||||
driver.get(str(Path('index.html').resolve()))
|
||||
driver.execute_script(jsonrpc2.prelude(), manifest, parameters)
|
||||
driver.execute_script(jsonrpc2.prelude(), list(map(vars, profiles)), parameters)
|
||||
except Exception as e:
|
||||
logger.critical('Unable to load starup page', exc_info=e)
|
||||
return 3
|
||||
@@ -234,7 +230,7 @@ def main(driver: WebDriver, logger = logging.getLogger('main')):
|
||||
@classmethod
|
||||
def perform(cls):
|
||||
nonlocal status
|
||||
statis = Status.READY
|
||||
status = Status.READY
|
||||
driver.switch_to.window(driver.window_handles[0])
|
||||
raise cls
|
||||
|
||||
@@ -380,13 +376,29 @@ def main(driver: WebDriver, logger = logging.getLogger('main')):
|
||||
progress['number'] = number
|
||||
progress['index'] = i-1
|
||||
|
||||
if (id := item['category_id']) not in categories:
|
||||
if (x := item['category_id']) not in categories:
|
||||
flow.react()
|
||||
categories[id] = fetch(f'{base}/categories/{id}.json?api_token={profile.token}')
|
||||
response = fetch(f'{base}/categories/{x}.json?api_token={profile.token}')
|
||||
|
||||
if (id := item['client_id']) not in clients:
|
||||
if 'error' in response:
|
||||
error = response['error']
|
||||
code = response['code']
|
||||
logger.warning("Error while fetching 'category' (code: %s, message: %s); skipping", code, error)
|
||||
continue
|
||||
else:
|
||||
categories[x] = response
|
||||
|
||||
if (x := item['client_id']) not in clients:
|
||||
flow.react()
|
||||
clients[id] = fetch(f'{base}/clients/{id}.json?api_token={profile.token}')
|
||||
response = fetch(f'{base}/clients/{x}.json?api_token={profile.token}')
|
||||
|
||||
if 'error' in response:
|
||||
error = response['error']
|
||||
code = response['code']
|
||||
logger.warning("Error while fetching 'client' (code: %s, message: %s); skipping", code, error)
|
||||
continue
|
||||
else:
|
||||
clients[x] = response
|
||||
|
||||
category = categories.get(item['category_id'])
|
||||
client = clients.get(item['client_id'])
|
||||
@@ -535,6 +547,7 @@ def main(driver: WebDriver, logger = logging.getLogger('main')):
|
||||
|
||||
while index < len(data):
|
||||
try:
|
||||
attempts += 1
|
||||
driver.switch_to.window(driver.window_handles[2])
|
||||
item = data[index]
|
||||
kind = item['kind']
|
||||
@@ -542,7 +555,6 @@ def main(driver: WebDriver, logger = logging.getLogger('main')):
|
||||
number = profile.format(item['number'])
|
||||
positions = item['positions']
|
||||
opportunity = None
|
||||
attempts += 1
|
||||
|
||||
if kind != 'vat':
|
||||
logger.info('[%d/%d] Skipping %s', index+1, len(data), number)
|
||||
|
||||
Reference in New Issue
Block a user