Last active
August 18, 2017 23:36
-
-
Save tzkmx/eaad6904729b6b58beeac27c754e042b to your computer and use it in GitHub Desktop.
GraphQL Query to get "Hoy no Circula" from SEMOVI
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
require __DIR__ . '/vendor/autoload.php'; | |
function strip_of($subject, $to_strip) { | |
$search = [ $to_strip, ' ', "\t", "\n" ]; | |
return str_replace($search, ['','','',''], $subject); | |
} | |
use Goutte\Client; | |
$client = new Client(); | |
$crawler = $client->request("GET", "http://semovi.cdmx.gob.mx"); | |
$widget = $crawler->filter('#Level-1 .Widget-circulate--sm')->first(); | |
$inclusive = $widget->filter('.Widget-box')->first()->extract('inclu-text')[0]; | |
$date = trim($widget->filter('.Title h4')->first()->text()); | |
$hoynocircula = $widget->filter('.Widget-child-item .Widget-label--lg')->first(); | |
$hoynocircula = [ | |
'terminacion' => $hoynocircula->filter('strong')->text(), | |
'color' => strip_of($hoynocircula->extract('class'), 'Widget-label--lg'), | |
]; | |
$verifican = $widget->filter('.Widget-child-item')->last()->filter('.Widget-label-half') | |
->each(function($node, $i){ | |
return [ | |
'terminacion' => $node->filter('strong')->text(), | |
'color' => strip_of($node->filter('.Widget-label--lg')->extract('class'), 'Widget-label--lg'), | |
]; | |
}); | |
$sabado = $widget->filter('.Widget-child-item')->eq(1)->filter('.Widget-label--lg') | |
->each(function($node, $i){return trim($node->text());}); | |
echo json_encode(compact('inclusive', 'date', 'hoynocircula', 'verifican', 'sabado'), JSON_PRETTY_PRINT); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{ | |
page(url: "http://semovi.cdmx.gob.mx/") { | |
query(selector: "#Level-1 .Widget-circulate--sm") { | |
inclusive: query(selector: ".Widget-box") { | |
text: attr(name: "inclu-text") | |
} | |
date: query(selector: ".Title:first h4") { | |
text: content | |
} | |
hoynocircula: query(selector: ".Widget-child-item:first .Widget-label--lg") { | |
terminacion: query(selector: "strong") { | |
text | |
} | |
color: attr(name: "class") | |
} | |
verifican: query(selector: ".Widget-child-item:last .Widget-label-half") { | |
terminacion: query(selector: "strong") { | |
text | |
} | |
color: query(selector: ".Widget-label--lg") { | |
attr(name: "class") | |
} | |
} | |
sabado: query(selector: ".Widget-child-item:nth-child(2) .Widget-label--lg") { | |
clave: text | |
} | |
} | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
http://gdom.graphene-python.org/graphql?query={%0A page(url%3A "http%3A%2F%2Fsemovi.cdmx.gob.mx%2F") {%0A query(selector%3A "%23Level-1 .Widget-circulate--sm") {%0A inclusive%3A query(selector%3A ".Widget-box") {%0A text%3A attr(name%3A "inclu-text")%0A }%0A date%3A query(selector%3A ".Title%3Afirst h4") {%0A text%3A content%0A }%0A hoynocircula%3A query(selector%3A ".Widget-child-item%3Afirst .Widget-label--lg") {%0A terminacion%3A query(selector%3A "strong") {%0A text%0A }%0A color%3A attr(name%3A "class")%0A }%0A verifican%3A query(selector%3A ".Widget-child-item%3Alast .Widget-label-half") {%0A terminacion%3A query(selector%3A "strong") {%0A text%0A }%0A color%3A query(selector%3A ".Widget-label--lg") {%0A attr(name%3A "class")%0A }%0A }%0A sabado%3A query(selector%3A ".Widget-child-item%3Anth-child(2) .Widget-label--lg") {%0A clave%3A text%0A }%0A }%0A }%0A}%0A |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{ | |
"data": { | |
"page": { | |
"query": [ | |
{ | |
"inclusive": [ | |
{ | |
"text": "Hoy Jueves 17 de agosto de 2017, no circulan vehículos con terminación 1 y 2. Este mes verifican vehículos con terminación 5 y 6 y con terminación 7 y 8." | |
} | |
], | |
"date": [ | |
{ | |
"text": "\n Jueves 17 de agosto de 2017\n " | |
} | |
], | |
"hoynocircula": [ | |
{ | |
"terminacion": [ | |
{ | |
"text": "1 y 2" | |
} | |
], | |
"color": "Widget-label--lg Calc-verde" | |
} | |
], | |
"verifican": [ | |
{ | |
"terminacion": [ | |
{ | |
"text": "5 y 6" | |
} | |
], | |
"color": [ | |
{ | |
"attr": "Widget-label--lg Calc-amarilla" | |
} | |
] | |
}, | |
{ | |
"terminacion": [ | |
{ | |
"text": "7 y 8" | |
} | |
], | |
"color": [ | |
{ | |
"attr": "Widget-label--lg Calc-rosa" | |
} | |
] | |
} | |
], | |
"sabado": [ | |
{ | |
"clave": "H1: Impar" | |
}, | |
{ | |
"clave": "H2: Todos" | |
} | |
] | |
} | |
] | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
A friend suggests using the webservice to get this information instead: