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`:
|
1. Create a JSON configuration file in `config.json`:
|
||||||
```json
|
```json
|
||||||
{
|
{
|
||||||
|
"memory": [512, 1, 2, 4],
|
||||||
"matrix": {
|
"matrix": {
|
||||||
"homeserver": "https://matrix.juggalol.com",
|
"homeserver": "https://matrix.juggalol.com",
|
||||||
"username": "",
|
"username": "",
|
||||||
|
@ -59,12 +59,9 @@ def load_config(filename):
|
|||||||
|
|
||||||
async def main():
|
async def main():
|
||||||
logger.info('checking buyvm stocks')
|
logger.info('checking buyvm stocks')
|
||||||
|
|
||||||
# load configuration
|
|
||||||
config = load_config('config.json')
|
config = load_config('config.json')
|
||||||
|
|
||||||
# initialize bot
|
|
||||||
bot = MatrixBot(config['matrix'])
|
bot = MatrixBot(config['matrix'])
|
||||||
|
memory_filter = config.get('memory', [512, 1, 2, 4, 8, 16, 32]) # Defaults to all sizes
|
||||||
|
|
||||||
for url in URLS:
|
for url in URLS:
|
||||||
html = get_url(url)
|
html = get_url(url)
|
||||||
@ -74,7 +71,10 @@ async def main():
|
|||||||
|
|
||||||
packages = get_packages(html)
|
packages = get_packages(html)
|
||||||
for package in packages:
|
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")
|
logger.info(f"{package['name']}: {package['qty']} in stock")
|
||||||
await bot.send_message(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(asyncio.gather(*pending_tasks, return_exceptions=True))
|
||||||
loop.run_until_complete(loop.shutdown_asyncgens())
|
loop.run_until_complete(loop.shutdown_asyncgens())
|
||||||
loop.close()
|
loop.close()
|
||||||
logger.info("Event loop closed.")
|
|
||||||
|
|
||||||
|
|
||||||
if __name__ == '__main__':
|
if __name__ == '__main__':
|
||||||
|
Loading…
Reference in New Issue
Block a user