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

19 lines
910 B
Python

from requests import get, post
from globals import *
from munch import DefaultMunch
bh_hdr = {'x-api-key': blackhistory_api, 'Content-Type': 'application/json'}
# blackhistory_fact = DefaultMunch.fromDict(loads(get(blackhistory_endpoint, headers=bh_hdr).text)['data'][0])
blackhistory_fact = DefaultMunch.fromDict(get(blackhistory_endpoint, headers=bh_hdr).json()['data'][0])
post_text = f"{blackhistory_fact.text}. \n Event Date: {blackhistory_fact.date_of_event}\nSource: {blackhistory_fact.source_references[0].source_url}\n#BlackHistoryFacts"
post_hdr = {'Authorization': 'Bearer ' + botsy_token}
payload = {'status': post_text, 'visibility': 'mutuals_only' }
post_result = post(bots_endpoint + endpoints.status, headers=post_hdr, data=payload)
if post_result.reason == 'OK':
notify(-1, 'BlackHistoryFacts: ' + loads(post_result.text)['url'])
else:
notify(-1, 'Post failed: ' + post_result.reason)