Skip to content

Instantly share code, notes, and snippets.

@hallboav
Last active February 3, 2019 00:30
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save hallboav/32231f89f3799ebcde6f9ec0e9b60e69 to your computer and use it in GitHub Desktop.
Save hallboav/32231f89f3799ebcde6f9ec0e9b60e69 to your computer and use it in GitHub Desktop.
Look for Brazilians certified by SensioLabs.
{
"require": {
"fabpot/goutte": "^3.2",
"symfony/console": "^4.2"
}
}
<?php
use Goutte\Client;
use Symfony\Component\DomCrawler\Crawler;
use Symfony\Component\Console\Helper\Table;
use Symfony\Component\Console\Output\ConsoleOutput;
use Symfony\Component\Console\Formatter\OutputFormatterStyle;
require_once 'vendor/autoload.php';
$pages = [
[
'title' => 'SFCE (Expert)',
'url' => 'https://connect.symfony.com/badge/58/sensiolabs-certified-symfony-developer-expert',
],
[
'title' => 'SFCE (Advanced)',
'url' => 'https://connect.symfony.com/badge/70/sensiolabs-certified-symfony-developer-advanced',
],
[
'title' => 'SF3CE (Advanced)',
'url' => 'https://connect.symfony.com/badge/98/symfony-3-certified-developer-advanced',
],
[
'title' => 'SF3CE (Expert)',
'url' => 'https://connect.symfony.com/badge/97/symfony-3-certified-developer-expert',
],
[
'title' => 'SF4CE (Advanced)',
'url' => 'https://connect.symfony.com/badge/122/symfony-4-certified-developer-advanced',
],
[
'title' => 'SF4CE (Expert)',
'url' => 'https://connect.symfony.com/badge/123/symfony-4-certified-developer-expert',
],
];
$client = new Client();
$output = new ConsoleOutput();
$firefly = new OutputFormatterStyle('green', 'default', ['bold', 'blink']);
$output->getFormatter()->setStyle('firefly', $firefly);
foreach ($pages as $page) {
$rows = [];
$crawler = $client->request('GET', $page['url']);
$users = $crawler->filter('.badge-container > li > a');
$count = $users->count();
$users->each(function (Crawler $anchor) use ($client, &$rows) {
$link = current($anchor->links());
$profile = $client->click($link)->filter('#profile-username-container');
$name = $profile->filter('h1[itemprop=name]')->text();
$country = $profile->filter('span[itemprop=addressCountry]')->text();
$rows[] = [
'name' => trim($name, "\x20\x9\xa\xD\x0\xb\xe2\x9c\x8c\xef\xb8\x8f"),
'country' => $country,
'brazilian' => 'Brazil' === $country ? '<firefly>Yep!</>' : 'No',
];
});
$table = new Table($output);
$table->setHeaders(['Name', 'Country', 'Brazilian'])
->setColumnWidths([30, 30, 0])
->setHeaderTitle(sprintf('%s (%d)', $page['title'], $count))
->setRows($rows)
->render();
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment