Skip to content

Instantly share code, notes, and snippets.

@implicitlycorrect
Created May 11, 2024 11:39
Show Gist options
  • Save implicitlycorrect/75aa8c1f3a6c3f27b588237549ff6115 to your computer and use it in GitHub Desktop.
Save implicitlycorrect/75aa8c1f3a6c3f27b588237549ff6115 to your computer and use it in GitHub Desktop.
Python program for getting proxyscrape residental proxy usage.
import requests
ACCOUNT_ID = "ACCOUNT ID"
def bytes_to_gb(bytes_value):
return bytes_value / 1000 / 1000 / 1000
def bytes_to_mb(bytes_value):
return bytes_value / 1000 / 1000
try:
response = requests.get(
f"https://api.proxyscrape.com/v3/accounts/residential/ResidentialUsage.php?account_id={ACCOUNT_ID}&type=current"
)
response.raise_for_status()
data = response.json()
remaining_data = data.get("remaining_data", 0)
used_data = data.get("used_data", 0)
total_data = remaining_data + used_data
total_data_gb = bytes_to_gb(total_data)
remaining_data_gb = bytes_to_gb(remaining_data)
used_data_mb = bytes_to_mb(used_data)
print(f"Total traffic: {total_data_gb:.2f} GB")
print(f"Remaining traffic: {remaining_data_gb:.2f} GB")
print(f"Total used traffic: {used_data_mb:.2f} MB")
except requests.RequestException as e:
print("Error fetching data:", e)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment