HubDB API along with the Blog Posts API to batch create/publish 152 blog entries
lösung
Hi all. Im looking for some advice on using the HubDB API along with the Blog Posts API to create/publish a batch of 152 blog posts. I have a HubDB set up with all of the data. The same HubDB also is being used by a custom module to render an embargoed preview of the blog posts. Each row in the HubDB contains all of the content for a blog post. There are 152 rows of data in the DB, one for each post. I am able to publish a single post and receive a 201 status, but then receive a TypeError that breaks the function from completing more than one blog entry/row. I have included the error from Terminal at the end. Unfortunately I do not understand how to solve the error. I have been trying to debug and look up errors, but seem to be stuck in a negative feedback loop. Any advice appreciated. I am open to new approaches as well.
Traceback (most recent call last):
File "get_tables.py", line 71, in <module>
get_single_row(MEOS_Q1_2019)
File "get_tables.py", line 34, in get_single_row
blog_author_id = value[i]["values"]["2"]
TypeError: 'int' object is not subscriptable
My HubDB has 20 columns of data and 152 rows. But when I try to return the JSON object with key, value pairs I only receive 12. Any thoughts on how to access the full HubDB? I am loading my JSON then printing the key, value of items.
for key, value in table_data.items():
print(value[i]["values"])
Response:
{
'objects':[
{
'id':6657630003,
'createdAt':1543515074733,
'path':None,
'name':None,
'values':{
'18':'1 Dec 2018 | Positive Job Market Expected in Final Quarter of 2018 for Alabama',
'2':'5521284303',
'19':'5684804132',
'3':'71df6020-8385-4e2e-9a36-23e708fa4605',
'20':'5634648902',
'4':'MEOS NA',
'21':'5634648855',
'5':'5664168304',
'22':'5634522727',
'6':'https://go.manpowergroup.com/hubfs/MEOS/2019_Q1/MEOS_Q1_2019_Infographic.png',
'10':"<embed src='https://drive.google.com/viewerng/viewer?embedded=true&url=https://go.manpowergroup.com/hubfs/MEOS/2018_Q4/Hopeful%20Job%20Market%20Expected%20in%20Final%20Quarter%20of%202018%20for%20Milwaukee-Waukesha-West%20Allis,%20WI%20MSA.pdf' width='500' height='675'>",
'14':'Q1_2019/alabama_al'
},
'isSoftEditable':False,
'childTableId':0
}
],
'total':1,
'limit':1000,
'offset':0,
'message':None,
'totalCount':1
}
HubDB API along with the Blog Posts API to batch create/publish 152 blog entries
lösung
I posted some function definitions in Slack. @Matt_Coley replied with assistance, guiding me through several issues with my program. I have posted the updated (and working) code to github as a gist here.
I was incorrectly looping through the HubDB rows, causing a TypeError to occur. Incorrect code for example:
for key, value in table_data.items():
The corrected code to loop through a row in the DB and use the each column in the row as a content item in the blog post. Working example:
HubDB API along with the Blog Posts API to batch create/publish 152 blog entries
lösung
I posted some function definitions in Slack. @Matt_Coley replied with assistance, guiding me through several issues with my program. I have posted the updated (and working) code to github as a gist here.
I was incorrectly looping through the HubDB rows, causing a TypeError to occur. Incorrect code for example:
for key, value in table_data.items():
The corrected code to loop through a row in the DB and use the each column in the row as a content item in the blog post. Working example: