feat: memory filter can be specified in the config

This commit is contained in:
agatha 2024-09-15 18:20:50 -04:00
parent 93146294d8
commit 27fa77219c
2 changed files with 6 additions and 6 deletions

View File

@ -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": "",

View File

@ -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__':