razorhash / pyfmpcloud

A python wrapper for the Financial Model Prep API for analysis of public companies
MIT License
49 stars 10 forks source link

Reading JSON fails if JSON includes a URL #18

Open tjewell99 opened 3 years ago

tjewell99 commented 3 years ago

For example, https://fmpcloud.io/api/v3/income-statement/AAPL?period=quarter&limit=400&apikey=demo ends like this:

...
"weightedAverageShsOutDil" : 17528214000,
  "link" : "https://www.sec.gov/Archives/edgar/data/320193/000032019320000096/0000320193-20-000096-index.htm",
  "finalLink" : "https://www.sec.gov/Archives/edgar/data/320193/000032019320000096/aapl-20200926.htm"
},

The Pandas JSON parser complains of "Protocol not known". It's upset by the semicolon in the URL. My fix has to been to modify safe_read_json() in company_valuation.py:

def safe_read_json(data):
    if (data.find("Error Message") != -1):
        raise Exception(data[20:-3])
    else:
        data = data.replace('http:','http-')
        data = data.replace('https:','https-')
        return pd.read_json(data)

This at least removes the semicolons. There's probably prettier ways of doing this!

antoinevulcain commented 3 years ago

I found a new one https://github.com/daxm/fmpsdk