Files
bots/dog_facts.py
Camille Frantz 506fa996fd
All checks were successful
ReleaseBot / deploy (push) Successful in 47s
QuipBot / deploy (push) Successful in 17s
DogFacts / deploy (push) Successful in 14s
PuppyBot / deploy (push) Successful in 26s
QuotesBot / deploy (push) Successful in 19s
response.json instead of json.loads
2025-07-24 14:12:48 -05:00

26 lines
874 B
Python

from requests import get, post
from os import getenv
from collections import namedtuple as nt
from munch import DefaultMunch
from globals import *
post_endpoint = f"{bots_endpoint}/api/v1/statuses"
api_url = 'https://dogapi.dog/api/v2/facts'
headers = {
"Authorization": f"Bearer {dogfacts_token}"
}
response = get(api_url)
if response.reason == "OK":
dog_fact = DefaultMunch.fromDict(response.json()['data'][0])
payload = {"status": f"didja know: \n {dog_fact.attributes.body}\n#RandomDogFacts", "visibility": "unlisted"}
response = post(post_endpoint, headers=headers, json=payload)
if response.reason == "OK":
if po_user_token:
notify(-1, 'dog facts post url: ' + response.json()['uri'])
else:
notify(1, 'dog facts post error: ' + response.reason)
else:
if po_user_token:
notify(1, 'dog facts api call failed: ' + response.reason)