Example #1
0
$url_pattern = 'http://localhost/bmtmgr/import/clubs/blv_club_kontakte.php%%3fid=%d';
$imported_clubs = [];
$not_found_since = 0;
Model::beginTransaction();
for ($i = 1; $i < 100000; $i++) {
    $url = \sprintf($url_pattern, $i);
    $page = \file_get_contents($url);
    $r = \preg_match('/
		<label>ClubID:<\\/label><div>(?P<id>[0-9-]+)<\\/div>.*
		<label>Vereinsname:<\\/label><div>(?P<name>[^<]+)<\\/div>.*
		<label>Email:<\\/label><div><a.*?>(?P<email>[^<]+)<\\/a>
		/xs', $page, $m);
    if (!$r) {
        $not_found_since++;
        if ($not_found_since > 100) {
            break;
        }
        continue;
    }
    $id = \html_entity_decode($m['id'], ENT_QUOTES | ENT_HTML5, 'utf-8');
    $name = \html_entity_decode($m['name'], ENT_QUOTES | ENT_HTML5, 'utf-8');
    $email = \html_entity_decode($m['email'], ENT_QUOTES | ENT_HTML5, 'utf-8');
    $c = User::by_id_optional($id);
    if (!$c) {
        $c = new User($id, $name, $email, ['register']);
        $c->save();
        \array_push($imported_clubs, $c);
    }
}
Model::commit();
render_ajax('club/', ['imported_clubs' => $imported_clubs]);
Example #2
0
if (!preg_match('#<div id="divTournamentHeader" class="header">\\s*<div class="title"><h3>(.*)</h3>#', $clubs_content, $m)) {
    throw new \Exception('Cannot find season name');
}
$name = \html_entity_decode($m[1], ENT_QUOTES | ENT_HTML5, 'utf-8');
Model::beginTransaction();
$season = Season::fetch_optional('WHERE name=?', [$name]);
if (!$season) {
    $season = Season::create($name, false, $_POST['tournament_url']);
    $season->save();
}
$players = [];
if (!\preg_match_all('#<td><a href="club\\.aspx(?P<club_path>\\?id=[^"]+)&club=(?P<club_num>[0-9]+)">(?P<name>[^<]+)</a></td><td class="right">(?P<id>[0-9-]+)</td>#', $clubs_content, $matches, PREG_SET_ORDER)) {
    throw new \Exception('Cannot find any club entries!');
}
foreach ($matches as $m) {
    $club = User::by_id_optional($m['id']);
    if (!$club) {
        $club = new User($m['id'], $m['name'], null, ['register']);
        $club->save();
    }
    $players_url = $base_url . 'clubplayers.aspx' . $m['club_path'] . '&cid=' . $m['club_num'];
    $players_page = \file_get_contents($players_url);
    $genders = ['Männer' => 'm', 'Frauen' => 'f'];
    if (!\preg_match_all('#<caption>\\s*(?<gender_str>Männer|Frauen)\\s*</caption><thead>(?P<table>.*?)</tbody>#s', $players_page, $player_table_m, \PREG_SET_ORDER)) {
        continue;
        // Some clubs don't have any players associated with them (because of merger etc.)
    }
    foreach ($player_table_m as $table_m) {
        $g = $genders[$table_m['gender_str']];
        $table = $table_m['table'];
        preg_match_all('#