1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30
|
"""Contains the MullvadAPI class"""
import requests
class MullvadAPI:
"""
An object containing a dictionary representation of data returned by
the Mullvad API
"""
def __init__(self):
self.data = dict()
self.api_url = "https://am.i.mullvad.net/json"
self.update()
def update(self):
try:
response = requests.get(self.api_url)
self.data = response.json()
except:
raise MullvadAPIError(
"Could not fetch Mullvad API data. Check your network connection."
)
class MullvadAPIError(Exception):
"""Failed to fetch Mullvad API data."""
pass
|