Skip to content

Instantly share code, notes, and snippets.

@ink-splatters
Created February 6, 2026 18:54
Show Gist options
  • Select an option

  • Save ink-splatters/71d8eecf92a72cf91fa7ea64152b5db9 to your computer and use it in GitHub Desktop.

Select an option

Save ink-splatters/71d8eecf92a72cf91fa7ea64152b5db9 to your computer and use it in GitHub Desktop.
#!/usr/bin/env python3
# uv venv && source .venv/bin/activate
# uv pip install -U requests multidict phonenumbers
from urllib.parse import urlparse, parse_qs
import requests
import phonenumbers as pn
from multidict import MultiDict
import sys
REGION_CODE_TO_COUNTRY_CODE = MultiDict()
for code, countries in pn.COUNTRY_CODE_TO_REGION_CODE.items():
for c in countries:
REGION_CODE_TO_COUNTRY_CODE[c] = code
def get_country_code() -> int:
r = requests.get("https://api.country.is")
r.raise_for_status()
region_code = r.json()["country"]
return REGION_CODE_TO_COUNTRY_CODE[region_code]
if __name__ == "__main__":
url = sys.argv[1].replace("&", "?")
u = urlparse(url)
print(f"Phone number: +{get_country_code()}{u.netloc}")
print(f"Message: {parse_qs(u.query)['body'][0]}")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment