Skip to content

Instantly share code, notes, and snippets.

@theemstra
Created March 4, 2015 12:20
Show Gist options
  • Save theemstra/f722319e2242927cd8b6 to your computer and use it in GitHub Desktop.
Save theemstra/f722319e2242927cd8b6 to your computer and use it in GitHub Desktop.
Getting Yahoo Finance quote printed
<!DOCTYPE html>
<?php
/*
* Copyright (C) 2015 Thom Heemstra <[email protected]>
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation; either version 2
* of the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*/
/*
*
* @author Thom Heemstra <[email protected]>
*
*/
?>
<html>
<head>
<meta charset="UTF-8">
<title>Beursinformatie</title>
<script src="https://code.jquery.com/jquery-2.1.3.min.js"></script>
<script type="text/javascript">
function getData() {
var url = "http://query.yahooapis.com/v1/public/yql";
var symbol = ""; // Put your symbol in here
var data = encodeURIComponent("select * from yahoo.finance.quotes where symbol in ('" + symbol + "')");
$.getJSON(url, 'q=' + data + "&format=json&diagnostics=true&env=http://datatables.org/alltables.env")
.done(function (data) {
$("#result").text(data.query.results.quote.LastTradePriceOnly);
})
.fail(function (jqxhr, textStatus, error) {
var err = textStatus + ", " + error;
$("#result").text('Request failed: ' + err);
});
}
jQuery(document).ready(function() {
getData();
});
</script>
</head>
<body>
<div id='result'>Loading...</div>
</body>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment