How can I use Appscript of google sheets to import json data into Google Sheets I looked at this github link : [import_json_appsscript.js][1] and I have the API here of ticketmaster.com : https://app.ticketmaster.com/discovery/v2/events.json?size=1&apikey=xxxxxxx
Should I use the code of github link all of it into Appsscript? [1]: https://gist.github.com/paulgambill/cacd19da95a1421d3164
2- How can I do this in automating way with Python or Javascript that I have the json data then create Google Sheets file Automatically then represent the data in it.
var url = "https://app.ticketmaster.com/discovery/v2/events.json?size=1&apikey=xxxxxxx";
var xhr = new XMLHttpRequest();
xhr.open("GET", url);
xhr.onreadystatechange = function() {
if (xhr.readyState === 4) {
console.log(xhr.status);
console.log(xhr.responseText);
console.log("Events");
}
};
xhr.send();
CodePudding user response:
You can do it with the gspread library for python. Take a look at the docs here: https://docs.gspread.org/en/latest/#example-usage. Once you have it all set up the below code should work for uploading a json
import json
import gspread
from google.oauth2.service_account import Credentials
# connect to your google sheet
scope = ['https://spreadsheets.google.com/feeds',
'https://www.googleapis.com/auth/drive']
credentials = Credentials.from_service_account_file('key.json', scopes=scope)
gc = gspread.authorize(credentials)
wks = gc.open("spreadsheet name").sheet1
# You can load a json file here, just using some sample data
x = '{ "receiver_email_1":6, "receiver_email_2":8, "receiver_email_3":10 }'
y = json.loads(x)
result = []
for key in y:
result.append([key,y[key]])
wks.update('A1', result)