warcraftlogs.py 980 B

12345678910111213141516171819202122232425262728293031323334353637
  1. #! /usr/bin/python3
  2. """
  3. WarcrafLogs notifications
  4. """
  5. import time
  6. import sys
  7. import redis
  8. import requests
  9. import webhook
  10. import conf
  11. now = time.time()
  12. wh = webhook.Webhook(conf.url_discord_webhook_guild)
  13. r = redis.StrictRedis(host='localhost', charset="utf-8", decode_responses=True, db=1)
  14. r.zremrangebyscore("bot:warcraftlogs", "-inf", now-(60*60*24*30*12)) # 12 meses
  15. wl_api = "https://www.warcraftlogs.com/v1/reports/guild/mirrors/dun-modr/eu?api_key={0}".format(conf.warcraftlogs_token)
  16. wl = requests.get(url=wl_api).json()
  17. if "error" in wl:
  18. print(wl)
  19. sys.exit()
  20. for report in wl:
  21. if report["start"]/1000 < now-(60*60*24*7): # oooold, 7 day only
  22. continue
  23. if not r.zadd("bot:warcraftlogs", now, report["id"]):
  24. continue
  25. url = "https://www.warcraftlogs.com/reports/{0}".format(report["id"])
  26. wh.send("{3} Logs! **[{2}](<{1}>)** por **{0}**".format(report["owner"], url, report["title"], conf.icon_warcraftlogs))
  27. time.sleep(2)