from requests import get, post from json import loads from os import getenv from collections import namedtuple as nt from munch import DefaultMunch from globals import * def notify(priority, message): r = post("https://api.pushover.net/1/messages.json", data = { "token": po_test_token, "user": po_user_token, "message": "dog facts: " + message, "priority": priority }) post_endpoint = f"{bots_endpoint}/api/v1/statuses" api_url = 'https://dogapi.dog/api/v2/facts' headers = { "Authorization": f"Bearer {botsy_token}" } response = get(api_url) if response.reason == "OK": dog_fact = DefaultMunch.fromDict(loads(response.text)['data'][0]) payload = {"status": f"didja know: \n {dog_fact.attributes.body}\n#RandomDogFacts", "visibility": "mutuals_only"} response = post(post_endpoint, headers=headers, json=payload) if response.reason == "OK": notify(-1, loads(response.text)['uri']) else: notify(1, response.reason)