Skip to content

Commit 52dd194

Browse files
committed
added example and updated readme
1 parent 1047c1c commit 52dd194

File tree

6 files changed

+335
-76
lines changed

6 files changed

+335
-76
lines changed

.idea/workspace.xml

Lines changed: 8 additions & 8 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

README.md

Lines changed: 93 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,93 @@
1-
# nobetcieczane
2-
Türkiye Nöbetçi Eczaneler
1+
# Eczane Scraper Kütüphanesi
2+
3+
**Eczane Scraper**, Türkiye'deki eczanelerin listesini ve detaylı bilgilerini kolayca çekebilmenizi sağlayan bir PHP kütüphanesidir.
4+
5+
---
6+
7+
## Özellikler (Features)
8+
9+
- **Eczane Listesi Çekimi**: Seçtiğiniz şehirdeki nöbetçi eczanelerin listesini alabilirsiniz.
10+
- **Detaylı Bilgi**: Bir eczanenin telefon, adres, harita konumu gibi detaylarını kolayca çekin.
11+
- **Hızlı ve Güvenilir**: Verileri çekerken cURL kullanır, UTF-8 desteklidir ve hataları düzgün bir şekilde ele alır.
12+
13+
---
14+
15+
## Kurulum (Installation)
16+
17+
Bu kütüphaneyi projelerinize dahil etmek için aşağıdaki adımları izleyin:
18+
19+
### Composer ile Yükleme (Install with Composer)
20+
```bash
21+
composer require ahmeterdgn/nobetcieczane
22+
```
23+
### Manuel Kurulum (Manual Installation)
24+
#### 1. Bu depoyu indirin:
25+
```bash
26+
git clone https://github.com/uzmoon/eczane-scraper.git
27+
```
28+
#### 2. Projenize dahil edin:
29+
```php
30+
require 'path/to/EczaneScraper.php';
31+
```
32+
33+
## Kullanım (Usage)
34+
35+
#### Eczane Listesi Çekme (Fetching Pharmacy List)
36+
```php
37+
require 'vendor/autoload.php';
38+
39+
use Uzmoon\EczaneScraper;
40+
41+
$scraper = new EczaneScraper('istanbul');
42+
$data = $scraper->scrape('https://example.com/?city=istanbul&link=');
43+
print_r($data);
44+
```
45+
#### Detaylı Bilgi Çekme (Fetching Detailed Info)
46+
```php
47+
require 'vendor/autoload.php';
48+
49+
use Uzmoon\EczaneScraper;
50+
51+
$scraper = new EczaneScraper('ankara');
52+
$details = $scraper->detail('eczane-link');
53+
print_r($details);
54+
```
55+
## Geri Bildirim (Feedback)
56+
57+
Kütüphaneyi kullanırken karşılaştığınız hataları bildirmek veya geliştirme önerilerinde bulunmak için [GitHub Issues](https://github.com/ahmeterdgn/nobetcieczane/issues) sayfasını kullanabilirsiniz.
58+
59+
- **Hata Raporlama**: Karşılaştığınız hataları GitHub Issues üzerinden bildirebilirsiniz. Hata raporlarınızı daha hızlı çözebilmemiz için aşağıdaki bilgileri eklemeyi unutmayın:
60+
- Hata mesajı veya ekran görüntüsü
61+
- Adım adım nasıl tekrar edileceği (bug’un nasıl tekrarlanabileceğine dair talimatlar)
62+
- Kullandığınız PHP versiyonu ve işletim sistemi
63+
64+
- **Özellik İstekleri ve İyileştirme Teklifleri**: Kütüphaneye yeni özellikler eklemek veya mevcut özellikleri geliştirmek için GitHub Issues sayfasına önerilerinizi yazabilirsiniz.
65+
## Lisans (License)
66+
MIT License
67+
68+
Copyright (c) 2024 Ahmet Erdoğan
69+
70+
Permission is hereby granted, free of charge, to any person obtaining a copy
71+
of this software and associated documentation files (the "Software"), to deal
72+
in the Software without restriction, including without limitation the rights
73+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
74+
copies of the Software, and to permit persons to whom the Software is
75+
furnished to do so, subject to the following conditions:
76+
77+
The above copyright notice and this permission notice shall be included in all
78+
copies or substantial portions of the Software.
79+
80+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
81+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
82+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
83+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
84+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
85+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
86+
SOFTWARE.
87+
88+
## İletişim (Contact)
89+
90+
**Yazar**: Ahmet Erdoğan
91+
**Websitesi**: [uzmoon.com](https://uzmoon.com)
92+
**GitHub**: [Ahmeterdgn](https://github.com/ahmeterdgn)
93+
**E-posta**: [[email protected]](mailto:[email protected])

composer.json

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,9 @@
1414
}
1515
],
1616
"require": {
17-
"php": ">=7.4"
17+
"php": ">=7.4",
18+
"ext-curl": "*",
19+
"ext-mbstring": "*"
1820
},
1921
"autoload": {
2022
"psr-4": {

examples/test.php

Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
<?php
2+
3+
use nobetcieczane\EczaneScraper;
4+
include '../vendor/autoload.php';
5+
6+
try {
7+
$city = filter_input(INPUT_GET, 'city', FILTER_SANITIZE_STRING) ?? 'istanbul';
8+
9+
$scraper = new EczaneScraper($city);
10+
11+
header('Content-Type: application/json; charset=utf-8');
12+
13+
if (isset($_GET['link'])) {
14+
$link = filter_input(INPUT_GET, 'link', FILTER_SANITIZE_URL);
15+
$response = $scraper->detail($link);
16+
}
17+
elseif (isset($_GET['city'])) {
18+
$domain = $_SERVER['HTTP_HOST'];
19+
20+
$protocol = isset($_SERVER['HTTPS']) && $_SERVER['HTTPS'] === 'on' ? "https" : "http";
21+
$fullUrl = $protocol . "://" . $domain;
22+
23+
$response = $scraper->scrape($fullUrl.'/eczane/?city=' . urlencode($city) . '&link=');
24+
}
25+
else {
26+
$cities = $scraper->cities();
27+
$response = generateCityListHtml($cities);
28+
header('Content-Type: text/html; charset=utf-8');
29+
}
30+
31+
echo is_array($response) ? json_encode($response, JSON_PRETTY_PRINT | JSON_UNESCAPED_UNICODE) : $response;
32+
} catch (Exception $e) {
33+
http_response_code(500);
34+
echo json_encode([
35+
'error' => true,
36+
'message' => $e->getMessage(),
37+
]);
38+
}
39+
40+
/**
41+
* Generate the city list in HTML format
42+
*
43+
* @param array $cities Array of city keys and values
44+
* @return string HTML output
45+
*/
46+
function generateCityListHtml(array $cities): string
47+
{
48+
$html = '<h1>Şehir Listesi</h1>';
49+
$html .= '<ul>';
50+
foreach ($cities as $key => $item) {
51+
$html .= '<li><a href="?city=' . htmlspecialchars($key) . '">' . htmlspecialchars($item) . '</a></li>';
52+
}
53+
$html .= '</ul>';
54+
return $html;
55+
}

0 commit comments

Comments
 (0)