From c346f5292fc3090bd3ea7448e5e904c26972b007 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Sergio=20=C3=81lvarez?= Date: Wed, 13 Dec 2017 10:59:32 +0100 Subject: [PATCH] raider io progress --- raiderio.py | 44 ++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 44 insertions(+) create mode 100644 raiderio.py diff --git a/raiderio.py b/raiderio.py new file mode 100644 index 0000000..820a1f4 --- /dev/null +++ b/raiderio.py @@ -0,0 +1,44 @@ +#! /usr/bin/python3 + +import redis +import time +import requests +import webhook +import conf + +# 0 9 * * 3 timeout 58 /mnt/raid10/cron/raiderio.py >> /var/log/crons/raiderio.log 2>&1 + +wh = webhook.Webhook(conf.url_discord_webhook_guild) + +r = redis.StrictRedis(host='localhost', charset="utf-8", decode_responses=True, db=1) + +rio_api = "https://raider.io/api/v1/guilds/profile?region=eu&realm=dun%20modr&name=mirrors&fields=raid_progression%2Craid_rankings" +slug = "antorus-the-burning-throne" + +api = requests.get(url=rio_api).json() + +if api is not None and "raid_rankings" in api and "raid_progression" and slug in api["raid_rankings"]: + prev_rank = r.get("bot:raiderio") + + rank = api["raid_rankings"][slug]["mythic"]["realm"] + progress = api["raid_progression"][slug]["summary"] + msg = None + + if prev_rank is None: + msg = ":arrow_right: La guild entra en el ranking de Dun Modr: #**{0}**, {1}".format(rank, progress) + + elif int(prev_rank) > int(rank): + msg = ":arrow_up: La guild sube en el ranking de Dun Modr: #**{0}** (+{1}), {2}".format(rank, int(prev_rank)-int(rank), progress) + + elif int(prev_rank) < int(rank): + msg = ":arrow_down: La guild baja en el ranking de Dun Modr: #**{0}** (-{1}), {2}".format(rank, int(rank)-int(prev_rank), progress) + + elif int(prev_rank) == int(rank): + msg = ":ok_hand: La guild se mantiene en el ranking de Dun Modr: #**{0}**, {1}".format(rank, progress) + + r.set("bot:raiderio", rank) + + if msg: + msg += " - [Raider.IO]() - [WoWProgress]()" + wh.send(msg) + time.sleep(2)