response.json instead of json.loads
This commit is contained in:
@ -4,7 +4,8 @@ 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(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}
|
||||
|
@ -1,5 +1,4 @@
|
||||
from requests import get, post
|
||||
from json import loads
|
||||
from os import getenv
|
||||
from collections import namedtuple as nt
|
||||
from munch import DefaultMunch
|
||||
@ -13,12 +12,12 @@ headers = {
|
||||
|
||||
response = get(api_url)
|
||||
if response.reason == "OK":
|
||||
dog_fact = DefaultMunch.fromDict(loads(response.text)['data'][0])
|
||||
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: ' + loads(response.text)['uri'])
|
||||
notify(-1, 'dog facts post url: ' + response.json()['uri'])
|
||||
else:
|
||||
notify(1, 'dog facts post error: ' + response.reason)
|
||||
else:
|
||||
|
Reference in New Issue
Block a user