raiderio.py 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  1. #! /usr/bin/python3
  2. """
  3. Raider.IO progress
  4. """
  5. import redis
  6. import requests
  7. import webhook
  8. import conf
  9. # Every wednesday 9am
  10. # 0 9 * * 3 timeout 58 /mnt/raid10/cron/raiderio.py >> /var/log/crons/raiderio.log 2>&1
  11. wh = webhook.Webhook(conf.url_discord_webhook_guild)
  12. r = redis.StrictRedis(host='localhost', charset="utf-8", decode_responses=True, db=1)
  13. rio_api = "https://raider.io/api/v1/guilds/profile?region=eu&realm=dun%20modr&name=mirrors&fields=raid_progression%2Craid_rankings"
  14. slug = "antorus-the-burning-throne"
  15. api = requests.get(url=rio_api).json()
  16. if api is not None and "raid_rankings" in api and "raid_progression" and slug in api["raid_rankings"]:
  17. prev_rank = r.get("bot:raiderio")
  18. rank = api["raid_rankings"][slug]["mythic"]["realm"]
  19. progress = api["raid_progression"][slug]["summary"]
  20. msg = None
  21. if prev_rank is None:
  22. msg = ":arrow_right: La guild entra en el ranking de Dun Modr: #**{0}**, {1}".format(rank, progress)
  23. elif int(prev_rank) > int(rank):
  24. msg = ":arrow_up: La guild sube en el ranking de Dun Modr: #**{0}** (+{1}), {2}".format(rank, int(prev_rank)-int(rank), progress)
  25. elif int(prev_rank) < int(rank):
  26. msg = ":arrow_down: La guild baja en el ranking de Dun Modr: #**{0}** (-{1}), {2}".format(rank, int(rank)-int(prev_rank), progress)
  27. elif int(prev_rank) == int(rank):
  28. msg = ":ok_hand: La guild se mantiene en el ranking de Dun Modr: #**{0}**, {1}".format(rank, progress)
  29. r.set("bot:raiderio", rank)
  30. if msg:
  31. msg += " - [Raider.IO](<https://raider.io/guilds/eu/dun-modr/Mirrors>) - [WoWProgress](<https://www.wowprogress.com/guild/eu/dun-modr/Mirrors>)"
  32. wh.send(msg)