loot.py 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  1. #! /usr/bin/python3
  2. """
  3. Loot notifications
  4. """
  5. import time
  6. import json
  7. import traceback
  8. import os
  9. import redis
  10. import requests
  11. import webhook
  12. import conf
  13. now = time.time()
  14. wh = webhook.Webhook(conf.url_discord_webhook_guild)
  15. r = redis.StrictRedis(host='localhost', charset="utf-8", decode_responses=True, db=1)
  16. bnet_member = "https://{1}.api.battle.net/wow/character/dun%20modr/{0}?fields=feed,items&locale=es_ES&apikey={2}"
  17. # legends database
  18. items = {}
  19. with open(os.path.join(os.path.dirname(os.path.abspath(__file__)), "items_legend.json"), 'r') as f:
  20. js = json.load(f)
  21. for item in js:
  22. items[item["item_id"]] = item
  23. members = r.smembers("bot:members") # i need all guild members
  24. request = requests.Session()
  25. for m in members:
  26. try:
  27. member = request.get(url=bnet_member.format(m, conf.battle_net_region, conf.battle_net_apikey)).json()
  28. if "feed" not in member:
  29. continue
  30. for feed in member["feed"]:
  31. if feed["type"] != "LOOT":
  32. continue
  33. fid = "{}-{}".format(m, feed["itemId"])
  34. if feed["itemId"] in items and r.sadd("bot:legends", fid):
  35. wh.send(":tangerine: **{0}** pilla legendario! **[{1}](<http://es.wowhead.com/item={2}>)**".format(member["name"], items[feed["itemId"]]["name_eses"], feed["itemId"]))
  36. time.sleep(2)
  37. except:
  38. traceback.print_exc()
  39. """
  40. Vamos a generar el archivo items_legend.json
  41. Sacar la lista de legends de aquí: view-source:http://es.wowhead.com/items/quality:5/slot:16:5:8:11:10:1:7:2:3:12:6:9?filter=166;7;0
  42. Buscar: 'var _ = {};' y copiar toda la línea siguiente
  43. Reemplazar: '_\[(\d+)\]=\{' por '\n{"item_id": \1, '
  44. Reemplazar: ';$' por ','
  45. Añadir los [ ... ]
  46. """