} //bad data if (!isset($js->data->properties->funding_type)) { continue; echo "!"; } //bad data //update invround if ($need_update_jsons) { $objname = $doc['id']; $url = "http://api.crunchbase.com/v/2/funding-round/" . $objname . "?user_key={$apikey}"; //echo $doc['id'].": ".$js->data->uuid."\n"; $res = askhost($url, FALSE, "", "", "1", 60000, "", true); $js = json_decode($res['data']); if (isset($js->data->uuid)) { save_json_to_mongo($js, $objname, $jsoninv_collection); } else { echo "_"; $apikey = get_api_key(); $js = $js2; } } $ftype = $js->data->properties->funding_type; if (!isset($js->data->properties->money_raised_usd)) { echo "no usdsum, skip\n"; continue; } $usdsum = $js->data->properties->money_raised_usd; $fcurr = $js->data->properties->money_raised_currency_code; if (isset($fround->data->properties->series)) { $fser = $js->data->properties->series;
function process_tag($tag, $twitterApi, $lastid, $tagid, $tweets_collection) { $json = $twitterApi->get('search/tweets', ['q' => $tag, 'count' => '2000', 'since_id' => $lastid]); //echo $json; $result = json_decode($json); //$arr=array(); //$res=json_encode($arr, JSON_PRETTY_PRINT); //print_r($result); $i = 0; $id = 0; foreach ($result->statuses as $arval) { $tid = 0; $place_name = "null"; $place_c = "null"; $id = $arval->id; save_json_to_mongo($arval, $id, $tweets_collection); $ts = date("Y-m-d H:i:sO", strtotime($arval->created_at)); $text = $arval->text; // @todo process mensions //$text=base64_encode($text); $username = $arval->user->screen_name; $location = $arval->user->location; $retweet_count = (int) $arval->retweet_count; //if (0!=$retweet_count) if (isset($arval->retweeted_status->id)) { // this is retweet $tid = $arval->retweeted_status->id; pg_query("update twits set rtc={$retweet_count} where id={$tid}"); echo "@"; continue; } if (isset($arval->place->id)) { // have place? $place_name = $arval->place->name; $place_c = $arval->place->country_code; echo "\n {$place_name} {$place_c}\n"; } //echo "[$id] $ts $retweet_count : $text \n"; echo "."; //$rj=base64_encode(bzcompress( print_r($result, true))); $text = pg_escape_string($text); $location = pg_escape_string($location); //$location=pg_escape_string(preg_replace('/[^A-Za-z0-9\ \-]/', '', $location)); //CURRENT_TIMESTAMP pg_query("insert into twits (t_id, id, userid, location, ttext, rtc, ts, placename, placecntry) values ({$tagid}, {$id}, '{$username}', '{$location}', '{$text}', 0, '{$ts}', '{$place_name}', '{$place_c}' );"); if ($lastid < $id) { $lastid = $id; } $i++; } // each twit //file_put_contents("/tmp/t/$id.log", print_r($result, true) , FILE_APPEND); //echo "\n";print_r($result);echo "\n"; //$json //echo "($i) sleep 10 sec ... "; return $lastid; }
//$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(); } } if (null == $fround) { echo "no investment data - skip"; //print_r($fround); continue; } // skip "closed" if (!isset($fround->data->properties->money_raised_usd)) { echo "no amount data - skip";
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); }