source: trunk/Modules/Meet/Import/TanecniSkola.php

Last change on this file was 69, checked in by chronos, 13 months ago
  • Modified: Updated parsing of web tanecniskola.cz.
File size: 4.4 KB
Line 
1<?php
2
3class MeetSourceTanecniSkola extends MeetSource
4{
5 function Import(): string
6 {
7 $Output = parent::Import();
8 $HeightRange = array(
9 '< 120 cm' => 120,
10 '120 cm - 130 cm' => 125,
11 '125 cm - 135 cm' => 130,
12 '130 cm - 140 cm' => 135,
13 '135 cm - 145 cm' => 140,
14 '140 cm - 150 cm' => 145,
15 '145 cm - 155 cm' => 150,
16 '150 cm - 160 cm' => 155,
17 '155 cm - 165 cm' => 160,
18 '160 cm - 170 cm' => 165,
19 '165 cm - 175 cm' => 170,
20 '170 cm - 180 cm' => 175,
21 '175 cm - 185 cm' => 180,
22 '180 cm - 190 cm' => 185,
23 '185 cm - 195 cm' => 190,
24 '190 cm - 200 cm' => 195,
25 '195 cm - 205 cm' => 200,
26 '200 cm <' => 205,
27 );
28 $Content = file_get_contents($this->URL);
29
30 $BlockStart = 'data-content="inzeraty">';
31 $BlockEnd = '</section>';
32 $Content = GetTextBetween($Content, $BlockStart, $BlockEnd);
33 if ($Content == '')
34 {
35 $Output .= 'Main block not isolated.</br>';
36 return $Output;
37 }
38
39 $ItemStart = '<div class="item item-dating">';
40 $ItemEnd = 'Odpovědět na inzerát</a></p>';
41 $PreviousTime = null;
42 while (strpos($Content, $ItemStart) !== false)
43 {
44 $Item = GetTextBetween($Content, $ItemStart, $ItemEnd);
45 if ($Item != '')
46 {
47 $MeetItem = new MeetItem();
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);
66 if ($MeetItem->Time != null)
67 {
68 $PreviousTime = $MeetItem->Time;
69 } else $MeetItem->Time = $PreviousTime;
70
71 $Part = GetTextBetween($Item, '<h2>', '</h2>');
72 if (strpos($Part, '(') !== false)
73 {
74 $MeetItem->Name = substr($Part, 0, strpos($Part, '('));
75 $MeetItem->Age = substr($Part, strpos($Part, '(') + 1);
76 $MeetItem->Age = substr($MeetItem->Age, 0, strpos($MeetItem->Age, ')'));
77 $MeetItem->Age = trim(str_replace('let', '', $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>'));
90 while (strpos($MeetItem->Height, ' ') !== false)
91 {
92 $MeetItem->Height = str_replace(' ', ' ', $MeetItem->Height);
93 }
94 if (array_key_exists($MeetItem->Height, $HeightRange))
95 $MeetItem->Height = $HeightRange[$MeetItem->Height];
96
97 $MeetItem->Message = trim(GetTextBetween($Item, '<p>', '</p>'));
98
99 $MeetItem->Email = GetEmailFromText($MeetItem->Message);
100 $MeetItem->Weight = GetWeightFromText($MeetItem->Message);
101
102 // Update age only if it is not set already
103 if ($MeetItem->Age == '')
104 {
105 $MessageAge = GetAgeFromText($MeetItem->Message);
106 if ($MessageAge != '') $MeetItem->Age = $MessageAge;
107 }
108
109 // Update height from message text even if height is already set
110 // because it can be more precise
111 $MessageHeight = GetHeightFromText($MeetItem->Message);
112 if ($MessageHeight != '') $MeetItem->Height = $MessageHeight;
113
114 $MeetItem->Location = 'Praha';
115 $MeetItem->Database = $this->Database;
116 $MeetItem->Source = $this->Id;
117 //print_r($MeetItem);
118 $this->MeetItems[] = $MeetItem;
119 }
120 }
121 return $Output;
122 }
123}
124
Note: See TracBrowser for help on using the repository browser.