discord-guild-notifications/warcraftlogs.py

30 lines
873 B
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_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/farm%20and%20furious/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()
for report in wl:
if report["start"]/1000 < now-(60*60*24*7): # oooold, 7 day only
continue
if not r.zadd("bot:warcraftlogs", now, report["id"]):
continue
url = "https://www.warcraftlogs.com/reports/{0}".format(report["id"])
2017-07-25 07:21:48 +00:00
wh.send("{3} Logs! **[{2}](<{1}>)** por **{0}**".format(report["owner"], url, report["title"], conf.icon_warcraftlogs))
time.sleep(2)