This Python script fetches restaurant data within a specified city and filters out restaurants with ratings below given rate using the Google Places API. The data is saved in both CSV and JSON formats for easy access and analysis.
- Grid-based Search: The city is divided into 5KM x 5KM grid sections to ensure thorough coverage.
- Rating Filter: Filters restaurants with a rating lower than 2.5 stars.
- Data Saving: Saves both the full list of restaurants and the low-rated restaurants to CSV and JSON files.
- Flexible Configuration: Easily change the city center, grid size, and rating threshold.
- Python 3.x
requests
librarypython-dotenv
library (for managing environment variables)- A valid Google Places API key
git clone git@github.com:BrahimChatri/restaurants_finder.git
cd restaurants_finder
Install the required libraries using pip
:
pip install -r requirements.txt
Create a .env
file in the root directory and add your Google Places API key:
API_KEY=your_google_places_api_key
You can obtain an API key from the Google Cloud Console.
In the script, you can modify the following parameters:
CITY_CENTER_LAT
andCITY_CENTER_LNG
: Latitude and longitude of the city center. Change these to your desired location.GRID_SIZE_KM
: The size of each grid cell in kilometers (default is 5KM x 5KM).MAX_RESULTS
: The maximum number of restaurants to fetch (default is 1000).
To run the script, simply execute the following command:
python main.py
The script will begin fetching restaurant data and save the results into CSV and JSON files.
The script generates the following files:
- all_restaurants.csv: Contains data for all fetched restaurants.
- all_restaurants.json: Contains data for all fetched restaurants in JSON format.
- low_rated_restaurants.csv: Contains data for low-rated restaurants in csv format.
- low_rated_restaurants.json: Contains data for low-rated restaurants in JSON format.
All files are saved in the data/
folder.
The saved data includes the following fields:
Name
: The name of the restaurant.Rating
: The rating of the restaurant.Address
: The address of the restaurant.URL
: A link to the restaurant on Google Maps.
This project is licensed under the MIT License - see the LICENSE file for details.
- The script uses the Google Places API to fetch restaurant data check their docs.