mirror of
https://git.juggalol.com/agatha/stockbot-buyvm.git
synced 2024-11-16 20:56:40 +00:00
feat: memory filter can be specified in the config
This commit is contained in:
parent
93146294d8
commit
27fa77219c
@ -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": "",
|
||||
|
@ -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__':
|
||||
|
Loading…
Reference in New Issue
Block a user