/// <summary> /// Gets the info about a company in Crunchbase /// </summary> /// <param name="crunchcompany">string that matches the shortname in crunchbase, for example as in companies collection name</param> /// <returns>Data in a CrunchBase class structure</returns> public CrunchBase GetCrunchCompany(string crunchcompany) { CrunchJsonStream cjStream = new CrunchJsonStream(); string jsonStream; jsonStream = cjStream.GetJsonStream(crunchcompany, "company"); if (jsonStream != null) { try { string jsonLine; JavaScriptSerializer ser = new JavaScriptSerializer(); //with the stream, now deserialize into the Crunchbase object CrunchBase jsonCrunchBase = ser.Deserialize <CrunchBase>(jsonStream); //assuming that worked, we need to clean up and create some additional meta data jsonCrunchBase.FixCrunchBaseURL(); jsonCrunchBase.AggregateFunding(); jsonCrunchBase.SplitTagString(); //and now we build the CSV string and write to file jsonLine = "\t" + jsonCrunchBase.GetImageURL() + "\t" + jsonCrunchBase.name + "\t" + jsonCrunchBase.homepage_url + "\t" + jsonCrunchBase.crunchbase_url + "\t" + jsonCrunchBase.description + "\t" + jsonCrunchBase.category_code + "\t" + jsonCrunchBase.number_of_employees + "\t" + jsonCrunchBase.hqcity + "\t" + jsonCrunchBase.hqstate + "\t" + jsonCrunchBase.hqcountry + "\t" + jsonCrunchBase.founded_year + "\t" + jsonCrunchBase.GetAggregateFunding().ToString() + "\t" + jsonCrunchBase.GetKeywordList(); /* + "\t\"" + //there are max of 5 keywords I will dump out * jsonCrunchBase.overview + "\"";*/ //I really wanted to put the "overview" field into the file, but the XLS import was //blowing up on the HTML...will need to revisit and fix // tw note: see http://www.blackbeltcoder.com/Articles/strings/convert-html-to-text jsonCrunchBase.tabdelimited = jsonLine; Console.Error.WriteLine("Retrieved info for {0}", jsonCrunchBase.name); return(jsonCrunchBase); } catch (Exception e) { System.Diagnostics.Debug.WriteLine("Oops, the exception {0} happened with {1}", e.ToString(), crunchcompany); return(null); } } else { return(null); } //if } //member get crunch
private void button1_Click(object sender, RibbonControlEventArgs e) { string company = FreeSearch.Text; CrunchBaseConnect cbc = new CrunchBaseConnect(); CrunchBase cbentry = cbc.GetCrunchCompany(company); if (cbentry != null) { int num_cols = 18; Object[,] companyrow = new Object[1, num_cols]; //headerstring if needed /* string[] cpny ={"Company Logo URL","Company Name","Homepage URL","Crunchbase URL", * "Short Description","Category","Number of Employees","City","State", * "Country","Year Founded","Total Funding",,"keyword tags"}; */ companyrow[0, 0] = cbentry.GetImageURL(); companyrow[0, 1] = cbentry.name; companyrow[0, 2] = cbentry.homepage_url; companyrow[0, 3] = cbentry.crunchbase_url; companyrow[0, 4] = cbentry.description; companyrow[0, 5] = cbentry.category_code; companyrow[0, 6] = cbentry.number_of_employees; companyrow[0, 7] = cbentry.offices[0].city; companyrow[0, 8] = cbentry.offices[0].state_code; companyrow[0, 9] = cbentry.offices[0].country_code; companyrow[0, 10] = cbentry.founded_year; companyrow[0, 11] = cbentry.GetAggregateFunding(); companyrow[0, 12] = cbentry.tag_list; var curr = Globals.ThisAddIn.Application.ActiveSheet; var startCell = Globals.ThisAddIn.Application.ActiveCell; var endCell = curr.Cells[startCell.Row, startCell.Column + num_cols]; var writeRange = curr.Range[startCell, endCell]; writeRange.Value2 = companyrow; } else // it's not a company { CrunchFinancial cfc = cbc.GetCrunchFinanceOrg(company); } }