Metrogo is the route of the subway. The Metroggo finds the fastest route and informs you of the next train to the source station and tells you the cost of your trip.
- Auto-correction of input station names
- Fast routing with minimal time wastage
- The arrival time of the train at the origin station
- Travel cost
- The length of time the user is inside the subway
- Show when the user arrives at the destination station
- A simple and straightforward guide for the general public
MetroGo uses Excel files from Tehran Metro Company and Ali Project to build its database. First, the DB Factory program is run and combines the time data in the Excel files into the stations template file and stores it in the database.
Then the Data Loader program reads the database and creates line and station objects. Then the Routing service uses the pathfinder , line , schedule , travelinfo and wordutils tools to perform routing and add information including train schedules and other items to the result and then outputs the result.
Clone the project to your system with the following command :
git clone https://github.com/theothermmd/MetrogoEnter the project directory with the following command:
cd MetrogoCreate the Python virtual environment with the following commands or activate it if you already have one:
# Create python virtual environment
python3 -m venv metrogo
# Active python virtual environment in Linux/Mac
source metrogo/bin/activate
# Active python virtual environment in Windows
metrogo\Scripts\activate
Install Metrogo prerequisites with the following command:
pip install -r requirements.txtCreate the database with the following command:
python -m metrogo.utils.Excel_extractors.db_factoryRun the Metrogo API server with the following command:
fastapi dev .\metrogo\api\server.pyThe MetroGo server is listening to you on 127.0.0.1:8000 :)
Tip
You can use httpie or postman to request the Metrogo API, depending on your convenience. httpie is recommended.
For routing, you need to send your data to the API in the form of Query Parameters using the GET method. Take a look at the following example:
http://127.0.0.1:8000/v1/routing/get_route?source=%D9%86%D8%A8%D8%B1%D8%AF&destination=%D8%AA%D8%A6%D8%A7%D8%AA%D8%B1%D8%B4%D9%87%D8%B1%&type_of_day=%D8%B9%D8%A7%D8%AF%DB%8C&time=10:30Note
You may be wondering what %D9%85%D9%86%DB%8C%D8%B1%DB%8C%D9%87 is?
To send Persian words to the API, we need to format the words or data as URL-encoded. For example, %D9%85%D9%86%DB%8C%D8%B1%DB%8C%D9%87 is the formatted form of the word "منیریه".
Tip
What does each part of this example send?
The source parameter specifies the source station
The destination parameter specifies the destination station
The type_of_day parameter specifies the type of day, which can be normal, i.e. Saturday to Wednesday or Thursday or Friday. The type of day affects the train schedule. If you leave this parameter blank, it will be considered a normal day by default
The time parameter specifies the time you will enter the metro, which you can enter manually. If you leave this parameter blank, it will be considered the current time by default.
After entering this example into your httpie application or even your regular browser, you will receive the following result from the API:
{
"status": true,
"isrouting": true,
"route": [
{
"station_name": "منیریه",
"time": "10:34",
"color": null,
"is_line_change": false,
"message": ""
},
{
"station_name": "تئاتر شهر",
"time": "10:40",
"color": null,
"is_line_change": true,
"message": "در ایستگاه تئاتر شهر از قطار پیاده شده و به سمت قائم جهت تغییر خط به 4 اقدام کنید."
},
{
"station_name": "تئاتر شهر",
"time": "10:41",
"color": null,
"is_line_change": false,
"message": ""
},
{
"station_name": "فردوسی",
"time": "10:45",
"color": null,
"is_line_change": false,
"message": ""
}
],
"travel_duration": "00:15",
"travel_distance": "33.824",
"travel_guide": [
"در ایستگاه منیریه وارد خط 3 شوید و به سمت قائم سوار مترو شوید.",
"در ایستگاه تئاتر شهر از مترو پیاده شوید. سپس وارد خط 4 شده و به سمت قائم سوار مترو شوید.",
"در ایستگاه فردوسی از مترو پیاده شوید و از ایستگاه خارج شوید."
],
"next_train": "4",
"arrival_time": "10:45"
}
Are you interested in Metrogo? Read this document and we welcome you :)
Very special thanks. to @Mostafa-Kheibary for the tehran-metro-data project
Also special thanks to Tehran Metro Company
Caution
Yes. You can. But you should know that it is true that the metro train schedule is from the official source of the metro company, but according to the experience and feedback of others, trains do not always arrive at the station on time due to technical problems or passengers preventing the train from moving.
Metrogo is not only a regular program, but also a Python package. Move the metrogo folder into your project and use Metrogo like any other Python package.

