From e46fc4505a8d6a096a721369f46b8acfb188b3bb Mon Sep 17 00:00:00 2001 From: Eric Davis Date: Sat, 26 Oct 2024 21:40:38 -0700 Subject: [PATCH] feat: drop plc-activity.py --- plc-activity.py | 46 ---------------------------------------------- 1 file changed, 46 deletions(-) delete mode 100755 plc-activity.py diff --git a/plc-activity.py b/plc-activity.py deleted file mode 100755 index f3c97d6..0000000 --- a/plc-activity.py +++ /dev/null @@ -1,46 +0,0 @@ -#!/usr/bin/env python3 - -from datetime import datetime, timezone -import sys -import json -import redis -import requests -import time - -PLC_EXPORT_URL = 'https://plc.directory/export' - -cids = [] -redis_conn = redis.Redis() -redis_pipe = redis_conn.pipeline() - -while True: - plc_latest = redis_conn.get('dev.edavis.muninsky.plc_latest') - assert plc_latest is not None, 'manually set the `plc_latest` redis key first' - ts = datetime.fromisoformat(plc_latest.decode()) - ts = ts.isoformat('T', 'milliseconds').replace('+00:00', 'Z') - - qs = '?after={ts}'.format(ts=ts) - - print(f'Requesting {PLC_EXPORT_URL}{qs}', end=' ') - resp = requests.get(PLC_EXPORT_URL + qs) - resp.raise_for_status() - - ops = 0 - after = datetime.now(timezone.utc) - for line in resp.iter_lines(): - doc = json.loads(line) - after = datetime.strptime(doc['createdAt'], '%Y-%m-%dT%H:%M:%S.%fZ').replace(tzinfo=timezone.utc) - if doc['cid'] in cids: - continue - cids.insert(0, doc['cid']) - redis_pipe.incr('dev.edavis.muninsky.plc_ops') - ops += 1 - - print(f'Fetched {ops} operations') - sys.stdout.flush() - cids = cids[:25] - - redis_pipe.set('dev.edavis.muninsky.plc_latest', after.isoformat()) - redis_pipe.execute() - - time.sleep(5) -- 2.51.2