Kandilli Rasathanesi (Boğaziçi Üniversitesi) · AFAD (Afet ve Acil Durum Yönetimi Başkanlığı)
Canlı veri · 5 dakikada bir otomatik güncelleme · GeoJSON uyumlu çıktı · CORS açık
Earthquake API, Türkiye'nin iki büyük deprem veri kaynağından — Kandilli Rasathanesi ve AFAD — canlı veri çeken, 5 dakikada bir otomatik güncellenen ve GeoJSON uyumlu temiz bir JSON çıktısı sunan hafif bir Flask API'sidir.
Kurulumu saniyeler sürer, harici veritabanı gerektirmez, tüm veriyi bellekte tutar ve web uygulamalarınıza, mobil uygulamalarınıza, harita dashboard'larınıza veya GIS araçlarınıza (Leaflet, Mapbox, QGIS) doğrudan bağlanabilir.
Neden Earthquake API? Çünkü iki ayrı kaynağı tek bir tutarlı şemada birleştirir, bir kaynak düşse bile diğeri çalışmaya devam eder ve thread-safe bir mimariyle Flask'ı asla bloke etmez.
| 🌍 | ⏱️ | 🔎 | 📦 |
|---|---|---|---|
| İki kaynak, tek API | Otomatik güncelleme | Zengin filtreleme | GeoJSON uyumlu |
| Kandilli + AFAD aynı şemada | Her 5 dakikada bir | Konum, büyüklük veya ikisi | Leaflet, Mapbox, QGIS |
| 🧵 | 🛡️ | ❤️ | 🪶 |
|---|---|---|---|
| Thread-safe mimari | Hata izolasyonu | /health endpoint |
Hafif |
threading.Lock ile korunur |
Bir kaynak düşse diğeri çalışır | Canlılık + tazelik kontrolü | Flask + BS4 + schedule |
|
|
| Katman | Teknoloji |
|---|---|
| Backend | Python 3.10+, Flask 3.0 |
| HTML Parsing | BeautifulSoup4 |
| Zamanlayıcı | schedule + threading |
| HTTP Client | urllib (standart kütüphane) |
| Eşzamanlılık | threading.Lock (thread-safe buffer) |
| Çıktı | JSON (GeoJSON uyumlu) |
- Python 3.10 veya üzeri
- pip
# 1. Repoyu klonla
git clone https://github.com/mdaedalus/Earthquake-api.git
cd Earthquake-api
# 2. Sanal ortam oluştur
python -m venv venv
# Windows:
venv\Scripts\activate
# macOS/Linux:
source venv/bin/activate
# 3. Bağımlılıkları yükle
pip install -r requirements.txt
# 4. API'yi başlat
python app.pyTarayıcınızda açın: http://localhost:5000
Not:
requestskütüphanesi kullanılmıyor — HTTP istekleri standart kütüphanedekiurllibile yapılıyor.
GET /| Parametre | Tip | Açıklama | Örnek |
|---|---|---|---|
type |
string | Kaynak: kandilli (varsayılan) veya afad |
?type=afad |
location |
string | Şehir / ilçe filtresi (case-insensitive) | ?location=Izmir |
size |
float | Minimum büyüklük (md/ml/mw arasından en büyüğü) | ?size=4.5 |
# Kandilli'den son depremler
curl http://localhost:5000/
# AFAD'dan son depremler
curl http://localhost:5000/?type=afad
# İzmir'deki depremler
curl http://localhost:5000/?location=Izmir
# 4.0 ve üzeri büyüklükteki depremler
curl http://localhost:5000/?size=4
# Ankara'da 3.0 ve üzeri depremler
curl http://localhost:5000/?size=3&location=Ankara
# Sağlık kontrolü
curl http://localhost:5000/health{
"type": "FeatureCollection",
"metadata": {
"generated": "2025-01-15 14:32:00 UTC",
"last_updated": "2025-01-15 14:30:00 UTC",
"title": "Earthquake API",
"api_version": "1.0.0",
"source": "kandilli",
"count": 42,
"errors": {}
},
"features": [
{
"type": "Feature",
"properties": {
"mag": { "md": 0, "ml": 4.2, "mw": 0 },
"place": "IZMIR KORFEZI",
"time": 1736958720,
"updated": 1736958720,
"status": "İlksel",
"type": "earthquake",
"title": "M 4.2 - IZMIR KORFEZI",
"depth": 7.3
},
"geometry": {
"type": "Point",
"coordinates": [26.85, 38.42, 7.3]
},
"id": "kandilli-1736958720-483921",
"source": "kandilli"
}
]
}GET /health{
"status": "ok",
"last_updated": "2025-01-15 14:30:00 UTC",
"kandilli_count": 42,
"afad_count": 38,
"errors": {}
}| Adres | Yaptığı İş |
|---|---|
/ |
Tüm depremler (varsayılan: Kandilli) |
/?type=afad |
AFAD kaynağından depremler |
/?type=kandilli |
Kandilli kaynağından depremler |
/?location=<il> |
Belirtilen ildeki depremler |
/?size=<büyüklük> |
Belirtilen büyüklük ve üzeri |
/?size=<b>&location=<il> |
Hem konum hem büyüklük filtresi |
/health |
Canlılık ve veri tazeliği kontrolü |
Earthquake-api/
├── app.py # Ana Flask uygulaması
├── requirements.txt
├── LICENSE # MIT
├── README.md
├── .gitignore
└── img/ # 📸 Ekran görüntüleri
⏱️ Güncelleme Sıklığı
update_data() çağrısının sıklığını değiştirmek için:
UPDATE_INTERVAL_MINUTES = 5 # 5 dakika
UPDATE_INTERVAL_MINUTES = 1 # 1 dakika🌐 Port ve Host
app.run() satırını düzenleyin:
app.run(host="0.0.0.0", port=8080, debug=False)🔒 CORS Politikası
Tüm domain'lere açmak yerine belirli bir domain'e kısıtlamak için:
response.headers["Access-Control-Allow-Origin"] = "https://siteniz.com"🔎 Filtre Genişletme
Yeni filtreler eklemek için index() fonksiyonundaki if/elif zincirini genişletin:
depth = request.args.get("depth")
if depth:
data = [d for d in data if d["properties"]["depth"] >= float(depth)]- 🟢 v0.1 — Kandilli scraper
- 🟢 v0.2 — AFAD scraper
- 🟢 v0.3 — Thread'li otomatik güncelleme
- 🟢 v0.4 — Konum & büyüklük filtreleri
- 🟢 v0.5 — GeoJSON uyumlu çıktı
- 🟢 v0.6 — CORS desteği
- 🟢 v0.7 — Thread-safe buffer +
/healthendpoint - 🟡 v0.8 — Tarih aralığı filtresi (
?from=2025-01-01&to=2025-01-31) - 🟡 v0.9 — Derinlik filtresi (
?depth=10) - 🟡 v1.0 — CSV / GeoJSON export endpoint'leri
- 🟠 v1.1 — WebSocket canlı akış
- 🟠 v1.2 — Redis cache katmanı
- 🟠 v1.3 — Prometheus metrics
- 🟠 v1.4 — Rate limiting
- 🔴 v1.5 — Docker imajı
- 🔴 v2.0 — Harici deprem API'leri (USGS, EMSC) entegrasyonu
Katkılarınızı bekliyoruz! Büyük değişiklikler için önce bir issue açın.
# Fork → Clone → Branch → Commit → Push → PR
git checkout -b feature/yeni-ozellik
git commit -m "feat: yeni özellik eklendi"
git push origin feature/yeni-ozellik| Prefix | Anlamı |
|---|---|
feat: |
yeni özellik |
fix: |
hata düzeltme |
docs: |
dokümantasyon |
style: |
kod formatı |
refactor: |
yeniden düzenleme |
test: |
test ekleme |
Bu API, kamuya açık kaynaklardan (Kandilli Rasathanesi ve AFAD) veri çeker. Resmî bir kurum değildir ve acil durum kararları için tek başına kullanılmamalıdır. Kritik bilgiler için lütfen resmî kaynaklara başvurun:
Earthquake API is a lightweight Flask API that scrapes live earthquake data from two major Turkish sources — Kandilli Observatory and AFAD — refreshes automatically every 5 minutes, and exposes a clean GeoJSON-compatible JSON output.
It sets up in seconds, requires no external database, holds all data in memory, and plugs directly into your web apps, mobile apps, map dashboards, or GIS tools (Leaflet, Mapbox, QGIS).
Why Earthquake API? Because it merges two sources into one consistent schema, keeps working even if one source goes down, and never blocks Flask thanks to a thread-safe architecture.
| 🌍 | ⏱️ | 🔎 | 📦 |
|---|---|---|---|
| Two sources, one API | Auto-refresh | Rich filtering | GeoJSON compatible |
| Kandilli + AFAD in one schema | Every 5 minutes | Location, magnitude, or both | Leaflet, Mapbox, QGIS |
| 🧵 | 🛡️ | ❤️ | 🪶 |
|---|---|---|---|
| Thread-safe | Fault isolation | /health endpoint |
Lightweight |
Protected by threading.Lock |
One source down, other keeps running | Liveness + freshness check | Flask + BS4 + schedule |
|
|
| Layer | Technology |
|---|---|
| Backend | Python 3.10+, Flask 3.0 |
| HTML Parsing | BeautifulSoup4 |
| Scheduler | schedule + threading |
| HTTP Client | urllib (standard library) |
| Concurrency | threading.Lock (thread-safe buffer) |
| Output | JSON (GeoJSON-compatible) |
- Python 3.10 or higher
- pip
# 1. Clone the repo
git clone https://github.com/mdaedalus/Earthquake-api.git
cd Earthquake-api
# 2. Create virtual environment
python -m venv venv
# Windows:
venv\Scripts\activate
# macOS/Linux:
source venv/bin/activate
# 3. Install dependencies
pip install -r requirements.txt
# 4. Start the API
python app.pyOpen in your browser: http://localhost:5000
Note:
requestsis not used — HTTP calls go through the standard library'surllib.
GET /| Parameter | Type | Description | Example |
|---|---|---|---|
type |
string | Source: kandilli (default) or afad |
?type=afad |
location |
string | City / district filter (case-insensitive) | ?location=Izmir |
size |
float | Minimum magnitude (largest of md/ml/mw) | ?size=4.5 |
# Latest earthquakes from Kandilli
curl http://localhost:5000/
# Latest earthquakes from AFAD
curl http://localhost:5000/?type=afad
# Earthquakes in Izmir
curl http://localhost:5000/?location=Izmir
# Earthquakes of magnitude 4.0 and above
curl http://localhost:5000/?size=4
# Earthquakes of magnitude 3.0+ in Ankara
curl http://localhost:5000/?size=3&location=Ankara
# Health check
curl http://localhost:5000/health{
"type": "FeatureCollection",
"metadata": {
"generated": "2025-01-15 14:32:00 UTC",
"last_updated": "2025-01-15 14:30:00 UTC",
"title": "Earthquake API",
"api_version": "1.0.0",
"source": "kandilli",
"count": 42,
"errors": {}
},
"features": [
{
"type": "Feature",
"properties": {
"mag": { "md": 0, "ml": 4.2, "mw": 0 },
"place": "IZMIR KORFEZI",
"time": 1736958720,
"updated": 1736958720,
"status": "İlksel",
"type": "earthquake",
"title": "M 4.2 - IZMIR KORFEZI",
"depth": 7.3
},
"geometry": {
"type": "Point",
"coordinates": [26.85, 38.42, 7.3]
},
"id": "kandilli-1736958720-483921",
"source": "kandilli"
}
]
}GET /health{
"status": "ok",
"last_updated": "2025-01-15 14:30:00 UTC",
"kandilli_count": 42,
"afad_count": 38,
"errors": {}
}| URL | What It Does |
|---|---|
/ |
All earthquakes (default: Kandilli) |
/?type=afad |
Earthquakes from AFAD |
/?type=kandilli |
Earthquakes from Kandilli |
/?location=<city> |
Earthquakes in the given city |
/?size=<magnitude> |
Earthquakes at or above magnitude |
/?size=<m>&location=<city> |
Both filters combined |
/health |
Liveness & data freshness check |
Earthquake-api/
├── app.py # Main Flask app
├── requirements.txt
├── LICENSE # MIT
├── README.md
├── .gitignore
└── img/ # 📸 Screenshots
⏱️ Refresh Interval
To change how often update_data() runs:
UPDATE_INTERVAL_MINUTES = 5 # 5 minutes
UPDATE_INTERVAL_MINUTES = 1 # 1 minute🌐 Port and Host
Edit the app.run() line:
app.run(host="0.0.0.0", port=8080, debug=False)🔒 CORS Policy
To restrict CORS to a specific domain instead of opening it to all:
response.headers["Access-Control-Allow-Origin"] = "https://yourdomain.com"🔎 Extending Filters
Add new filters by extending the if/elif chain in index():
depth = request.args.get("depth")
if depth:
data = [d for d in data if d["properties"]["depth"] >= float(depth)]- 🟢 v0.1 — Kandilli scraper
- 🟢 v0.2 — AFAD scraper
- 🟢 v0.3 — Threaded auto-refresh
- 🟢 v0.4 — Location & magnitude filters
- 🟢 v0.5 — GeoJSON-compatible output
- 🟢 v0.6 — CORS support
- 🟢 v0.7 — Thread-safe buffer +
/healthendpoint - 🟡 v0.8 — Date range filter (
?from=2025-01-01&to=2025-01-31) - 🟡 v0.9 — Depth filter (
?depth=10) - 🟡 v1.0 — CSV / GeoJSON export endpoints
- 🟠 v1.1 — WebSocket live stream
- 🟠 v1.2 — Redis cache layer
- 🟠 v1.3 — Prometheus metrics
- 🟠 v1.4 — Rate limiting
- 🔴 v1.5 — Docker image
- 🔴 v2.0 — External earthquake APIs (USGS, EMSC) integration
Contributions are welcome! For major changes, please open an issue first.
# Fork → Clone → Branch → Commit → Push → PR
git checkout -b feature/new-feature
git commit -m "feat: added new feature"
git push origin feature/new-feature| Prefix | Meaning |
|---|---|
feat: |
new feature |
fix: |
bug fix |
docs: |
documentation |
style: |
code formatting |
refactor: |
refactoring |
test: |
adding tests |
This API scrapes data from publicly available sources (Kandilli Observatory and AFAD). It is not an official body and must not be used as the sole basis for emergency decisions. Always refer to official sources for critical information:
This project is licensed under the MIT License.
See the LICENSE file for details.