A Telegram bot that helps users find nearby carparks in Singapore and check their real-time availability.
- 🔍 Search for carparks near any location in Singapore
- 📊 View real-time availability of parking lots
- 📍 Shows distance to each carpark from your specified location
- 🚦 Visual indicators of carpark occupancy (🟢 Available, 🟡 Moderate, 🟠 Busy, 🔴 Very Busy)
- Python 3.8+
- Telegram Bot Token (obtained from @BotFather)
- Google Maps Geocoding API key
- Internet connection to access the Google Maps API and Data.gov.sg API
-
Clone this repository:
git clone https://github.com/yourusername/singapore-carpark-bot.git cd singapore-carpark-bot -
Create a virtual environment and activate it:
python -m venv .venv source .venv/bin/activate # On Windows: .venv\Scripts\activate
-
Install the required packages:
pip install -r requirements.txt
-
Create a
.envfile in the root directory with your API keys:TELEGRAM_TOKEN=your_telegram_bot_token_here API_KEY=your_google_api_key_here
The bot requires the HDB Carpark Information dataset to function properly. Follow these steps to download it:
-
Visit the HDB Carpark Information dataset on data.gov.sg (dataset ID: d_23f946fa557947f93a8043bbef41dd09)
-
Download the CSV file by clicking on "Download" button
-
Place the downloaded CSV file in the root directory of the project and rename it to
HDBCarparkInformation.csv -
Generate the carpark locations database by running:
python gen_carparks.py
This will create a carpark_locations.json file that contains all carpark locations with their coordinates.
-
Start the bot:
python bot.py
-
Open Telegram and search for your bot
-
Start a conversation with
/start -
Send a location in Singapore (address, postal code, landmark) to find nearby carparks
- User sends a location to the bot
- The bot uses Google Maps Geocoding API to convert the location to coordinates
- The bot finds nearby carparks within a 1km radius
- The bot fetches real-time availability data from data.gov.sg API
- Results are formatted and sent back to the user
├── bot.py # Main bot implementation
├── gen_carparks.py # Script to generate carpark database
├── carpark_locations.json # Generated database of carpark locations
├── converter.py # SVY21 to WGS84 coordinate converter
├── google_geocode.py # Google Maps Geocoding API integration
├── .env # Environment variables (including bot token and API key)
├── scraper/
│ ├── __init__.py
│ ├── Carpark_grabber.py # Scraper for carpark availability data
│ ├── parser.py # Content parsers (HTML, JSON, XML)
│ ├── requester.py # HTTP request handler
│ └── scraper.py # Base scraper class
- Carpark Availability API:
https://api.data.gov.sg/v1/transport/carpark-availability - Google Maps Geocoding API:
https://maps.googleapis.com/maps/api/geocode/json
- python-telegram-bot
- requests
- pandas
- python-dotenv
- beautifulsoup4
This project uses the HDB Carpark Information dataset (ID: d_23f946fa557947f93a8043bbef41dd09) from data.gov.sg, which is made available under the Singapore Open Data License.
Data is provided by the Housing & Development Board (HDB) and accessed through the data.gov.sg API.
The SVY21 to WGS84 coordinate conversion functionality is based on cgcai/SVY21.
Contributions are welcome! Please feel free to submit a Pull Request.
- Fork the repository
- Create your feature branch (
git checkout -b feature/amazing-feature) - Commit your changes (
git commit -m 'Add some amazing feature') - Push to the branch (
git push origin feature/amazing-feature) - Open a Pull Request