Berlin Services API is a web application that scrapes, stores, and presents information about various services offered by the city of Berlin. It provides a user-friendly interface to explore services and their associated locations (Standorte).
- Features
- Technology Stack
- Project Structure
- Installation
- Usage
- API Endpoints
- Frontend
- Data Scraping
- Database
- Scrapes service and location data from the official Berlin service portal
- Stores data in a SQLite database
- Provides API endpoints for accessing service and location information
- Offers a user-friendly web interface to browse services and locations
- Implements a search functionality for services and locations
- Displays detailed information about services and locations in modal popups
- Backend: FastAPI (Python)
- Frontend: HTML, CSS (Tailwind CSS), JavaScript
- Database: SQLite with SQLModel ORM
- Scraping: BeautifulSoup4, Requests
- API: RESTful with JSON responses
The project is organized as follows:
berlin-services-api/
βββ app/
β βββ controllers/
β β βββ formular_controller.py
β β βββ service_controller.py
β β βββ standort_controller.py
β βββ static/
β β βββ js/
β β β βββ main.js
β βββ templates/
β β βββ base.html
β β βββ formular_detail.html
β β βββ formulare.html
β β βββ service_detail.html
β β βββ services.html
β β βββ standort_detail.html
β β βββ standorte.html
β βββ views/
β β βββ formular_view.py
β β βββ service_view.py
β β βββ standort_view.py
| βββ main.py
| βββ models.py
βββ Scraper Build/
| βββ read_db.py
β βββ scraper_v4.py
βββ services.db
βββ README.md
βββ requirements.txt
app/
: Contains the main application codeapp/controllers/
: Implements API endpoints and route handlersapp/static/
: Stores static filesapp/templates/
: Stores HTML (Jinja2) templates for the frontendapp/views/
: Implements API endpoints and route handlersapp/main.py
: Entry point for the FastAPI applicationapp/models.py
: Defines database modelsScraper Build/
: Houses the scraping scriptsservices.db
: SQLite database filerequirements.txt
: Lists the project dependencies
-
Clone the repository:
git clone https://github.com/tobiasseck/berlin-services-api.git cd berlin-services-api
-
Create a virtual environment and activate it:
python -m venv venv # On Windows venv\Scripts\activate.bat # On macOS and Linux source venv/bin/activate
-
Install the required dependencies:
pip install -r requirements.txt
-
Run the scraper to populate the database (if not already done - a full scrape of the site can take up to 20 minutes):
python "Scraper Build"/scraper_v4.py
-
Start the FastAPI server:
uvicorn app.main:app --reload
-
Open your web browser and navigate to
http://localhost:8000/services/
to access the application.
The following API endpoints are available:
GET /api/services/
: List all servicesGET /api/services/{service_id}
: Get details of a specific serviceGET /api/standorte/
: List all locations (Standorte)GET /api/standorte/{standort_id}
: Get details of a specific locationGET /api/formulare/
: List all formsGET /api/formulare/{formular_id}
: Get details of a specific form
For more detailed API documentation, visit http://localhost:8000/docs
after starting the server.
The frontend is built using HTML, Tailwind CSS, and JavaScript. It provides a responsive and intuitive interface for users to browse services and locations. Key features include:
- Search functionality for services and locations
- Modal popups for detailed service and location information
- Interactive map display for location addresses
- On-demand loading of service and location data
Examples of the frontend:
The data scraping process is implemented in the scraper_v4.py
file. It uses BeautifulSoup4 to parse HTML content from the official Berlin service portal. The scraper extracts information about services, their details, and associated locations.
Example of the scraper in action:
- As a full scrape can take up to 20 minutes, the scraper will not run automatically on startup. Instead, the scraper can be run from the command line. While running progress is displayed in the console to show the user what data is currently being scraped.
The project uses SQLite with SQLModel ORM for data storage. The database schema is defined in the app/models/
directory. Key models include:
Service
: Represents a city serviceServiceDetail
: Stores detailed information about a serviceStandorte
: Represents a location where services are offeredStandorteServices
: Manages the many-to-many relationship between services and locationsFormular
: Represents a form associated with a serviceFormularDetail
: Stores detailed information about a formFormularStandorte
: Manages the many-to-many relationship between forms and locations