示例#1
0
$updatecounter = mysql_fetch_assoc($query);
//echo $updatecounter[rundate];
if ($updatecounter[rundate] == $intraday) {
    echo "this is a USA Intraday refresh";
    $symbol_period_increment = 0;
    $queryType = "(USA Intraday refresh)";
} else {
    echo "This is a fresh new day!";
    $symbol_period_increment = 1;
    $counter = 0;
    $updatecounter[counter] = 0;
    $queryType = "(Fresh new USA day!)";
    mysql_query("UPDATE myichi_tracker SET counter='{$counter}' WHERE script='Intraday_USA'");
}
// 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;
}
// Get number of instruments available
$query = mysql_query("SELECT COUNT(*) AS num FROM myichi_instrument_names WHERE market = 'USA'");
$row = mysql_fetch_assoc($query);
$symbols_num = $row['num'];
echo $symbols_num;
echo $selectid;
$rounds = 0;
$symbolList = array();
//	while ($selectid < 140) {
while ($selectid < $symbols_num) {
示例#2
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;
}
示例#3
0
define('OAUTH_CONSUMER_KEY', '###');
define('OAUTH_CONSUMER_SECRET', '###');
define('OAUTH_DOMAIN', '###');
define('OAUTH_APP_ID', '###');
// oauth dance if not authenticated
$session = YahooSession::requireSession(OAUTH_CONSUMER_KEY, OAUTH_CONSUMER_SECRET, OAUTH_APP_ID);
$header = '<h2><img src="http://delicious.com/favicon.ico" title="Delicious" width="16" height="16" />Delicious // social bookmarking</h2>';
$content = '<div id="bookmarks">';
// if user is logged in and oauth is valid
if (is_object($session)) {
    // get oauthed user guid + profile
    $user = $session->getSessionedUser();
    // load y! profile data
    $profile = $user->getProfile();
    // get yap app instance for yql / small view
    $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);
/*************************************************************************************************************
* update_small_from_cron.php
* Update Small YAP View From Cron Job Sample
* 
* Created by Jonathan LeBlanc on 06/08/09.
* Copyright (c) 2009 Yahoo! Inc. All rights reserved.
*
* The copyrights embodied in the content of this file are licensed under the BSD (revised) open source license.
*************************************************************************************************************/
require_once 'apis/Yahoo.inc';
//session information
define('API_KEY', 'KEY HERE');
define('SHARED_SECRET', 'KEY HERE');
define('APP_ID', 'APP ID HERE');
//instantiate session
$session = new YahooApplication(API_KEY, SHARED_SECRET, APP_ID);
//db information
$dbhostname = '###';
$dbusername = '******';
$dbpassword = '******';
$dbname = '###';
//connect to database and get all users
mysql_connect($dbhostname, $dbusername, $dbpassword) or die('Unable to connect to database. Please try again later.');
mysql_select_db($dbname);
$query = "SELECT * FROM user_store";
$result = mysql_query($query);
$j = 1;
//for each database user, update the small view
while (($row = mysql_fetch_assoc($result)) !== false) {
    if ($row['uid']) {
        $html = '';
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}')");
}