Advertisement
FIN-codelines

scoreodds

Jan 3rd, 2023 (edited)
272
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 9.28 KB | None | 0 0
  1. <?php
  2. /*
  3. Listataan Veikkauksen tulosvedon viimeisimmät kertoimet, kaksi vaihtoehtoa:
  4. 1) pelinro = tulosvedon pelinumero (listIndex)
  5. Vielä avoin kohde: scoreodds.php?pelinro=1
  6. (hae oikea pelinro/listIndex pelilistalta, 1, 2, 3,...)
  7.  
  8. 2) id = yksilöllinen numero tulosvedolle (id)
  9. Jo suljettu kohde: scoreodds.php?id=133644
  10. (oikea id selvitettävä pelin ollessa vielä avoinna, kuusinumeroinen kokonaisluku)
  11.  
  12. Löydetyistä kertoimista luodaan automaattisesti tiedosto 'scoreodds-{id}.csv'
  13. CSV-tiedoston sijaintipolku on sama kuin tämän PHP-tiedoston.
  14. */
  15. error_reporting(0);
  16. header("Content-Type: text/html; charset=utf-8");
  17. header("Cache-Control: no-cache");
  18. $offset = 60 * 60 * 24 * 1;
  19. $ExpStr = "Expires: " . gmdate("D, d M Y H:i:s", time() + $offset) . " GMT";
  20. header($ExpStr);
  21. date_default_timezone_set("Europe/Helsinki");
  22. $current_file_name = basename($_SERVER['PHP_SELF']);
  23. //alustetaan muuttujat ja funktiot
  24. function test_input($data) {
  25.     $data = trim($data);
  26.     $data = stripslashes($data);
  27.     $data = htmlspecialchars($data);
  28.     return (int)$data;
  29. }
  30. function participants($data) {
  31.     $data = trim($data);
  32.     $data = stripslashes($data);
  33.     $data = htmlspecialchars($data);
  34.     $data = str_replace(".","",$data);
  35.     return $data;
  36. }
  37. $scoreId = $scoreListIndex = $valuemax = $participants = 0;
  38. $kertoimet = $pelikohteet = array();
  39. //luetaan tarvittavat muuttujat
  40. if (isset($_GET['game'])) {
  41.     $participants = strval(participants($_GET['game']));
  42. }
  43. if (isset($_GET['id'])) {
  44.     $scoreId = test_input($_GET['id']);
  45.     if (!is_int($scoreId)) { $scoreId = 0; }
  46.     if ($participants <> "0") {
  47.         $failinimi = "scoreodds-".$scoreId."-".$participants.".csv";
  48.         $oddsfile = $participants."\r\nsep=;\r\nkotimaalit;vierasmaalit;kerroin\r\n";
  49.     } else {
  50.         $failinimi = "scoreodds-".$scoreId.".csv";
  51.         $oddsfile = "sep=;\r\nkotimaalit;vierasmaalit;kerroin\r\n";
  52.     }
  53. }
  54. if (isset($_GET['pelinro'])) {
  55.     $scoreListIndex = test_input($_GET['pelinro']);
  56.     if (!is_int($scoreListIndex)) { $scoreListIndex = 0; }
  57. }
  58. ?>
  59. <!DOCTYPE HTML>
  60. <html lang="fi">
  61. <head>
  62. <meta charset="UTF-8" />
  63. <meta name="viewport" content="width=device-width, initial-scale=1.0" />
  64. <title>TULOSVETO</title>
  65. <meta name="apple-mobile-web-app-title" content="SCORE ODDS" />
  66. <meta name="author" content="Anonymous" />
  67. <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>
  68. </head>
  69. <body>
  70. <div id="main">
  71. <?php
  72. if ($scoreId == 0 && $scoreListIndex == 0) {
  73.     // Alustetaan URL
  74.     $host = "https://www.veikkaus.fi";
  75.     $header = array(
  76.         "Accept: application/json",
  77.         "Content-Type: application/json",
  78.         "X-ESA-API-Key: ROBOT"
  79.     );
  80.     $url = $host ."/api/sport-open-games/v1/games/score/draws";
  81.  
  82.     // Alustetaan cURL asetuksineen
  83.     $ch = curl_init();
  84.     curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 0);
  85.     curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0);
  86.     curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
  87.     curl_setopt($ch, CURLOPT_URL, $url);
  88.     curl_setopt($ch, CURLOPT_POST, 0);
  89.     curl_setopt($ch, CURLOPT_HTTPHEADER, $header);
  90.     curl_setopt($ch, CURLOPT_ENCODING, "identity");
  91.  
  92.     // Suoritetaan pyyntö
  93.     $data = curl_exec($ch);
  94.  
  95.     // Suljetaan cURL
  96.     curl_close($ch);
  97.  
  98.     // Tarkistetaan että datassa on eloa
  99.     $sub = "gameRuleSet";
  100.     if ($data && strpos($data, $sub) !== false) {
  101.         $pelikohteet = json_decode($data, true);
  102.         echo "<h2>AVOIMET KOHTEET:</h2>";
  103.         foreach((array) $pelikohteet as $listIndexes) {
  104.             //noudetaan avoimet tulosvedon kohteet
  105.             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>";
  106.         }
  107.     } else {
  108.         die("<h3>Kohdetietoja ei ole saatavilla!</h3>");
  109.     }
  110. }
  111. if ($scoreId > 0) {
  112.     // Alustetaan URL
  113.     $host = "https://www.veikkaus.fi";
  114.     $header = array(
  115.         "Accept: application/json",
  116.         "Content-Type: application/json",
  117.         "X-ESA-API-Key: ROBOT"
  118.     );
  119.     $url = $host ."/api/sport-odds/v1/games/score/draws/".$scoreId."/odds";
  120.  
  121.     // Alustetaan cURL asetuksineen
  122.     $ch = curl_init();
  123.     curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 0);
  124.     curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0);
  125.     curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
  126.     curl_setopt($ch, CURLOPT_SAFE_UPLOAD, true);
  127.     curl_setopt($ch, CURLOPT_URL, $url);
  128.     curl_setopt($ch, CURLOPT_POST, 0);
  129.     curl_setopt($ch, CURLOPT_HTTPHEADER, $header);
  130.     curl_setopt($ch, CURLOPT_ENCODING, "identity");
  131.  
  132.     // Suoritetaan pyyntö
  133.     $data = curl_exec($ch);
  134.  
  135.     // Suljetaan cURL
  136.     curl_close($ch);
  137.  
  138.     // Tarkistetaan että datassa on eloa
  139.     $sub = "totalResults";
  140.     if ($data && strpos($data, $sub) !== false) {
  141.         $kertoimet = json_decode($data, true);
  142.         $valuemax = $kertoimet['totalResults'];
  143.         for ($x = 0; $x < $valuemax; $x++) {
  144.             $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";
  145.         }
  146.         echo "<span class='menu' title='AVOIMET KOHTEET'><a href='".$current_file_name."'>AVOIMET KOHTEET</a></span>";
  147.         echo "<hr class='sep'>";
  148.         if ($valuemax > 0) {
  149.             //tulostus ruudulle
  150.             echo "<h2>KERTOIMET (.csv):<br />(id=".$scoreId.")</h2>";
  151.             echo nl2br($oddsfile);
  152.             //.csv-tiedoston tallennus hakemistoon
  153.             $oddsfile .= "\r\nurl:\r\nlocalhost".urldecode($_SERVER['REQUEST_URI']);
  154.             $saveMyFile = fopen($failinimi, "w");
  155.             fwrite($saveMyFile, $oddsfile); //(without BOM)
  156.             fclose($saveMyFile);
  157.         } else {
  158.             die("<h3>Kohdetta ei ole vielä pelattu!</h3>");
  159.         }
  160.     } else {
  161.         echo "<span class='menu' title='AVOIMET KOHTEET'><a href='".$current_file_name."'>AVOIMET KOHTEET</a></span>";
  162.         echo "<hr class='sep'>";
  163.         die("<h3>Kertoimia ei saatavilla!</h3>");
  164.     }
  165. } else if ($scoreListIndex > 0) {
  166.     // Alustetaan URL
  167.     $host = "https://www.veikkaus.fi";
  168.     $header = array(
  169.         "Accept: application/json",
  170.         "Content-Type: application/json",
  171.         "X-ESA-API-Key: ROBOT"
  172.     );
  173.     $url = $host ."/api/sport-open-games/v1/games/score/draws";
  174.  
  175.     // Alustetaan cURL asetuksineen
  176.     $ch = curl_init();
  177.     curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 0);
  178.     curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0);
  179.     curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
  180.     curl_setopt($ch, CURLOPT_URL, $url);
  181.     curl_setopt($ch, CURLOPT_POST, 0);
  182.     curl_setopt($ch, CURLOPT_HTTPHEADER, $header);
  183.     curl_setopt($ch, CURLOPT_ENCODING, "identity");
  184.  
  185.     // Suoritetaan pyyntö
  186.     $data = curl_exec($ch);
  187.  
  188.     // Suljetaan cURL
  189.     curl_close($ch);
  190.  
  191.     // Tarkistetaan että datassa on eloa
  192.     $sub = "gameRuleSet";
  193.     if ($data && strpos($data, $sub) !== false) {
  194.         $pelikohteet = json_decode($data, true);
  195.         foreach((array) $pelikohteet as $listIndexes) {
  196.             //noudetaan id jos pelinumerolla on olemassa kohdetietoa
  197.             if ($listIndexes['listIndex'] == $scoreListIndex) {
  198.                 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']));
  199.                 exit();
  200.             }
  201.         }
  202.         echo "<span class='menu' title='AVOIMET KOHTEET'><a href='".$current_file_name."'>AVOIMET KOHTEET</a></span>";
  203.         echo "<hr class='sep'>";
  204.         die("<h3>Peli valitsemallasi numerolla ei ole avoinna!</h3>");
  205.     } else {
  206.         echo "<span class='menu' title='AVOIMET KOHTEET'><a href='".$current_file_name."'>AVOIMET KOHTEET</a></span>";
  207.         echo "<hr class='sep'>";
  208.         die("<h3>Kertoimia ei saatavilla!</h3>");
  209.     }
  210. }
  211. //siivotaan jälkiä
  212. if (isset($scoreId)) { unset($scoreId); }
  213. if (isset($scoreListIndex)) { unset($scoreListIndex); }
  214. if (isset($valuemax)) { unset($valuemax); }
  215. if (isset($kertoimet)) { unset($kertoimet); }
  216. if (isset($data)) { unset($data); }
  217. if (isset($sub)) { unset($sub); }
  218. if (isset($pelikohteet)) { unset($pelikohteet); }
  219. if (isset($listIndexes)) { unset($listIndexes); }
  220. if (isset($oddsfile)) { unset($oddsfile); }
  221. if (isset($host)) { unset($host); }
  222. if (isset($header)) { unset($header); }
  223. if (isset($url)) { unset($url); }
  224. if (isset($ch)) { unset($ch); }
  225. if (isset($current_file_name)) { unset($current_file_name); }
  226. if (isset($failinimi)) { unset($failinimi); }
  227. if (isset($participants)) { unset($participants); }
  228. ?>
  229. </div>
  230. </body>
  231. </html>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement