Files
bots/dog_facts.py

39 lines
1.1 KiB
Python
Raw Normal View History

2025-06-08 13:59:58 -05:00
from requests import get, post
from json import loads
from os import getenv
from collections import namedtuple as nt
2025-06-08 14:22:24 -05:00
from munch import DefaultMunch
2025-06-08 13:59:58 -05:00
from globals import *
def notify(priority, message):
r = post("https://api.pushover.net/1/messages.json", data = {
2025-06-08 14:23:02 -05:00
"token": po_test_token,
2025-06-08 13:59:58 -05:00
"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 = {
2025-06-08 14:22:24 -05:00
"Authorization": f"Bearer {botsy_token}"
2025-06-08 13:59:58 -05:00
}
2025-06-08 14:45:57 -05:00
print(botsy_token)
print(api_url)
print(po_user_token, po_test_token)
2025-06-08 13:59:58 -05:00
response = get(api_url)
if response.reason == "OK":
2025-06-08 14:45:57 -05:00
print(dog_fact)
2025-06-08 14:22:24 -05:00
dog_fact = DefaultMunch.fromDict(loads(response.text)['data'][0])
payload = {"status": f"didja know: \n {dog_fact.attributes.body}\n#RandomDogFacts", "visibility": "mutuals_only"}
2025-06-08 13:59:58 -05:00
response = post(post_endpoint, headers=headers, json=payload)
if response.reason == "OK":
notify(-1, loads(response.text)['uri'])
else:
notify(1, response.reason)
2025-06-08 14:44:07 -05:00
else:
notify(1, response.reason)