I would like to save the whole Azure Prices REST API to CSV.
In order to do so I have to query the endpoint https://prices.azure.com/api/retail/prices which ends with a:
"NextPageLink":"https://prices.azure.com:443/api/retail/prices?$skip=100","Count":100}
I wrote a Python scripts that could help me grab that NextPageLink
and loop it into a function:
import requests
import json
import pandas as pd
from timeit import default_timer as timer
from datetime import timedelta
start = timer()
NextPageLink = "https://prices.azure.com/api/retail/prices"
def GetJSON(NextPageLink):
wjdata = requests.get(NextPageLink).json()
df = pd.DataFrame(wjdata)
df.to_csv("test.csv", index=False)
if 'NextPageLink' in wjdata:
print (timer(), wjdata['NextPageLink'])
NextPageLink = wjdata['NextPageLink']
return NextPageLink
GetJSON(NextPageLink)
The script is quite simple but it just saves the first page and doesn't query the NextPageLink
.
What am I doing wrong?