discord-guild-notifications/wowprogress.py

40 lines
1.0 KiB
Python
Raw Normal View History

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