68 lines
2.1 KiB
Python
68 lines
2.1 KiB
Python
import sys
|
|
import os
|
|
import requests
|
|
import pandas as pd
|
|
|
|
sys.path.append(os.path.abspath(os.path.join(os.path.dirname(__file__), '..', '_data')))
|
|
from api_keys import GOOGLE_API_KEY
|
|
|
|
# Base URL für die Google Places API
|
|
BASE_URL = "https://maps.googleapis.com/maps/api/place/nearbysearch/json"
|
|
|
|
def search_places(query, location, radius=5000):
|
|
"""
|
|
Sucht Orte basierend auf Query und Standort.
|
|
|
|
:param query: Suchbegriff (z. B. 'Therapeuten')
|
|
:param location: Standort als 'latitude,longitude'
|
|
:param radius: Suchradius in Metern (Standard: 5000)
|
|
:return: Liste von Orten
|
|
"""
|
|
params = {
|
|
'key': GOOGLE_API_KEY,
|
|
'keyword': query,
|
|
'location': location,
|
|
'radius': radius
|
|
}
|
|
response = requests.get(BASE_URL, params=params, verify=False)
|
|
if response.status_code == 200:
|
|
return response.json().get('results', [])
|
|
else:
|
|
print(f"Error: {response.status_code}, {response.text}")
|
|
return []
|
|
|
|
def save_to_csv(data, filename):
|
|
"""
|
|
Speichert die Daten in einer CSV-Datei.
|
|
|
|
:param data: Liste von Orten
|
|
:param filename: Name der CSV-Datei
|
|
"""
|
|
df = pd.DataFrame(data)
|
|
df.to_csv(filename, index=False)
|
|
print(f"Datei gespeichert: {filename}")
|
|
|
|
def main():
|
|
query = input("Gib den Suchbegriff ein (z. B. 'Therapeuten'): ")
|
|
location = input("Gib den Standort ein (z. B. '52.5200,13.4050' für Berlin): ")
|
|
radius = int(input("Gib den Suchradius in Metern ein (z. B. 5000): "))
|
|
|
|
places = search_places(query, location, radius)
|
|
|
|
if places:
|
|
formatted_data = [
|
|
{
|
|
'Name': place.get('name'),
|
|
'Adresse': place.get('vicinity'),
|
|
'Bewertung': place.get('rating', 'N/A'),
|
|
'Anzahl Bewertungen': place.get('user_ratings_total', 'N/A'),
|
|
'Typ': ', '.join(place.get('types', []))
|
|
}
|
|
for place in places
|
|
]
|
|
save_to_csv(formatted_data, 'places.csv')
|
|
else:
|
|
print("Keine Ergebnisse gefunden.")
|
|
|
|
if __name__ == "__main__":
|
|
main() |