Welcome to my API Fun Projects repository! Here, I create small Python projects using different public APIs.
- Each subfolder has a different project, showing how to use APIs in Python.
- Check out the code to see how I make interesting things with data from various APIs.
- These projects are my way of learning and trying out new things with Python and APIs.
- See how to get, process, and show data from different APIs while improving your coding skills.
- Explore, add your own touch, or share your ideas.
- I'd love to hear your thoughts and ideas to make these projects even better.
- This repository is always changing as I add new projects. Keep an eye out for updates!
The modules and libraries can be installed using the Python package installer 'pip'
-
json
-
Official Link: json - Python Standard Library
-
Installation:
Python has a built-in package called json, which can be used to work with JSON data
-
-
datetime, timedelta, time
-
Official Link: datetime - Python Standard Library
-
Installation:
Python has a module named datetime to work with dates and times
-
-
pytz
- Official Link: pytz - World Timezone Definitions for Python
- Installation:
pip install pytz
-
PrettyTable
- Official Link: PrettyTable - A Simple Python Library for Table Representation
- Installation:
python -m pip install -U prettytable
-
os
-
Official Link: os - Python Standard Library
-
Installation:
Built-in os module
-
-
urllib.request
- Official Link: urllib.request - Python Standard Library
- Installation:
pip install urllib
The Python program utilizes the Digitransit's Routing API to display the stop/station schedule using GraphQL query. The variable definition "stopName": "V6110"
can be modified to include the desired name of the stops. To be able to access the API, user needs to register and use the API keys. In this case, the API key is accesed from environment variable using subscription_key = os.environ.get('HSL_SUBSCRIPTION_KEY')
. API request was sent using urllib.request
to the URL endpoint https://api.digitransit.fi/routing/v1/routers/hsl/index/graphql
and the data is stored in json
format in the parsed_response
variable. The UNIX date and time information from the parsed_response
variable are first stored in 4 different variable, converted to Helsinki timezone using the convert_date_time()
function and added in the table.
Program output | VIEW FILE
stoptimesWithoutPatterns(numberOfDepartures: 5)
: 5 departures will be displayed in the outputRoute Number
: displays the bus/train/tram numbers for a stop (in this caseV6110
stop; bus numbers 570 and 576)Scheduled arrival
: displays the secheduled arrival timeReal time arrival
: displays the real time arrival at the stopStatus
: displays the delay based on theScheduled
andReal time
arrivalsDirection
: displays the vehicle's head sign/route name