Im making an API request to pull some articles bodies and ids. I would like to pull them into an excel file where on the first column the id's are displayed and on the next column the corresponding bodies are displayed.
I managed to bring it this far but for some reason the formatting in excel is not right. There is a lot of data that I'm trying to pull here but I would want to display each one of them in it's separate cell.
Can I specifically ask my script to transpose the data automatically?
import requests
import csv
import unicodedata
import getpass
import xlsxwriter
url = 'https://.../articles.json'
workbook = xlsxwriter.Workbook('bodies.xlsx')
worksheet = workbook.add_worksheet()
output_1 = []
output_2 = []
listOf = ([output_1],[output_2])
while url:
user = '[email protected]'
pwd = '1234'
response = requests.get(url, auth=(user, pwd))
data = response.json()
for article in data['articles']:
article_id = article['id']
body = article['body']
decode_1 = int(article_id)
decode_2 = unicodedata.normalize('NFKD', body)
output_1.append(decode_1)
output_1.append(decode_2)
print(data['next_page'])
url = 'https://.../articles.json' and data['next_page']
row = 0
col = 0
for output_1, output_2 in (listOf):
worksheet.write_row(row, col, output_1)
worksheet.write_column(col, col + 1, output_2)
col += 1
workbook.close()
Update:
So basically in my script I'm reading a json that looks something like this
"per_page": 30,
"previous_page": null,
"articles": [
{
"id": 360239848018,
"url": "https://.../articles/360239848018.json",
"html_url": "https://...",
"author_id": 5201232,
"body": "<div class....a lot of html" }
decode_2looks like?decode_1is a int, the script writes a new row for each number(total of 845 rows). In the case ofdecode_2it all get's added to 10 rows..spreading over multiple columns (until DD). I just want to have 2 columns and 845 rows in total.write_column()instead ofwrite_row()?decode_2?