Пример #1
0
while ($selectid < $symbols_num) {
    if ($selectid + $selectidGroupSize > $symbols_num) {
        $selectidGroupSize = $symbols_num - $selectid;
    }
    $list = '';
    // if we don't empty $list, the new list of symbols will be added to the previous list and create double entries
    // Get the list of Yahoo_symbols and convert them into a YQL useable string
    $query = mysql_query("SELECT yahoo_symbol FROM myichi_instrument_names WHERE market = 'USA' LIMIT {$selectid},{$selectidGroupSize} ") or die('Erreur de requête<br />' . $sql . '<br />' . mysql_error());
    while ($row = mysql_fetch_row($query)) {
        $list[] = $row[0];
    }
    $symbolList = "'" . implode("', '", array_values($list)) . "'";
    echo "<br>" . $symbolList . "<br>";
    // Build YQL query
    $yql_query = "select * from yahoo.finance.quotes where symbol in ({$symbolList})";
    $yql_response = $two_legged_app->query($yql_query);
    $yqlqty++;
    if ($yql_response->query->count > 1) {
        for ($i = 0; $i < $yql_response->query->count; $i++) {
            // Determine the last "symbol_period" created for the "yahoo_symbol" we work on (as that is where we start)
            $CurrentSymbol = $yql_response->query->results->quote[$i]->symbol;
            $query = mysql_query("SELECT MAX(symbol_period) AS max, MAX(ID) AS ID FROM myichi_historical_data WHERE yahoo_symbol='{$CurrentSymbol}' AND open<>'NULL' ");
            if (!$query) {
                echo 'Impossible d\'exécuter la requête : ' . mysql_error();
                exit;
            }
            $symbolperiodrow = mysql_fetch_assoc($query);
            $SymbolPeriod = $symbolperiodrow["max"];
            $currentSymbolPeriod = $SymbolPeriod + $symbol_period_increment;
            $query = mysql_query("SELECT ID FROM myichi_historical_data WHERE yahoo_symbol='{$CurrentSymbol}' AND symbol_period='{$currentSymbolPeriod}' ");
            if (!$query) {
Пример #2
0
 $application = new YahooApplication(OAUTH_CONSUMER_KEY, OAUTH_CONSUMER_SECRET);
 // delicious yql
 $yql = "use 'http://www.javarants.com/delicious/delicious.feeds.xml' as delicious.feeds;";
 $yql .= "select * from delicious.feeds";
 if (isset($_REQUEST['username'])) {
     // validate delicious user and set username in datastore
     $username = htmlspecialchars($_REQUEST['username']);
 } else {
     // fetch user data store
     $username = apc_fetch('user_' . $user->guid);
 }
 if ($username) {
     // if user has specified a delicious username
     $yql .= " where username='******';";
 }
 $data = $application->query($yql);
 if (is_object($data) && isset($data->query->results->item)) {
     // build small view content (my yahoo)
     $content .= '<ul class="delicious">';
     foreach ($data->query->results->item as $bookmark) {
         $content .= '<li><a href="' . $bookmark->link . '">' . $bookmark->title . '</a></li>';
     }
     $content .= '</ul>';
     if ($username) {
         if (isset($_REQUEST['username'])) {
             //  username is valid (yql returned results), so save for future requests
             apc_store('user_' . $user->guid, $username);
         }
         // update small view for user bookmarks
         $application->setSmallView($user->guid, $header . $content);
     }
Пример #3
0
/**
 * Calls the Yahoo social directory API to get information about the user associated 
 * with this email address. For more details on the call, see
 * http://query.yahooapis.com/v1/yql?q=select%20*%20from%20social.profile%20where%20guid%20in%20(select%20guid%20from%20yahoo.identity%20where%20yid%3D'petercwarden')&format=xml
 *
 * @since Unknown
 *
 * @param string $email The email address of the user
 */
function yahoo_find_by_email($email)
{
    // Check to see if it's a Yahoo email address. If not, we can't get any information on it.
    $email_parts = split('@', $email);
    if (!isset($email_parts[1]) || $email_parts[1] != 'yahoo.com') {
        return null;
    }
    // The Yahoo user name is just the first part of the email address
    $user_name = $email_parts[0];
    $yahoo_app = new YahooApplication(YAHOO_API_KEY_APP, YAHOO_API_KEY_SHARED);
    if ($yahoo_app == NULL) {
        error_log("Couldn't create Yahoo application");
        return null;
    }
    // Run a YQL query to pull the user information for the given email address
    $query = "select * from social.profile where guid in (select guid from yahoo.identity where yid='{$user_name}')";
    $response = $yahoo_app->query($query);
    if (!isset($response->query->results)) {
        return null;
    }
    $results_object = $response->query->results;
    $profile = $results_object->profile;
    $user_id = $profile->guid;
    $display_name = '';
    $location = $profile->location;
    $portrait_url = $profile->image->imageUrl;
    // Check for an unset portrait. There's no guarantee that this path will remain the same, but
    // so far it seems to have been stable.
    if ($portrait_url == 'http://l.yimg.com/us.yimg.com/i/identity/nopic_192.gif') {
        $portrait_url = '';
    }
    $result = array('yahoo' => array('user_id' => $user_id, 'user_name' => $user_name, 'display_name' => $display_name, 'portrait_url' => $portrait_url, 'location' => $location));
    return $result;
}
function collectHistory($startdate, $enddate, $symbol)
{
    // This function collects the historical data for an Instrument, creates the senkou records and updates the tracker_report.
    // It has the following parameters: $startdate, $enddate and $symbol
    $start = date('H:i:s', time());
    include '/yourpath/charts/includes/yql_keys.php';
    $today = date("Y-m-d");
    echo "starting data collection function";
    // Check if this is the first time this script runs today, if so; reset the counter.
    $query = mysql_query("SELECT rundate, counter FROM myichi_tracker WHERE script='Historical'");
    if (!$query) {
        echo 'Impossible d\'exécuter la requête : ' . mysql_error();
        exit;
    }
    $updatecounter = mysql_fetch_assoc($query);
    //echo $updatecounter[rundate];
    if ($updatecounter[rundate] == $today) {
        echo "this is not the first time that the script runs today";
    } else {
        echo "This is the first time today the script runs";
        $counter = 0;
        $updatecounter[counter] = 0;
        mysql_query("UPDATE myichi_tracker SET counter='{$counter}' WHERE script='Historical'");
    }
    $symbolperiod = 1;
    // The YahooApplication class is used for two-legged authorization, which doesn't need permission from the end user.
    $two_legged_app = new YahooApplication(API_KEY, SHARED_SECRET);
    if ($two_legged_app == NULL) {
        print "<br />";
        print "Error: Cannot get two_legged_app (YahooApplication object).";
        exit;
    }
    // Build YQL query
    $yql_query = "select * from yahoo.finance.historicaldata where symbol = {$symbol} and startDate = {$startdate} and endDate = {$enddate} | sort(field='date')";
    $yql_response = $two_legged_app->query($yql_query);
    $yqlqty++;
    // Show QYL query in the browser
    $datatables = '://datatables.org/alltableswithkeys';
    $yql_query_url = "http://query.yahooapis.com/v1/public/yql?q=" . urlencode($yql_query) . "&env=store://datatables.org/alltableswithkeys&format=json";
    echo "<br>" . $yql_query_url;
    if ($yql_response->query->count > 1) {
        // We must have several days of data
        for ($i = 0; $i < $yql_response->query->count; $i++) {
            $Date = $yql_response->query->results->quote[$i]->Date;
            $Open = $yql_response->query->results->quote[$i]->Open;
            $High = $yql_response->query->results->quote[$i]->High;
            $Low = $yql_response->query->results->quote[$i]->Low;
            $Close = $yql_response->query->results->quote[$i]->Close;
            $Volume = $yql_response->query->results->quote[$i]->Volume;
            $updated = date('Y-m-d G:i:s');
            // Update the database
            mysql_query("INSERT INTO myichi_historical_temp (yahoo_symbol, symbol_period, timeframe, date, updated, open, high, low, close, volume) VALUES ('{$symbol}', '{$symbolperiod}', 'EOD', '{$Date}', '{$updated}', '{$Open}', '{$High}', '{$Low}', '{$Close}', '{$Volume}')");
            $symbolperiod++;
            $addedRecordsCounter++;
        }
        // Now we create the records for senkou
        $query = mysql_query("SELECT MAX(symbol_period) AS max FROM myichi_historical_temp WHERE yahoo_symbol='{$symbol}' AND open<>'NULL' ");
        if (!$query) {
            echo 'Impossible d\'exécuter la requête : ' . mysql_error();
            exit;
        }
        $row = mysql_fetch_assoc($query);
        $symbolperiod = $row["max"];
        for ($i = 1; $i < 27; $i++) {
            $symbolperiod++;
            $date = date("Y-m-d", strtotime("+" . $i . " days"));
            mysql_query("INSERT INTO myichi_historical_temp (yahoo_symbol, symbol_period, date, updated) VALUES ('{$symbol}', '{$symbolperiod}', '{$date}', '{$updated}')");
            $addedRecordsCounter++;
        }
    }
    $info = "Added: " . $symbol . " from: " . $startdate . " to: " . $enddate;
    $counter = $updatecounter[counter] + 1;
    $end = date('H:i:s', time());
    mysql_query("UPDATE myichi_tracker SET rundate='{$today}', counter='{$counter}' WHERE script='Historical' ");
    mysql_query("INSERT INTO myichi_tracker_report (script, date, start, end, yqlqty, records, info) VALUES ('Historical', '{$today}', '{$start}', '{$end}', '{$yqlqty}', '{$addedRecordsCounter}', '{$info}')");
}