import os import sys from pprint import pprint import json from dotenv import load_dotenv import roman import requests def send_message(status): base_url = 'https://discordapp.com/api/webhooks/' load_dotenv() webhooks_json = os.environ["DISCORD_TOKENS"] webhooks = json.loads(webhooks_json) name = status['name'] its_id = status['id'] status_text = f"[{name} \[{its_id}\]](https://www.torn.com/profiles.php?XID={its_id}) → Loot level changed to "+roman.toRoman(status['integer']) status_text += "\n" + status['time_string'] this_json = {'content': status_text} pprint(this_json) for webhook in webhooks: url = base_url+webhook response = requests.post(url, json=this_json) if response.status_code in [200, 204]: print("Webhook executed") else: print("status code {}: {}".format(response.status_code, response.content.decode("utf-8"))) if response.status_code == int(429): sys.exit(1) def send_alert(this_alert): base_url = 'https://discordapp.com/api/webhooks/' load_dotenv() webhooks_json = os.environ["DISCORD_TOKENS"] webhooks = json.loads(webhooks_json) this_json = {'content': this_alert} for webhook in webhooks: url = base_url+webhook response = requests.post(url, json=this_json) if response.status_code in [200, 204]: print("Webhook executed") else: print("status code {}: {}".format(response.status_code, response.content.decode("utf-8"))) if response.status_code == int(429): sys.exit(1)