예제 #1
0
파일: scrape.php 프로젝트: hubgit/ecsstract
        debug(count($nodes) . ' nodes');
        foreach ($nodes as $node) {
            if ($result = parse_item($node, $defs, $fix)) {
                $items[] = $result;
            }
        }
        $next = array();
        if ($defs->next) {
            foreach ($dom->query($defs->next) as $node) {
                $next[] = base_url($node->getAttribute('href'));
            }
        }
    } while (!empty($next) && !isset($visited[$next[0]]) && ++$count != 5);
    // max 5 pages
    //debug($items); exit();
    ical($defs, $items);
}
function parse_item($node, $defs, $fix)
{
    $d = new DOMDocument();
    $d->appendChild($d->importNode($node, TRUE));
    $zend = new Zend_Dom_Query($d->saveHTML());
    //debug($d->saveHTML());
    $properties = array();
    foreach ($defs->properties as $property => $def) {
        if (is_string($def)) {
            $def = (object) array('selector' => $def);
        }
        //debug($def);
        if ($def->selector) {
            $t = array();
예제 #2
0
#!/usr/bin/env php
<?php 
require __DIR__ . '/../main.inc.php';
$calendar_name = 'Kings Place Tuesdays';
$url = 'http://www.kingsplace.co.uk/music/this-is-tuesday';
$dom = url_html_zend($url);
$items = $dom->query('p.prod-event');
$events = array();
foreach ($items as $item) {
    $xml = simplexml_import_dom($item);
    $a = $xml->strong[0]->a;
    $title = (string) $a;
    $link = (string) $a['href'];
    unset($xml->strong[0]);
    unset($xml->br);
    $text = strip_tags((string) $xml);
    preg_match('/Time:\\s+(.+?\\))/s', $text, $matches);
    if (empty($matches)) {
        continue;
    }
    $date_string = filter_var($matches[1], FILTER_UNSAFE_RAW, FILTER_FLAG_STRIP_HIGH | FILTER_FLAG_STRIP_LOW);
    $date_string = preg_replace('/\\s+/', ' ', $date_string);
    $date = DateTime::createFromFormat('H:i  (l j F)', $date_string);
    $start = $date->getTimestamp();
    $end = $start + 3600 * 2;
    // 2hr
    $description = preg_replace('/\\b(To benefit from lower priced seats|Time:) .*/s', '', $text);
    $events[] = array('start' => $start, 'end' => $end, 'uri' => make_link($link), 'summary' => strip_tags($title), 'description' => strip_tags($description), 'location' => 'Kings Place');
}
ical($calendar_name, $events);