From 27fa77219c32cfd8bdcefddca5fa4ab8ba157b02 Mon Sep 17 00:00:00 2001 From: agatha Date: Sun, 15 Sep 2024 18:20:50 -0400 Subject: [PATCH] feat: memory filter can be specified in the config --- README.md | 1 + stockbot-buyvm.py | 11 +++++------ 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/README.md b/README.md index 5db0399..49fb51e 100644 --- a/README.md +++ b/README.md @@ -5,6 +5,7 @@ Send alerts when [BuyVM](https://buyvm.net) has KVM slices in stock. 1. Create a JSON configuration file in `config.json`: ```json { + "memory": [512, 1, 2, 4], "matrix": { "homeserver": "https://matrix.juggalol.com", "username": "", diff --git a/stockbot-buyvm.py b/stockbot-buyvm.py index 3b80cb4..c446386 100644 --- a/stockbot-buyvm.py +++ b/stockbot-buyvm.py @@ -59,12 +59,9 @@ def load_config(filename): async def main(): logger.info('checking buyvm stocks') - - # load configuration config = load_config('config.json') - - # initialize bot bot = MatrixBot(config['matrix']) + memory_filter = config.get('memory', [512, 1, 2, 4, 8, 16, 32]) # Defaults to all sizes for url in URLS: html = get_url(url) @@ -74,7 +71,10 @@ async def main(): packages = get_packages(html) for package in packages: - if package['qty'] > 0: + qty = package['qty'] + memory = int(package['name'].split()[-1][:-2]) + + if qty > 0 and (memory in memory_filter): logger.info(f"{package['name']}: {package['qty']} in stock") await bot.send_message(f"{package['name']}: {package['qty']} in stock") @@ -95,7 +95,6 @@ def main_with_shutdown(): loop.run_until_complete(asyncio.gather(*pending_tasks, return_exceptions=True)) loop.run_until_complete(loop.shutdown_asyncgens()) loop.close() - logger.info("Event loop closed.") if __name__ == '__main__':