Skip to content

Commit

Permalink
Changes the ip resolver from ip-api.com to ipapi.com because of https (
Browse files Browse the repository at this point in the history
…#78)

* Changes the ip resolver from ip-api.com to ipapi.com because of https

* Updates the Readme with the new ip service
  • Loading branch information
ribalba authored Jun 5, 2024
1 parent 95e2aa9 commit e040cd4
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 5 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ jobs:
- `send-data`: (optional) (default: true)
- Send metrics data to metrics.green-coding.io to create and display badge, and see an overview of the energy of your CI runs. Set to false to send no data. The data we send are: the energy value and duration of measurement; cpu model; repository name/branch/workflow_id/run_id; commit_hash; source (GitHub or GitLab). We use this data to display in our green-metrics-tool front-end here: https://metrics.green-coding.io/ci-index.html
- `show-carbon`: (optional) (default: true)
- Gets the location using http://ip-api.com
- Gets the location using https://ipapi.co/
- Get the CO2 grid intensity for the location from https://www.electricitymaps.com/
- Estimates the amount of carbon the measurement has produced
- `display-table`: (optional) (default: true)
Expand Down
8 changes: 4 additions & 4 deletions scripts/vars.sh
Original file line number Diff line number Diff line change
Expand Up @@ -170,14 +170,14 @@ function cpu_vars_fill {


get_geo_ipapi_co() {
response=$(curl -s http://ip-api.com/json/ || true)
response=$(curl -s https://ipapi.co/json || true)

if [[ -z "$response" ]] || ! echo "$response" | jq empty; then
echo "Failed to retrieve data or received invalid JSON. Exiting" >&2
return
fi

if echo "$response" | jq '.lat, .lon, .city' | grep -q null; then
if echo "$response" | jq '.latitude, .longitude, .city' | grep -q null; then
echo "Required data is missing. Exiting" >&2
return
fi
Expand Down Expand Up @@ -212,8 +212,8 @@ get_co2_val (){
total_energy=$1
geo_data=$(get_geo_ipapi_co) || true
if [ -n "$geo_data" ]; then
latitude=$(echo "$geo_data" | jq '.lat')
longitude=$(echo "$geo_data" | jq '.lon')
latitude=$(echo "$geo_data" | jq '.latitude')
longitude=$(echo "$geo_data" | jq '.longitude')
city=$(echo "$geo_data" | jq -r '.city')

export CITY="$city"
Expand Down

0 comments on commit e040cd4

Please sign in to comment.