Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- /*
- Listataan Veikkauksen tulosvedon viimeisimmät kertoimet, kaksi vaihtoehtoa:
- 1) pelinro = tulosvedon pelinumero (listIndex)
- Vielä avoin kohde: scoreodds.php?pelinro=1
- (hae oikea pelinro/listIndex pelilistalta, 1, 2, 3,...)
- 2) id = yksilöllinen numero tulosvedolle (id)
- Jo suljettu kohde: scoreodds.php?id=133644
- (oikea id selvitettävä pelin ollessa vielä avoinna, kuusinumeroinen kokonaisluku)
- Löydetyistä kertoimista luodaan automaattisesti tiedosto 'scoreodds-{id}.csv'
- CSV-tiedoston sijaintipolku on sama kuin tämän PHP-tiedoston.
- */
- error_reporting(0);
- header("Content-Type: text/html; charset=utf-8");
- header("Cache-Control: no-cache");
- $offset = 60 * 60 * 24 * 1;
- $ExpStr = "Expires: " . gmdate("D, d M Y H:i:s", time() + $offset) . " GMT";
- header($ExpStr);
- date_default_timezone_set("Europe/Helsinki");
- $current_file_name = basename($_SERVER['PHP_SELF']);
- //alustetaan muuttujat ja funktiot
- function test_input($data) {
- $data = trim($data);
- $data = stripslashes($data);
- $data = htmlspecialchars($data);
- return (int)$data;
- }
- function participants($data) {
- $data = trim($data);
- $data = stripslashes($data);
- $data = htmlspecialchars($data);
- $data = str_replace(".","",$data);
- return $data;
- }
- $scoreId = $scoreListIndex = $valuemax = $participants = 0;
- $kertoimet = $pelikohteet = array();
- //luetaan tarvittavat muuttujat
- if (isset($_GET['game'])) {
- $participants = strval(participants($_GET['game']));
- }
- if (isset($_GET['id'])) {
- $scoreId = test_input($_GET['id']);
- if (!is_int($scoreId)) { $scoreId = 0; }
- if ($participants <> "0") {
- $failinimi = "scoreodds-".$scoreId."-".$participants.".csv";
- $oddsfile = $participants."\r\nsep=;\r\nkotimaalit;vierasmaalit;kerroin\r\n";
- } else {
- $failinimi = "scoreodds-".$scoreId.".csv";
- $oddsfile = "sep=;\r\nkotimaalit;vierasmaalit;kerroin\r\n";
- }
- }
- if (isset($_GET['pelinro'])) {
- $scoreListIndex = test_input($_GET['pelinro']);
- if (!is_int($scoreListIndex)) { $scoreListIndex = 0; }
- }
- ?>
- <!DOCTYPE HTML>
- <html lang="fi">
- <head>
- <meta charset="UTF-8" />
- <meta name="viewport" content="width=device-width, initial-scale=1.0" />
- <title>TULOSVETO</title>
- <meta name="apple-mobile-web-app-title" content="SCORE ODDS" />
- <meta name="author" content="Anonymous" />
- <style>*{box-sizing:border-box}html{background-color:#F0F0F0}body{margin:0}#main{width:310px;margin:20px auto;display:block}p{color:#00F}.menu{font-size:x-large;border:solid 2px #00F;padding:5px}.sep{width:90%;height:1px;visibility:hidden}a{text-decoration:none;color:#00F}a:hover{text-decoration:none;background:#ADD8E6;box-shadow:0 0 15px 10px #ADD8E6}</style>
- </head>
- <body>
- <div id="main">
- <?php
- if ($scoreId == 0 && $scoreListIndex == 0) {
- // Alustetaan URL
- $host = "https://www.veikkaus.fi";
- $header = array(
- "Accept: application/json",
- "Content-Type: application/json",
- "X-ESA-API-Key: ROBOT"
- );
- $url = $host ."/api/sport-open-games/v1/games/score/draws";
- // Alustetaan cURL asetuksineen
- $ch = curl_init();
- curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 0);
- curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0);
- curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
- curl_setopt($ch, CURLOPT_URL, $url);
- curl_setopt($ch, CURLOPT_POST, 0);
- curl_setopt($ch, CURLOPT_HTTPHEADER, $header);
- curl_setopt($ch, CURLOPT_ENCODING, "identity");
- // Suoritetaan pyyntö
- $data = curl_exec($ch);
- // Suljetaan cURL
- curl_close($ch);
- // Tarkistetaan että datassa on eloa
- $sub = "gameRuleSet";
- if ($data && strpos($data, $sub) !== false) {
- $pelikohteet = json_decode($data, true);
- echo "<h2>AVOIMET KOHTEET:</h2>";
- foreach((array) $pelikohteet as $listIndexes) {
- //noudetaan avoimet tulosvedon kohteet
- echo "<p><span title='kohteen pelinro'>".$listIndexes['listIndex']."</span>) <a href='".$current_file_name."?id=".$listIndexes['id']."&game=".str_replace(' ', '', $listIndexes['rows'][0]['outcome']['home']['name'])."-".str_replace(' ', '', $listIndexes['rows'][0]['outcome']['away']['name'])."'>".$listIndexes['rows'][0]['outcome']['home']['name']." - ".$listIndexes['rows'][0]['outcome']['away']['name']."</a> (<span title='kohteen uniikki id'>".$listIndexes['id']."</span>)</p>";
- }
- } else {
- die("<h3>Kohdetietoja ei ole saatavilla!</h3>");
- }
- }
- if ($scoreId > 0) {
- // Alustetaan URL
- $host = "https://www.veikkaus.fi";
- $header = array(
- "Accept: application/json",
- "Content-Type: application/json",
- "X-ESA-API-Key: ROBOT"
- );
- $url = $host ."/api/sport-odds/v1/games/score/draws/".$scoreId."/odds";
- // Alustetaan cURL asetuksineen
- $ch = curl_init();
- curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 0);
- curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0);
- curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
- curl_setopt($ch, CURLOPT_SAFE_UPLOAD, true);
- curl_setopt($ch, CURLOPT_URL, $url);
- curl_setopt($ch, CURLOPT_POST, 0);
- curl_setopt($ch, CURLOPT_HTTPHEADER, $header);
- curl_setopt($ch, CURLOPT_ENCODING, "identity");
- // Suoritetaan pyyntö
- $data = curl_exec($ch);
- // Suljetaan cURL
- curl_close($ch);
- // Tarkistetaan että datassa on eloa
- $sub = "totalResults";
- if ($data && strpos($data, $sub) !== false) {
- $kertoimet = json_decode($data, true);
- $valuemax = $kertoimet['totalResults'];
- for ($x = 0; $x < $valuemax; $x++) {
- $oddsfile .= $kertoimet['odds'][$x]['selections'][0]['homeScores'][0].";".$kertoimet['odds'][$x]['selections'][0]['awayScores'][0].";".number_format(($kertoimet['odds'][$x]['value']/100),2,","," ")."\r\n";
- }
- echo "<span class='menu' title='AVOIMET KOHTEET'><a href='".$current_file_name."'>AVOIMET KOHTEET</a></span>";
- echo "<hr class='sep'>";
- if ($valuemax > 0) {
- //tulostus ruudulle
- echo "<h2>KERTOIMET (.csv):<br />(id=".$scoreId.")</h2>";
- echo nl2br($oddsfile);
- //.csv-tiedoston tallennus hakemistoon
- $oddsfile .= "\r\nurl:\r\nlocalhost".urldecode($_SERVER['REQUEST_URI']);
- $saveMyFile = fopen($failinimi, "w");
- fwrite($saveMyFile, $oddsfile); //(without BOM)
- fclose($saveMyFile);
- } else {
- die("<h3>Kohdetta ei ole vielä pelattu!</h3>");
- }
- } else {
- echo "<span class='menu' title='AVOIMET KOHTEET'><a href='".$current_file_name."'>AVOIMET KOHTEET</a></span>";
- echo "<hr class='sep'>";
- die("<h3>Kertoimia ei saatavilla!</h3>");
- }
- } else if ($scoreListIndex > 0) {
- // Alustetaan URL
- $host = "https://www.veikkaus.fi";
- $header = array(
- "Accept: application/json",
- "Content-Type: application/json",
- "X-ESA-API-Key: ROBOT"
- );
- $url = $host ."/api/sport-open-games/v1/games/score/draws";
- // Alustetaan cURL asetuksineen
- $ch = curl_init();
- curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 0);
- curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0);
- curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
- curl_setopt($ch, CURLOPT_URL, $url);
- curl_setopt($ch, CURLOPT_POST, 0);
- curl_setopt($ch, CURLOPT_HTTPHEADER, $header);
- curl_setopt($ch, CURLOPT_ENCODING, "identity");
- // Suoritetaan pyyntö
- $data = curl_exec($ch);
- // Suljetaan cURL
- curl_close($ch);
- // Tarkistetaan että datassa on eloa
- $sub = "gameRuleSet";
- if ($data && strpos($data, $sub) !== false) {
- $pelikohteet = json_decode($data, true);
- foreach((array) $pelikohteet as $listIndexes) {
- //noudetaan id jos pelinumerolla on olemassa kohdetietoa
- if ($listIndexes['listIndex'] == $scoreListIndex) {
- header('Location: '.$current_file_name.'?id='.$listIndexes['id'].'&game='.str_replace(' ', '', $listIndexes['rows'][0]['outcome']['home']['name']).'-'.str_replace(' ', '', $listIndexes['rows'][0]['outcome']['away']['name']));
- exit();
- }
- }
- echo "<span class='menu' title='AVOIMET KOHTEET'><a href='".$current_file_name."'>AVOIMET KOHTEET</a></span>";
- echo "<hr class='sep'>";
- die("<h3>Peli valitsemallasi numerolla ei ole avoinna!</h3>");
- } else {
- echo "<span class='menu' title='AVOIMET KOHTEET'><a href='".$current_file_name."'>AVOIMET KOHTEET</a></span>";
- echo "<hr class='sep'>";
- die("<h3>Kertoimia ei saatavilla!</h3>");
- }
- }
- //siivotaan jälkiä
- if (isset($scoreId)) { unset($scoreId); }
- if (isset($scoreListIndex)) { unset($scoreListIndex); }
- if (isset($valuemax)) { unset($valuemax); }
- if (isset($kertoimet)) { unset($kertoimet); }
- if (isset($data)) { unset($data); }
- if (isset($sub)) { unset($sub); }
- if (isset($pelikohteet)) { unset($pelikohteet); }
- if (isset($listIndexes)) { unset($listIndexes); }
- if (isset($oddsfile)) { unset($oddsfile); }
- if (isset($host)) { unset($host); }
- if (isset($header)) { unset($header); }
- if (isset($url)) { unset($url); }
- if (isset($ch)) { unset($ch); }
- if (isset($current_file_name)) { unset($current_file_name); }
- if (isset($failinimi)) { unset($failinimi); }
- if (isset($participants)) { unset($participants); }
- ?>
- </div>
- </body>
- </html>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement