Advertisement
FIN-codelines

sportpopularity

Jan 9th, 2023 (edited)
228
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 15.72 KB | None | 0 0
  1. <?php
  2. /*Listataan Veikkauksen lauantaivakion pelatuimmuusprosentit,
  3. kaksi pelikierrosta:
  4. kuluva viikko ja edellinen jo ratkennut viikko*/
  5. error_reporting(0);
  6. header("Content-Type: text/html; charset=utf-8");
  7. header("Cache-Control: no-cache");
  8. $offset = 60 * 60 * 24 * 1;
  9. $ExpStr = "Expires: " . gmdate("D, d M Y H:i:s", time() + $offset) . " GMT";
  10. header($ExpStr);
  11. date_default_timezone_set("Europe/Helsinki");
  12. //alustetaan muuttujat
  13. $startNr = 100430; //vuoden 2023 viikon 52 lauantaivakion id, täsmäytä $startNr vuosittain viikolla 1
  14. $weekNow = (int) date("W", strtotime('-7 hours'));
  15. $weekLast = (int) date("W", strtotime('-7 days -7 hours'));
  16. $vakioIdThisWeek = ($startNr + $weekNow);
  17. $vakioIdLastWeek = ($startNr + $weekNow - 1);
  18. $justNyt = time();
  19. ?>
  20. <!DOCTYPE HTML>
  21. <html lang="fi">
  22. <head>
  23. <meta charset="UTF-8" />
  24. <meta name="viewport" content="width=device-width, initial-scale=1.0" />
  25. <title>VAKIO-1 ~ PELIJAKAUMA (%)</title>
  26. <meta name="apple-mobile-web-app-title" content="PERCENTAGES" />
  27. <meta name="author" content="Anonymous" />
  28. <style>*{box-sizing:border-box}html{background-color:#F0F0F0}body{margin:0}#main{width:420px;margin:20px auto;display:block}h3{margin:10px}p{color:#000;margin:0 0 0 20px}th{padding:8px;border:solid 1px #000;background:#00F;color:#FFF}td{padding:8px;border:solid 1px #000;background:#F0F0FF}.act{color:#008000}.kes{text-align:center}.ohi{color:#F00}.oik{text-align:right}.sep{width:95%;height:1px}.st1{width:418px;table-layout:fixed}.st2{width:236px}.st3{width:56px}.vas{text-align:left}</style>
  29. </head>
  30. <body>
  31. <div id="main">
  32. <?php
  33. if (!isset($vakioIdThisWeek) && !isset($vakioIdLastWeek)) { die("<h3>Viikkoa ei ole määritelty!</h3>"); }
  34. if (isset($vakioIdThisWeek) && $vakioIdThisWeek > 0) {
  35.     $active = 0;
  36.     $outcomes = array();
  37.     // Alustetaan URL
  38.     $host = "https://www.veikkaus.fi";
  39.     $header = array(
  40.         "Accept: application/json",
  41.         "Content-Type: application/json",
  42.         "X-ESA-API-Key: ROBOT"
  43.     );
  44.     $url = $host ."/api/sport-results/v1/games/SPORT/draws/".$vakioIdThisWeek;
  45.  
  46.     // Alustetaan cURL asetuksineen
  47.     $ch = curl_init();
  48.     curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 0);
  49.     curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0);
  50.     curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
  51.     curl_setopt($ch, CURLOPT_SAFE_UPLOAD, true);
  52.     curl_setopt($ch, CURLOPT_URL, $url);
  53.     curl_setopt($ch, CURLOPT_POST, 0);
  54.     curl_setopt($ch, CURLOPT_HTTPHEADER, $header);
  55.     curl_setopt($ch, CURLOPT_ENCODING, "identity");
  56.  
  57.     // Suoritetaan pyyntö
  58.     $data = curl_exec($ch);
  59.  
  60.     // Suljetaan cURL
  61.     curl_close($ch);
  62.  
  63.     // Tarkistetaan että datassa on eloa
  64.     $sub = "outcome";
  65.     if ($data && strpos($data, $sub) !== false) {
  66.         $teams = array();
  67.         $teams = json_decode($data, true);
  68.         $z = 0;
  69.         while (isset($teams['rows'][$z])) {
  70.             array_push($outcomes, $teams['rows'][$z]['outcome']['home']['name']." - ".$teams['rows'][$z]['outcome']['away']['name']);
  71.             $z++;
  72.         }
  73.         if (isset($teams['closeTime'])) {
  74.             $closeT = date("d.m.Y \k\l\o H:i", $teams['closeTime']/1000);
  75.             if ($justNyt < ($teams['closeTime']/1000)) { $active = 1;}
  76.         }
  77.     }
  78.  
  79.     // Alustetaan URL
  80.     $host = "https://www.veikkaus.fi";
  81.     $header = array(
  82.         "Accept: application/json",
  83.         "Content-Type: application/json",
  84.         "X-ESA-API-Key: ROBOT"
  85.     );
  86.     $url = $host ."/api/sport-popularity/v1/games/SPORT/draws/".$vakioIdThisWeek."/popularity";
  87.  
  88.     // Alustetaan cURL asetuksineen
  89.     $ch = curl_init();
  90.     curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 0);
  91.     curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0);
  92.     curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
  93.     curl_setopt($ch, CURLOPT_SAFE_UPLOAD, true);
  94.     curl_setopt($ch, CURLOPT_URL, $url);
  95.     curl_setopt($ch, CURLOPT_POST, 0);
  96.     curl_setopt($ch, CURLOPT_HTTPHEADER, $header);
  97.     curl_setopt($ch, CURLOPT_ENCODING, "identity");
  98.  
  99.     // Suoritetaan pyyntö
  100.     $data = curl_exec($ch);
  101.  
  102.     // Suljetaan cURL
  103.     curl_close($ch);
  104.  
  105.     // Tarkistetaan että datassa on eloa
  106.     $sub = "resultPopularities";
  107.     if ($data && strpos($data, $sub) !== false) {
  108.         $prossat = array();
  109.         $prossat = json_decode($data, true);
  110.         echo "<h2 class='kes'>LAUANTAIVAKIO, KIERROS ".$vakioIdThisWeek."</h2>";
  111.         if ($active == 1) { echo "<h3 class='kes'>peliaika päättyy <span class='act'>".$closeT."</span></h3>"; } else { echo "<h3 class='kes'>peliaika päättyi <span class='ohi'>".$closeT."</span></h3>"; }
  112.         echo "<h3 class='kes'>perusvakion pelatuimmuus-%</h3>";
  113.         echo "<table class='st1'><thead><tr><th class='vas st2'>kohdelista</th><th class='st3'>1</th><th class='st3'>X</th><th class='st3'>2</th></tr></thead><tbody>";
  114.         $x = 0;
  115.         $y = 1;
  116.         while (isset($prossat['resultPopularities'][$x]['percentage'])) {
  117.             echo "<tr><td>".$y.") ".$outcomes[$y-1]."</td><td class='oik'>".number_format(($prossat['resultPopularities'][$x]['percentage']/100),2,","," ")."</td>";
  118.             $x++;
  119.             echo "<td class='oik'>".number_format(($prossat['resultPopularities'][$x]['percentage']/100),2,","," ")."</td>";
  120.             $x++;
  121.             echo "<td class='oik'>".number_format(($prossat['resultPopularities'][$x]['percentage']/100),2,","," ")."</td></tr>";
  122.             $x++;
  123.             $y++;
  124.         }
  125.         echo "</tbody></table><br />";
  126.         echo "<h3 class='kes'>minivakion pelatuimmuus-%</h3>";
  127.         echo "<table class='st1'><thead><tr><th class='vas st2'>kohdelista</th><th class='st3'>1</th><th class='st3'>X</th><th class='st3'>2</th></tr></thead><tbody>";
  128.         $x = 0;
  129.         $y = 1;
  130.         while (isset($prossat['resultPopularities'][$x]['awdPercentage'])) {
  131.             echo "<tr><td>".$y.") ".$outcomes[$y-1]."</td><td class='oik'>".number_format(($prossat['resultPopularities'][$x]['awdPercentage']/100),2,","," ")."</td>";
  132.             $x++;
  133.             echo "<td class='oik'>".number_format(($prossat['resultPopularities'][$x]['awdPercentage']/100),2,","," ")."</td>";
  134.             $x++;
  135.             echo "<td class='oik'>".number_format(($prossat['resultPopularities'][$x]['awdPercentage']/100),2,","," ")."</td></tr>";
  136.             $x++;
  137.             $y++;
  138.         }
  139.         echo "</tbody></table>";
  140.         echo "<br /><p>perusvakion vaihto: ".number_format(($prossat['exchange']/100),2,","," ")." &euro;</p>";
  141.  
  142.         //minivakion vaihtoon tarvittava kysely
  143.         $ehm = "{ \"page\": 0, \"pageSize\": 100, \"additionalPrizeTier\": true, \"selections\": [ ";
  144.         $ehm .= "{ \"outcomes\":[\"1\"] }, ";
  145.         $ehm .= "{ \"outcomes\":[\"1\"] }, ";
  146.         $ehm .= "{ \"outcomes\":[\"1\"] }, ";
  147.         $ehm .= "{ \"outcomes\":[\"1\"] }, ";
  148.         $ehm .= "{ \"outcomes\":[\"1\"] }, ";
  149.         $ehm .= "{ \"outcomes\":[\"1\"] }, ";
  150.         $ehm .= "{ \"outcomes\":[\"1\"] } ] }";
  151.  
  152.         // Alustetaan URL
  153.         $host = "https://www.veikkaus.fi";
  154.         $header = array(
  155.             "Accept: application/json",
  156.             "Content-Type: application/json",
  157.             "X-ESA-API-Key: ROBOT"
  158.         );
  159.         $url = $host . "/api/sport-winshare/v1/games/SPORT/draws/".$vakioIdThisWeek."/winshare";
  160.  
  161.         // Alustetaan cURL asetuksineen
  162.         $ch = curl_init();
  163.         curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 0);
  164.         curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0);
  165.         curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
  166.         curl_setopt($ch, CURLOPT_SAFE_UPLOAD, true);
  167.         curl_setopt($ch, CURLOPT_URL, $url);
  168.         curl_setopt($ch, CURLOPT_POST, 1);
  169.         curl_setopt($ch, CURLOPT_POSTFIELDS, $ehm);
  170.         curl_setopt($ch, CURLOPT_HTTPHEADER, $header);
  171.         curl_setopt($ch, CURLOPT_ENCODING, "identity");
  172.  
  173.         // Suoritetaan pyyntö
  174.         $minidata = curl_exec($ch);
  175.  
  176.         // Suljetaan cURL
  177.         curl_close($ch);
  178.  
  179.         // Tarkistetaan että datassa on eloa
  180.         $sub = "exchange";
  181.         if ($data && strpos($data, $sub) !== false) {
  182.             $tuloksetmini = array();
  183.             $tuloksetmini = json_decode($minidata,true);
  184.             echo "<p>minivakion vaihto: ".number_format(($tuloksetmini['exchange']/100),2,","," ")." &euro;</p>";
  185.         }
  186.         echo "<hr class='sep'>";
  187.     }
  188. }
  189.  
  190. if (isset($vakioIdLastWeek) && $vakioIdLastWeek > 0) {
  191.     $active = 0;
  192.     $outcomes = array();
  193.     // Alustetaan URL
  194.     $host = "https://www.veikkaus.fi";
  195.     $header = array(
  196.         "Accept: application/json",
  197.         "Content-Type: application/json",
  198.         "X-ESA-API-Key: ROBOT"
  199.     );
  200.     $url = $host ."/api/sport-results/v1/games/SPORT/draws/".$vakioIdLastWeek;
  201.  
  202.     // Alustetaan cURL asetuksineen
  203.     $ch = curl_init();
  204.     curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 0);
  205.     curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0);
  206.     curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
  207.     curl_setopt($ch, CURLOPT_SAFE_UPLOAD, true);
  208.     curl_setopt($ch, CURLOPT_URL, $url);
  209.     curl_setopt($ch, CURLOPT_POST, 0);
  210.     curl_setopt($ch, CURLOPT_HTTPHEADER, $header);
  211.     curl_setopt($ch, CURLOPT_ENCODING, "identity");
  212.  
  213.     // Suoritetaan pyyntö
  214.     $data = curl_exec($ch);
  215.  
  216.     // Suljetaan cURL
  217.     curl_close($ch);
  218.  
  219.     // Tarkistetaan että datassa on eloa
  220.     $sub = "outcome";
  221.     if ($data && strpos($data, $sub) !== false) {
  222.         $teams = array();
  223.         $teams = json_decode($data, true);
  224.         $z = 0;
  225.         while (isset($teams['rows'][$z])) {
  226.             array_push($outcomes, $teams['rows'][$z]['outcome']['home']['name']." - ".$teams['rows'][$z]['outcome']['away']['name']);
  227.             $z++;
  228.         }
  229.         if (isset($teams['closeTime'])) {
  230.             $closeT = date("d.m.Y \k\l\o H:i", $teams['closeTime']/1000);
  231.             if ($justNyt < ($teams['closeTime']/1000)) { $active = 1;}
  232.         }
  233.     }
  234.  
  235.     // Alustetaan URL
  236.     $host = "https://www.veikkaus.fi";
  237.     $header = array(
  238.         "Accept: application/json",
  239.         "Content-Type: application/json",
  240.         "X-ESA-API-Key: ROBOT"
  241.     );
  242.     $url = $host ."/api/sport-popularity/v1/games/SPORT/draws/".$vakioIdLastWeek."/popularity";
  243.  
  244.     // Alustetaan cURL asetuksineen
  245.     $ch = curl_init();
  246.     curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 0);
  247.     curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0);
  248.     curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
  249.     curl_setopt($ch, CURLOPT_SAFE_UPLOAD, true);
  250.     curl_setopt($ch, CURLOPT_URL, $url);
  251.     curl_setopt($ch, CURLOPT_POST, 0);
  252.     curl_setopt($ch, CURLOPT_HTTPHEADER, $header);
  253.     curl_setopt($ch, CURLOPT_ENCODING, "identity");
  254.  
  255.     // Suoritetaan pyyntö
  256.     $data = curl_exec($ch);
  257.  
  258.     // Suljetaan cURL
  259.     curl_close($ch);
  260.  
  261.     // Tarkistetaan että datassa on eloa
  262.     $sub = "resultPopularities";
  263.     if ($data && strpos($data, $sub) !== false) {
  264.         $prossat = array();
  265.         $prossat = json_decode($data, true);
  266.         echo "<h2 class='kes'>LAUANTAIVAKIO, KIERROS ".$vakioIdLastWeek."</h2>";
  267.         if ($active == 1) { echo "<h3 class='kes'>peliaika päättyy <span class='act'>".$closeT."</span></h3>"; } else { echo "<h3 class='kes'>peliaika päättyi <span class='ohi'>".$closeT."</span></h3>"; }
  268.         echo "<h3 class='kes'>perusvakion pelatuimmuus-%</h3>";
  269.         echo "<table class='st1'><thead><tr><th class='vas st2'>kohdelista</th><th class='st3'>1</th><th class='st3'>X</th><th class='st3'>2</th></tr></thead><tbody>";
  270.         $x = 0;
  271.         $y = 1;
  272.         while (isset($prossat['resultPopularities'][$x]['percentage'])) {
  273.             echo "<tr><td>".$y.") ".$outcomes[$y-1]."</td><td class='oik'>".number_format(($prossat['resultPopularities'][$x]['percentage']/100),2,","," ")."</td>";
  274.             $x++;
  275.             echo "<td class='oik'>".number_format(($prossat['resultPopularities'][$x]['percentage']/100),2,","," ")."</td>";
  276.             $x++;
  277.             echo "<td class='oik'>".number_format(($prossat['resultPopularities'][$x]['percentage']/100),2,","," ")."</td></tr>";
  278.             $x++;
  279.             $y++;
  280.         }
  281.         echo "</tbody></table><br />";
  282.         echo "<h3 class='kes'>minivakion pelatuimmuus-%</h3>";
  283.         echo "<table class='st1'><thead><tr><th class='vas st2'>kohdelista</th><th class='st3'>1</th><th class='st3'>X</th><th class='st3'>2</th></tr></thead><tbody>";
  284.         $x = 0;
  285.         $y = 1;
  286.         while (isset($prossat['resultPopularities'][$x]['awdPercentage'])) {
  287.             echo "<tr><td>".$y.") ".$outcomes[$y-1]."</td><td class='oik'>".number_format(($prossat['resultPopularities'][$x]['awdPercentage']/100),2,","," ")."</td>";
  288.             $x++;
  289.             echo "<td class='oik'>".number_format(($prossat['resultPopularities'][$x]['awdPercentage']/100),2,","," ")."</td>";
  290.             $x++;
  291.             echo "<td class='oik'>".number_format(($prossat['resultPopularities'][$x]['awdPercentage']/100),2,","," ")."</td></tr>";
  292.             $x++;
  293.             $y++;
  294.         }
  295.         echo "</tbody></table>";
  296.         echo "<br /><p>perusvakion vaihto: ".number_format(($prossat['exchange']/100),2,","," ")." &euro;</p>";
  297.  
  298.         //minivakion vaihtoon tarvittava kysely
  299.         $ehm = "{ \"page\": 0, \"pageSize\": 100, \"additionalPrizeTier\": true, \"selections\": [ ";
  300.         $ehm .= "{ \"outcomes\":[\"1\"] }, ";
  301.         $ehm .= "{ \"outcomes\":[\"1\"] }, ";
  302.         $ehm .= "{ \"outcomes\":[\"1\"] }, ";
  303.         $ehm .= "{ \"outcomes\":[\"1\"] }, ";
  304.         $ehm .= "{ \"outcomes\":[\"1\"] }, ";
  305.         $ehm .= "{ \"outcomes\":[\"1\"] }, ";
  306.         $ehm .= "{ \"outcomes\":[\"1\"] } ] }";
  307.  
  308.         // Alustetaan URL
  309.         $host = "https://www.veikkaus.fi";
  310.         $header = array(
  311.             "Accept: application/json",
  312.             "Content-Type: application/json",
  313.             "X-ESA-API-Key: ROBOT"
  314.         );
  315.         $url = $host . "/api/sport-winshare/v1/games/SPORT/draws/".$vakioIdLastWeek."/winshare";
  316.  
  317.         // Alustetaan cURL asetuksineen
  318.         $ch = curl_init();
  319.         curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 0);
  320.         curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0);
  321.         curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
  322.         curl_setopt($ch, CURLOPT_SAFE_UPLOAD, true);
  323.         curl_setopt($ch, CURLOPT_URL, $url);
  324.         curl_setopt($ch, CURLOPT_POST, 1);
  325.         curl_setopt($ch, CURLOPT_POSTFIELDS, $ehm);
  326.         curl_setopt($ch, CURLOPT_HTTPHEADER, $header);
  327.         curl_setopt($ch, CURLOPT_ENCODING, "identity");
  328.  
  329.         // Suoritetaan pyyntö
  330.         $minidata = curl_exec($ch);
  331.  
  332.         // Suljetaan cURL
  333.         curl_close($ch);
  334.  
  335.         // Tarkistetaan että datassa on eloa
  336.         $sub = "exchange";
  337.         if ($data && strpos($data, $sub) !== false) {
  338.             $tuloksetmini = array();
  339.             $tuloksetmini = json_decode($minidata,true);
  340.             echo "<p>minivakion vaihto: ".number_format(($tuloksetmini['exchange']/100),2,","," ")." &euro;</p>";
  341.         }
  342.         echo "<hr class='sep'>";
  343.     }
  344. }
  345.  
  346. //siivotaan jälkiä
  347. if (isset($host)) { unset($host); }
  348. if (isset($header)) { unset($header); }
  349. if (isset($url)) { unset($url); }
  350. if (isset($ch)) { unset($ch); }
  351. if (isset($startNr)) { unset($startNr); }
  352. if (isset($weekNow)) { unset($weekNow); }
  353. if (isset($weekLast)) { unset($weekLast); }
  354. if (isset($vakioIdThisWeek)) { unset($vakioIdThisWeek); }
  355. if (isset($vakioIdLastWeek)) { unset($vakioIdLastWeek); }
  356. if (isset($sub)) { unset($sub); }
  357. if (isset($data)) { unset($data); }
  358. if (isset($minidata)) { unset($minidata); }
  359. if (isset($prossat)) { unset($prossat); }
  360. if (isset($tuloksetmini)) { unset($tuloksetmini); }
  361. if (isset($outcomes)) { unset($outcomes); }
  362. if (isset($teams)) { unset($teams); }
  363. if (isset($ehm)) { unset($ehm); }
  364. if (isset($justNyt)) { unset($justNyt); }
  365. if (isset($active)) { unset($active); }
  366. if (isset($x)) { unset($x); }
  367. if (isset($y)) { unset($y); }
  368. if (isset($z)) { unset($z); }
  369. ?>
  370. </div>
  371. </body>
  372. </html>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement