-
Notifications
You must be signed in to change notification settings - Fork 32
/
webhook.php
77 lines (63 loc) · 2.15 KB
/
webhook.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
<?php
include('simple_html_dom.php');
define('BASE_URL',"http://g1.globo.com/loterias/");
define('URL_MEGA', BASE_URL.'megasena.html');
define('URL_QUINA', BASE_URL.'quina.html');
define('URL_LOTOMANIA', BASE_URL.'lotomania.html');
define('URL_LOTOCACIL', BASE_URL.'lotofacil.html');
function getResult($lottery){
$out = "Resultado - ".$lottery;
if($lottery=="Mega-Sena"){
$out .= parser(URL_MEGA);
}elseif($lottery=="Quina"){
$out .= parser(URL_QUINA);
}elseif($lottery=="Lotofácil"){
$out .= parser(URL_LOTOCACIL);
}else{
$out .= parser(URL_LOTOMANIA);
}
return json_encode(array("speech" => $out,
"displayText" => $out));
}
function parser($url){
//obtém o html da página
$html = file_get_html($url);
if (!empty($html)) {
$concurso_header = explode(" - ", $html->find('span.content-lottery__info',0)->plaintext);
$concurso = $concurso_header[0];
$data = $concurso_header[1];
if(!isset($html->find('div[class="content-lottery__ammount desativado"]',0)->plaintext)){
$acumulado = $html->find('div[class="content-lottery__ammount"]',0)->plaintext;
}else{
$acumulado = "Não Acumulou!";
}
$numeros = "";
foreach ($html->find('div[class="content-lottery__result"]') as $numero) {
$numeros .= $numero->plaintext . " ";
}
$premios = "";
foreach ($html->find('div[class="content-lottery__awards"]')[0]->find('tr') as $premio) {
$premios .= "\n" . $premio->find('td.col-acertos',0)->plaintext." - " . $premio->find('td.col-ganhadores',0)->plaintext;
if (strpos($premio->find('td.col-premio',0)->plaintext,"-")==false) {
$premios .= " ganhadores "." - ".$premio->find('td.col-premio',0)->plaintext;
}else{
$premios .= $premio->find('td.col-premio',0)->plaintext;
}
}
return "\n---------------".
"\n".$concurso .
"\nDATA: " . $data .
"\nNÚMEROS: " . $numeros .
"\n".$acumulado.
"\n---------------".
"\nPREMIAÇÕES" . $premios;
}else{
return "\nNão encontrado";
}
}
$update_response = file_get_contents("php://input");
$update = json_decode($update_response, true);
if (isset($update["result"]["parameters"]["Jogos"])) {
echo getResult($update["result"]["parameters"]["Jogos"]);
}
?>