view.py 923 B

1234567891011121314151617181920212223242526272829
  1. import json
  2. import os
  3. # import requests
  4. # import sys
  5. from dotenv import load_dotenv
  6. from pprint import pprint
  7. base_url = 'https://discordapp.com/api/webhooks/'
  8. def broadcast(this_text):
  9. load_dotenv()
  10. webhooks_json = os.environ["DISCORD_TOKENS"]
  11. webhooks = json.loads(webhooks_json)
  12. for webhook_key in webhooks:
  13. webhook = webhooks[webhook_key]
  14. if 'sent an application' in this_text:
  15. this_text += ' @KnockKnock'
  16. this_json = {'content': this_text}
  17. pprint(this_json)
  18. url = base_url+webhook
  19. print(url)
  20. # response = requests.post(url, json=this_json)
  21. # if response.status_code in [200, 204]:
  22. # print("Webhook executed")
  23. # else:
  24. # print("status code {}: {}".format(response.status_code, response.content.decode("utf-8")))
  25. # if response.status_code == int(429):
  26. # sys.exit(1)