When APIs Ghost You: Building a Python Company Industry API Fallback

Day 98 of 100 Days Coding Challenge

Today’s mission: teach Business Rader 3000 how to fetch industry information for a company. Sounds simple, right? Type “Ford Motor Corporation,” press enter, and voilà—get back “automotive industry.” Except, of course, nothing in programming is ever that straightforward.

My first plan was to use Clearbit. Plot twist: Clearbit slammed the door on free accounts. Then I looked at OpenCorporates—yep, that one comes with a price tag too. Fair enough; servers don’t run on fairy dust. But since I’m a hobbyist coder, dropping money on every shiny API is not my jam.

So I went with the Big Three:

  • Yahoo Finance (yfinance) for public companies.
  • Wikidata API for international and quirky cases.
  • Google Knowledge Graph is the “last resort uncle” who knows a little about everything.

Google KG is tricky—you get some queries free, but if you forget to actually activate your account (like I did), you’ll spend hours wondering why nothing works. I had déjà vu from a year ago when I took a Coursera class on Google Cloud and burned through my free credits, then was charged $6.5. It’s possible I may have just expired a trial. To be fair, Google Cloud gave you a way to maintain your costs if you are serious about using their service. That is how I know I spent money. The bright side? Google still gives a generous allowance of daily free queries. It’s like IT giants saying, “Sure, kid, go play in our sandbox—just don’t dig a swimming pool.”

Today’s Motivation / Challenge

Why does this matter? Because knowing what industry a company belongs to is like knowing the genre of a book before you read it. You don’t want to bring a box of tissues to a slapstick comedy, and you don’t want to pitch software to a tire manufacturer. Business Rader 3000 needs this context to do anything useful, and today was the day it learned how to ask smart questions.

Purpose of the Code (Object)

The code takes the company name you provide and then checks three different sources (Yahoo Finance, Wikidata, Google KG) to guess its industry and sector. If one fails, the next one steps up. Think of it as having three friends with wildly different interests—if one doesn’t know the answer, another probably does.

AI Prompt

For your Business Rader 3000 project, I’d suggest:

  • Use Yahoo Finance / yfinance for public companies.
  • Use Wikidata API for broader coverage (private + international).
  • Fall back to the Google Knowledge Graph API for missing entries.

Please add exactly the same functions, but change the source of information.

Functions & Features

  • Prompt the user for a company name.
  • Query Yahoo Finance for industry and sector info.
  • Query the Wikidata API as a second source.
  • Use Google Knowledge Graph as a fallback.
  • Display results in a simple dictionary format.

Requirements / Setup

You’ll need:

  • Python 3.11+
  • Install libraries:

pip install yfinance requests

(Plus a Google API key if you’re using Google KG.)

Minimal Code Sample

import yfinance as yf

company = “F”

info = yf.Ticker(company).info

print({“industry”: info.get(“industry”), “sector”: info.get(“sector”)})

Here we ask Yahoo Finance about Ford, and it politely answers with industry and sector details.

business-rader-3000

Notes / Lessons Learned

When I first ran the program, the response was… silence. No data, no errors, just tumbleweeds. Debugging to the rescue. I added two levels:

  • BR_DEBUG=1 to show which provider answered (or didn’t).
  • BR_DEBUG=2 to print detailed HTTP errors.

That’s when I remembered my weather app fiasco: API keys sometimes need 45–50 minutes to wake up after being created. Turns out, I hadn’t properly activated Google KG at all. Once I fixed that, it worked like a charm. The funny part? By the time I figured this out, I couldn’t tell whether it was my script improving or the API finally letting me in. Either way, I learned something priceless—how to debug like a grown-up.

Optional Ideas for Expansion

  • Save industry results into a local file so you don’t keep hitting the APIs for the same company.
  • Add a fallback “guess” list based on keywords in the company name.
  • Display results in a friendly table instead of a plain dictionary.

        info = yf.Ticker(sym).get_info()

        industry = _normalize(info.get(“industry”))

        sector = _normalize(info.get(“sector”))

        if industry or sector:

            return {“industry”: industry, “sector”: sector or _guess_sector_from_industry(industry)}

Leave a Reply

Your email address will not be published. Required fields are marked *