Changeset 69 for trunk


Ignore:
Timestamp:
Nov 15, 2023, 12:40:49 AM (13 months ago)
Author:
chronos
Message:
  • Modified: Updated parsing of web tanecniskola.cz.
File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/Modules/Meet/Import/TanecniSkola.php

    r63 r69  
    2828    $Content = file_get_contents($this->URL);
    2929
    30     $BlockStart = '<div><!--[if IE]><input type=IEbug disabled style="display:none"><![endif]--></div>';
    31     $BlockEnd = '</article>';
     30    $BlockStart = 'data-content="inzeraty">';
     31    $BlockEnd = '</section>';
    3232    $Content = GetTextBetween($Content, $BlockStart, $BlockEnd);
    3333    if ($Content == '')
     
    3737    }
    3838
    39     $ItemStart = '<div>';
    40     $ItemEnd = '</div>';
     39    $ItemStart = '<div class="item item-dating">';
     40    $ItemEnd = 'Odpovědět na inzerát</a></p>';
    4141    $PreviousTime = null;
    4242    while (strpos($Content, $ItemStart) !== false)
     
    4646      {
    4747        $MeetItem = new MeetItem();
    48         $MeetItem->Time = HumanDateToTime(trim(GetTextBetween($Item, '<h3>', '</h3>')));
     48        $Time = trim(GetTextBetween($Item, '<p class="date">', '</p>'));
     49        if ($Time == 'Včera') $Time = HumanDate(time() - 60*60*24);
     50        else if ($Time == 'Dnes') $Time = HumanDate(time());
     51        else {
     52          $Time = str_replace('ledna', '1.', $Time);
     53          $Time = str_replace('února', '2.', $Time);
     54          $Time = str_replace('března', '3.', $Time);
     55          $Time = str_replace('dubna', '4.', $Time);
     56          $Time = str_replace('května', '5.', $Time);
     57          $Time = str_replace('června', '6.', $Time);
     58          $Time = str_replace('července', '7.', $Time);
     59          $Time = str_replace('srpna', '8.', $Time);
     60          $Time = str_replace('září', '9.', $Time);
     61          $Time = str_replace('října', '10.', $Time);
     62          $Time = str_replace('listopadu', '11.', $Time);
     63          $Time = str_replace('prosince', '1.', $Time);
     64        }
     65        $MeetItem->Time = HumanDateToTime($Time);
    4966        if ($MeetItem->Time != null)
    5067        {
     
    5269        } else $MeetItem->Time = $PreviousTime;
    5370
    54         $Part = GetTextBetween($Item, '</strong>', '<strong>');
    55         $Part = explode(',', $Part);
    56         if (count($Part) > 0) $MeetItem->Name = trim($Part[0]);
    57         if (count($Part) > 1) $MeetItem->Height = trim($Part[1]);
    58         if (strpos($MeetItem->Height, '(') !== false)
     71        $Part = GetTextBetween($Item, '<h2>', '</h2>');
     72        if (strpos($Part, '(') !== false)
    5973        {
    60           $MeetItem->Age = substr($MeetItem->Height, strpos($MeetItem->Height, '(') + 1);
     74          $MeetItem->Name = substr($Part, 0, strpos($Part, '('));
     75          $MeetItem->Age = substr($Part, strpos($Part, '(') + 1);
    6176          $MeetItem->Age = substr($MeetItem->Age, 0, strpos($MeetItem->Age, ')'));
    6277          $MeetItem->Age = trim(str_replace('let', '', $MeetItem->Age));
    63           $MeetItem->Height = trim(substr($MeetItem->Height, 0, strpos($MeetItem->Height, '(')));
    64         } else $MeetItem->Age = '';
     78        } else
     79        {
     80          $MeetItem->Name = $Part;
     81          $MeetItem->Age = '';
     82        }
     83
     84        $Gender = trim(GetTextBetween($Item, '</em>', '</p></div>'));
     85        if ($Gender == 'Hledám partnera') $MeetItem->Gender = Gender::Female;
     86          else if ($Gender == 'Hledám partnerku') $MeetItem->Gender = Gender::Male;
     87          else $MeetItem->Gender = Gender::Undefined;
     88
     89        $MeetItem->Height = trim(GetTextBetween($Item, '<div class="item py-5 px-10"><p><em class="fa fa-ruler"></em>', '</p></div>'));
    6590        while (strpos($MeetItem->Height, '  ') !== false)
    6691        {
     
    6994        if (array_key_exists($MeetItem->Height, $HeightRange))
    7095          $MeetItem->Height = $HeightRange[$MeetItem->Height];
    71         $MeetItem->Email = trim(GetTextBetween($Item, '">', '</a>'));
    72         $MeetItem->Phone = trim(GetTextBetween($Item, 'tel.:', '<br />'));
    73         $Gender = trim(GetTextBetween($Item, '</strong>', '<strong>'));
    74         if ($Gender == 'partnera,') $MeetItem->Gender = Gender::Female;
    75           else if ($Gender == 'partnerku,') $MeetItem->Gender = Gender::Male;
    76           else $MeetItem->Gender = Gender::Undefined;
    77         $MeetItem->Message = trim(GetTextBetween($Item, '<p class="message">', '</p>'));
     96
     97        $MeetItem->Message = trim(GetTextBetween($Item, '<p>', '</p>'));
     98
     99        $MeetItem->Email = GetEmailFromText($MeetItem->Message);
    78100        $MeetItem->Weight = GetWeightFromText($MeetItem->Message);
     101       
    79102        // Update age only if it is not set already
    80103        if ($MeetItem->Age == '')
     
    83106          if ($MessageAge != '') $MeetItem->Age = $MessageAge;
    84107        }
     108       
    85109        // Update height from message text even if height is already set
    86110        // because it can be more precise
    87111        $MessageHeight = GetHeightFromText($MeetItem->Message);
    88112        if ($MessageHeight != '') $MeetItem->Height = $MessageHeight;
     113
    89114        $MeetItem->Location = 'Praha';
    90115        $MeetItem->Database = $this->Database;
    91116        $MeetItem->Source = $this->Id;
     117        //print_r($MeetItem);
    92118        $this->MeetItems[] = $MeetItem;
    93119      }
Note: See TracChangeset for help on using the changeset viewer.