function update_object_and_related($objname) { //global $jsoninv_collection; global $jsondata_collection; $cachetime = 12 * 60 * 60; // 12h $objjs = load_json_from_mongo($objname, $jsondata_collection); $ts = $data['ts']; if ($ts + $cachetime > time()) { echo ","; return true; } $apikey = get_api_key(); $res = askhost("http://api.crunchbase.com/v/2/" . $objname . "?user_key={$apikey}", FALSE, "", "", "1", 60000, "", true); $js = json_decode($res['data']); if (isset($js->data->uuid)) { save_json_to_mongo($js, $objname, $jsondata_collection); } update_related($js); }
$fund_num = 0; foreach ($js->data->relationships->investments->items as $funding) { $round_uuid = strip_first_part($funding->funding_round->path); $fund[$fund_num] = $round_uuid; $fund_num++; if (!isset($investments[$round_uuid])) { // add new investment $newround = array(); $newround['id'] = $round_uuid; //$round_fname="/tmp/cb/$round_uuid.json"; //$newround['recipient']=strip_characters($funding->invested_in->name); $rcpt_path = strip_first_part($funding->invested_in->path); $newround['recipient'] = $rcpt_path; $fround = null; if (isset($fullinv[$round_uuid])) { $mnginv = load_json_from_mongo($round_uuid, $jsoninv_collection); $fround = json_decode(bzdecompress($mnginv['jsondata']->bin)); echo "+"; } if (!isset($fround->data->uuid)) { echo "\nbad investment data: " . print_r($fround, true) . "\ntrying to reload "; $res2 = askhost("http://api.crunchbase.com/v/2/funding-round/" . $round_uuid . "?user_key={$apikey}", FALSE, "", "", "1", 60000, "", true); $fround = json_decode($res2['data']); if (isset($fround->data->uuid)) { save_json_to_mongo($fround, $round_uuid, $jsoninv_collection); //file_put_contents($round_fname, json_encode($fround,JSON_PRETTY_PRINT) ); echo "-"; } else { echo "!"; $apikey = get_api_key(); }