Skip to content

Instantly share code, notes, and snippets.

@drguildo
Created May 25, 2026 22:46
Show Gist options
  • Select an option

  • Save drguildo/a68d536dea3c5f5fefcba22deb457385 to your computer and use it in GitHub Desktop.

Select an option

Save drguildo/a68d536dea3c5f5fefcba22deb457385 to your computer and use it in GitHub Desktop.
A script for calculating various useful AAISP quota statistics.
#!/usr/bin/python
# Copyright (C) 2026 Simon Morgan
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <https://www.gnu.org/licenses/>.
# This script can be used by Andrews & Arnold Ltd (AAISP) customers to check
# their monthly data quota usage and projected carry over for the next month. It
# retrieves the quota information from the AAISP API, calculates the average
# daily usage, and determines how much data can be used per day for the rest of
# the month to stay within the monthly quota. The remaining quota per day is
# highlighted in red if it is less than the total quota per day, and green
# otherwise.
import calendar
import http.client
import json
import sys
from datetime import datetime
conn = http.client.HTTPSConnection("soulless.aa.net.uk")
conn.request("GET", "/info.cgi", headers={"Accept": "application/json"})
response = conn.getresponse()
if response.status != 200:
print(f"Got {response.status} from remote API. Are you using a non-AAISP network?")
exit(response.status)
quota_json = response.read().decode()
quota_data = json.loads(quota_json)
if "--debug" in sys.argv[1:]:
print(json.dumps(quota_data, indent=2))
print()
# The current date and time.
today = datetime.now()
# The total number of days in the current month.
days_in_month = calendar.monthrange(today.year, today.month)[1]
# The number of days remaining in the current month.
days_remaining_in_month = days_in_month - today.day
# The monthly quota in gigabytes.
monthly_quota_gb = int(quota_data["monthly_quota_gb"])
# The remaining quota for the month in gigabytes.
quota_remaining_gb = int(quota_data["quota_remaining_gb"])
# The amount of data used in the month so far in gigabytes.
quota_used_gb = monthly_quota_gb - quota_remaining_gb
# The average daily usage in gigabytes per day.
average_daily_usage = quota_used_gb / today.day
# The amount of data that can be used per day over the duration of the month to
# stay within the monthly quota.
total_quota_per_day = monthly_quota_gb / days_in_month
# The amount of data that can be used per day over the remaining days of the
# month to stay within the monthly quota.
remaining_quota_per_day = quota_remaining_gb / days_remaining_in_month
# The color of the remaining quota per day indicator. Red if the remaining quota
# per day is less than the total quota per day, green otherwise.
if remaining_quota_per_day < total_quota_per_day:
remaining_indicator_color = "[1;37;41m"
else:
remaining_indicator_color = "[1;30;42m"
print(
f"Remaining Quota: {quota_remaining_gb}GB of {monthly_quota_gb}GB ({monthly_quota_gb - quota_remaining_gb}GB used)"
)
# AAISP allow you to carry over half of your remaining quota to the next month,
# so we take what we've used so far, then "guess" what will be used over the
# rest of the month by multiplying the average daily usage by the number of days
# remaining in the month, and then add the two numbers. We then halve the result
# to get the projected carry over for the next month.
print(
f"Projected Carry Over: {round((quota_remaining_gb - (days_remaining_in_month * average_daily_usage)) / 2)}GB"
)
print()
print(f"Average Daily Usage: {round(average_daily_usage, 1)}GB")
print(
f"Quota per Day for Entire Month ({days_in_month} days): {round(total_quota_per_day, 1)}GB"
)
print(
f"Quota per Day for Remaining Days ({days_remaining_in_month} days): \x1b{remaining_indicator_color}{round(remaining_quota_per_day, 1)}GB\x1b[0m"
)
conn.close()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment