Home > database >  Scraped JSON Data not Pushing to Google Sheet
Scraped JSON Data not Pushing to Google Sheet

Time:08-06

With a lot of help, I now have a very interesting JSON dataset on wave info. I wanted to push it into a Google Sheet, so I can sort and analyze there. I went through and created the credential, connected to sheet, gave access, etc. I tested just by pushing random values to the sheet, and it worked.

Additionally, the script (without trying to push to G Sheet), runs fine - producing result in terminal.

Is there some reason why this type of data wouldn't be able to go to a Google Sheet? Seems to be working for everything else I've tried.

Any thoughts are much appreciated.

import requests
import pandas as pd
import json

import gspread
gc = gspread.service_account(filename='nj-waves.json')
sh = gc.open_by_key('1mbst-uaRGHWG5ReoFfIsazx0kpY7kXKIBqsRswy1y1Q')
worksheet = sh.sheet1


r = requests.get('https://magicseaweed.com/api/mdkey/spot?&limit=-1')
df = pd.DataFrame(r.json())
# pd.set_option("display.max_rows", None)
# pd.set_option("display.max_columns", None)
print(df)
AddValue = [df]
worksheet.append_row(AddValue)

CodePudding user response:

You can save scraped data as csv file using pandas then store in google sheet from your system

import requests
import pandas as pd
r = requests.get('https://magicseaweed.com/api/mdkey/spot?&limit=-1')
df = pd.DataFrame(r.json()).to_csv('out.csv',index=False)
  • Related