This repository was archived by the owner on Feb 8, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathEczane.php
More file actions
109 lines (84 loc) · 2.71 KB
/
Eczane.php
File metadata and controls
109 lines (84 loc) · 2.71 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
<?php
require "simple_html_dom.php";
/**
* @author: Tolga CESUR
* @website: tolgacesur.com
* @website : api.eczanapp.space
*
*/
class Eczane
{
function __construct($city)
{
$this->city = $city;
$this->baseUrl = "http://".$this->ConvertString($this->city).".eczaneleri.org/";
$this->pharmacyList = [];
$this->html = str_get_html($this->fetchData($this->baseUrl));
if($this->html === FALSE) {
exit("Lütfen Geçerli Bir İl Giriniz.");
}
$this->parse();
}
private function parse() {
$list = $this->html->find('div.active ul.media-list li');
foreach ($list as $item) {
$div = $item->children(0);
$info = $div->children(0)->children(0)->plaintext;
$info = explode("Eczanesi", $info);
$name = rtrim(ltrim($info[0]));
$district = rtrim(ltrim($info[1]));
$address = $div->innertext;
$address = explode("</a>", $address);
$address = $address[1];
$address = explode("<br />", $address);
$address = rtrim(ltrim($address[0]));
$address_url = $address.'+'.$district.'+'.$name.'+Eczanesi';
$address_url = str_replace(' ', '%20', $address_url);
$googleApiUrl = 'https://maps.googleapis.com/maps/api/geocode/json?address='.$address_url.'+Turkey&key=AIzaSyDAR3ctfLepWdXOgrHKobyfRlq7C87Nl4M';
$google = $this->fetchData($googleApiUrl);
$google = json_decode($google);
$result['name'] = $name.' '.'Eczanesi';
$resul['city'] = $this->city;
$result['district'] = $district;
$result['address'] = $address;
if (!empty($google->results)) {
$lat = $google->results[0]->geometry->location->lat;
$lng = $google->results[0]->geometry->location->lng;
$result['lat'] = $lat;
$result['lng'] = $lng;
}
array_push($this->pharmacyList, $result);
}
}
public function getPharmacy() {
return json_encode($this->pharmacyList);
}
private function fetchData($url) {
$curl_handle=curl_init();
curl_setopt($curl_handle, CURLOPT_URL,$url);
curl_setopt($curl_handle, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($curl_handle, CURLOPT_SSL_VERIFYPEER, false);
$data = curl_exec($curl_handle);
curl_close($curl_handle);
return $data;
}
/**
*
* @param String $s
*
* @return $s
*/
private function ConvertString($s) {
$tr = array('ş','Ş','ı','İ','ğ','Ğ','ü','Ü','ö','Ö','Ç','ç');
$eng = array('s','s','i','i','g','g','u','u','o','o','c','c');
$s = str_replace($tr,$eng,$s);
$s = strtolower($s);
$s = preg_replace('/&.+?;/', '', $s);
$s = preg_replace('/[^%a-z0-9 _-]/', '', $s);
$s = preg_replace('/\s+/', '-', $s);
$s = preg_replace('|-+|', '-', $s);
$s = trim($s, '-');
return $s;
}
}
?>