add black history code
This commit is contained in:
17
black_history.py
Normal file
17
black_history.py
Normal file
@ -0,0 +1,17 @@
|
|||||||
|
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])
|
||||||
|
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)
|
10
globals.py
10
globals.py
@ -1,5 +1,7 @@
|
|||||||
from os import getenv
|
from os import getenv
|
||||||
from requests import post
|
from requests import post
|
||||||
|
from munch import Munch
|
||||||
|
from json import loads
|
||||||
|
|
||||||
def notify(priority, message):
|
def notify(priority, message):
|
||||||
r = post("https://api.pushover.net/1/messages.json", data = {
|
r = post("https://api.pushover.net/1/messages.json", data = {
|
||||||
@ -28,6 +30,11 @@ quip_file = getenv('QUIP_FILE')
|
|||||||
quip_tags = getenv('QUIP_TAGS')
|
quip_tags = getenv('QUIP_TAGS')
|
||||||
quip_token = getenv('QUIP_TOKEN')
|
quip_token = getenv('QUIP_TOKEN')
|
||||||
|
|
||||||
|
## BlackHistoryFacts
|
||||||
|
# blackhistory_token = getenv('BLACKHISTORY_POST_TOKEN')
|
||||||
|
blackhistory_api = getenv('BLACKHISTORY_API_TOKEN')
|
||||||
|
blackhistory_endpoint = getenv('BLACKHISTORY_API_ENDPOINT')
|
||||||
|
|
||||||
## Quotes file path
|
## Quotes file path
|
||||||
quotes_source = getenv('QUOTES_SOURCE')
|
quotes_source = getenv('QUOTES_SOURCE')
|
||||||
|
|
||||||
@ -62,3 +69,6 @@ do_token = getenv('DO_API_KEY')
|
|||||||
# Wikipedia creds
|
# Wikipedia creds
|
||||||
wikimedia_endpoint = 'https://api.wikimedia.org/feed/v1/wikipedia/en/onthisday/all'
|
wikimedia_endpoint = 'https://api.wikimedia.org/feed/v1/wikipedia/en/onthisday/all'
|
||||||
wikipedia_token = getenv('WIKIPEDIA_ACCESS_TOKEN')
|
wikipedia_token = getenv('WIKIPEDIA_ACCESS_TOKEN')
|
||||||
|
|
||||||
|
# AP API ENDPOINTS
|
||||||
|
endpoints = Munch(loads('{"status": "/api/v1/statuses", "media": "/api/v1/media", "timeline": "/api/v1/timelines/public"}'))
|
||||||
|
Reference in New Issue
Block a user