The below code is an example of how to interface with the SonarQube API and extract the information you need. To do this you will need:
- Python 3.7
- Python requests library.
- Find more on the python requests library, including installation, here.
This script finds the total number of lines of Apex and Visualforce code over all of your projects. It achieves this by making multiple API requests, deserialising the JSON returned and iterating through the results. It finds the number of lines of code listed for the desired language types via a regular expression, converts those values to integers and adds them to the total. This is by no means the most efficient way to do this but probably one of the most readable!
If you would like to look into the SonarQube API further, visit the official documentation here.