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); }
$objname = strip_characters($js->data->properties->name); } $markets = array(); if (isset($js->data->relationships->markets)) { foreach ($js->data->relationships->markets->items as $market) { $markets[] = $market->name; } // each market } else { $markets[] = "null"; } $fund = array(); if (isset($js->data->relationships->investments)) { foreach ($js->data->relationships->investments->items as $funding) { $round_uuid = strip_first_part($funding->funding_round->path); $fund[] = $round_uuid; } } //$markets=json_encode($markets); $fulldata_collection->insert(array("id" => $doc['id'], "markets" => $markets, "type" => $js->data->type, "name" => $objname, "investments" => $fund)); echo "."; if ($need_update_inv) { update_related($js); } if ($current_item > $items_count) { die("done!\n"); } } echo "cursor finished\n"; $resumerec = $current_item; }