Last active
December 14, 2015 06:19
-
-
Save rohinip/5041448 to your computer and use it in GitHub Desktop.
Returns how much money the company raised
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
################################################## | |
# Crunchbase API | |
# http://developer.crunchbase.com/docs | |
# Other References: | |
# http://docs.python-requests.org/en/latest/user/quickstart/#json-response-content | |
# Command Line: python FundingInfo.py | |
################################################## | |
# Import Libraries | |
import sys | |
import os | |
import json | |
import urllib | |
import urllib2 | |
import math | |
import simplejson | |
import requests | |
# Global Variables | |
apiKey = # Enter your API key here | |
# Ask the user for the company they want to look up | |
print "Enter the company name:" | |
companyEntered = raw_input() | |
# If they enter some (valid) company | |
if companyEntered: | |
# Set up the URI | |
requestURL = 'http://api.crunchbase.com/v/1/company/%(company)s.js?api_key=%(key)s' % {'company' : companyEntered, 'key' : apiKey} | |
r = requests.get(requestURL) | |
responseBody = json.loads(r.text) | |
# If the company is found in the Crunchbase database | |
try: | |
Funding = responseBody[u'total_money_raised'] | |
strDisplay = 'Total Funding = %(s)s' % {'s' : Funding} | |
# Otherwise, print an error message | |
except: | |
strDisplay = 'Sorry, no funding information was found for %(s)s' % {'s' : companyEntered} | |
print strDisplay | |
# Else if no company is entered | |
else: | |
print "Well, alas, we are at an impasse. No funding information found because you didn't enter anything. Womp womp." | |
################################################## | |
# To create breakpoints, use: | |
# import pdb | |
# pdb.set_trace() | |
################################################## |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment