wowprogress.py 1.1 KB

1234567891011121314151617181920212223242526272829303132333435363738
  1. #! /usr/bin/python3
  2. import redis
  3. import requests
  4. import webhook
  5. import conf
  6. now = time.time()
  7. wh = webhook.Webhook(conf.url_discord_webhook_guild)
  8. r = redis.StrictRedis(host='localhost', charset="utf-8", decode_responses=True, db=1)
  9. wp_api = "http://www.wowprogress.com/guild/eu/dun-modr/Mirrors/json_rank"
  10. rank = requests.get(url=wp_api).json()
  11. if rank is not None and "realm_rank" in rank:
  12. last = r.get("bot:wowprogress")
  13. realm = rank["realm_rank"]
  14. msg = None
  15. if last is None:
  16. msg = ":arrow_right: La guild entra en el ranking de Dun Modr: **{0}**".format(realm)
  17. elif int(last) > int(rank["realm_rank"]):
  18. msg = ":arrow_up: La guild sube en el ranking de Dun Modr: **{0}** (+{1})".format(realm, int(last)-int(realm))
  19. elif int(last) < int(realm):
  20. msg = ":arrow_down: La guild baja en el ranking de Dun Modr: **{0}** (-{1})".format(realm, int(realm)-int(last))
  21. elif int(last) == int(realm):
  22. msg = ":ok_hand: La guild se mantiene en el ranking de Dun Modr: **{0}**".format(realm)
  23. r.set("bot:wowprogress", realm)
  24. if msg:
  25. wh.send(msg)