2017-07-10 08:58:51 +00:00
|
|
|
#! /usr/bin/python3
|
|
|
|
|
|
|
|
import redis
|
|
|
|
import requests
|
|
|
|
import webhook
|
|
|
|
import conf
|
|
|
|
|
|
|
|
now = time.time()
|
|
|
|
|
2017-08-31 15:21:23 +00:00
|
|
|
wh = webhook.Webhook(conf.url_discord_webhook_guild)
|
2017-07-10 08:58:51 +00:00
|
|
|
|
2017-08-31 15:21:23 +00:00
|
|
|
r = redis.StrictRedis(host='localhost', charset="utf-8", decode_responses=True, db=1)
|
2017-07-10 08:58:51 +00:00
|
|
|
|
2017-12-12 12:54:43 +00:00
|
|
|
wp_api = "http://www.wowprogress.com/guild/eu/dun-modr/Mirrors/json_rank"
|
2017-07-10 08:58:51 +00:00
|
|
|
|
|
|
|
rank = requests.get(url=wp_api).json()
|
|
|
|
|
|
|
|
if rank is not None and "realm_rank" in rank:
|
2017-12-13 11:37:31 +00:00
|
|
|
last = r.get("bot:wowprogress")
|
|
|
|
realm = rank["realm_rank"]
|
|
|
|
msg = None
|
2017-07-10 08:58:51 +00:00
|
|
|
|
2017-12-13 11:37:31 +00:00
|
|
|
if last is None:
|
|
|
|
msg = ":arrow_right: La guild entra en el ranking de Dun Modr: **{0}**".format(realm)
|
2017-07-10 08:58:51 +00:00
|
|
|
|
2017-12-13 11:37:31 +00:00
|
|
|
elif int(last) > int(rank["realm_rank"]):
|
|
|
|
msg = ":arrow_up: La guild sube en el ranking de Dun Modr: **{0}** (+{1})".format(realm, int(last)-int(realm))
|
2017-07-10 08:58:51 +00:00
|
|
|
|
2017-12-13 11:37:31 +00:00
|
|
|
elif int(last) < int(realm):
|
|
|
|
msg = ":arrow_down: La guild baja en el ranking de Dun Modr: **{0}** (-{1})".format(realm, int(realm)-int(last))
|
2017-07-10 08:58:51 +00:00
|
|
|
|
2017-12-13 11:37:31 +00:00
|
|
|
elif int(last) == int(realm):
|
|
|
|
msg = ":ok_hand: La guild se mantiene en el ranking de Dun Modr: **{0}**".format(realm)
|
2017-07-12 14:06:10 +00:00
|
|
|
|
2017-12-13 11:37:31 +00:00
|
|
|
r.set("bot:wowprogress", realm)
|
2017-07-10 08:58:51 +00:00
|
|
|
|
2017-12-13 11:37:31 +00:00
|
|
|
if msg:
|
|
|
|
wh.send(msg)
|