discord-guild-notifications/warcraftlogs.py

38 lines
980 B
Python
Raw Normal View History

2017-07-10 08:58:51 +00:00
#! /usr/bin/python3
2017-12-13 11:37:31 +00:00
"""
WarcrafLogs notifications
"""
2017-07-10 08:58:51 +00:00
import time
2017-12-13 11:37:31 +00:00
import sys
import redis
2017-07-10 08:58:51 +00:00
import requests
import webhook
import conf
now = time.time()
wh = webhook.Webhook(conf.url_discord_webhook_guild)
2017-07-10 08:58:51 +00:00
r = redis.StrictRedis(host='localhost', charset="utf-8", decode_responses=True, db=1)
2017-07-10 08:58:51 +00:00
r.zremrangebyscore("bot:warcraftlogs", "-inf", now-(60*60*24*30*12)) # 12 meses
wl_api = "https://www.warcraftlogs.com/v1/reports/guild/mirrors/dun-modr/eu?api_key={0}".format(conf.warcraftlogs_token)
2017-07-10 08:58:51 +00:00
wl = requests.get(url=wl_api).json()
if "error" in wl:
2017-12-13 11:37:31 +00:00
print(wl)
sys.exit()
2017-07-10 08:58:51 +00:00
for report in wl:
2017-12-13 11:37:31 +00:00
if report["start"]/1000 < now-(60*60*24*7): # oooold, 7 day only
continue
2017-07-10 08:58:51 +00:00
2017-12-13 11:37:31 +00:00
if not r.zadd("bot:warcraftlogs", now, report["id"]):
continue
2017-07-10 08:58:51 +00:00
2017-12-13 11:37:31 +00:00
url = "https://www.warcraftlogs.com/reports/{0}".format(report["id"])
wh.send("{3} Logs! **[{2}](<{1}>)** por **{0}**".format(report["owner"], url, report["title"], conf.icon_warcraftlogs))
time.sleep(2)