Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Diesel price of JET petrol station in Penzberg (melody script)
<?php
<<<CONFIG
packages:
- "fabpot/goutte: ^3.1"
- "symfony/console: ^3.1"
CONFIG;
use Goutte\Client;
use Symfony\Component\Console\Input\ArrayInput;
use Symfony\Component\Console\Output\ConsoleOutput;
use Symfony\Component\Console\Style\SymfonyStyle;
use Symfony\Component\DomCrawler\Crawler;
$page = 'http://www.clever-tanken.de/tankstelle_details/2039';
$client = new Client();
$crawler = $client->request('GET', $page);
$price = (float) trim($crawler->filter('.fuel-price-entry .price-field > span')->text());
switch ($price) {
case ($price >= 1.10):
$highlight = 'fg=red';
break;
case ($price <= 1.05):
$highlight = 'fg=yellow';
break;
case ($price < 1):
$highlight = 'fg=green';
break;
default:
$highlight = 'fg=white';
break;
}
$updateInfo = trim($crawler->filter('.fuel-price-header')->text());
preg_match('/Letzte Aktualisierung: (.*)/', $updateInfo, $matches);
$io = new SymfonyStyle(new ArrayInput([]), new ConsoleOutput());
$io->writeln(sprintf('<%3$s>%1$02.2f EUR</%3$s> (%2$s)', $price, $matches[1], $highlight));
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment