File: mullvad_api.py

package info (click to toggle)
python-mullvad-api 1.0.0-1.1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 56 kB
  • sloc: python: 38; makefile: 3
file content (30 lines) | stat: -rw-r--r-- 675 bytes parent folder | download
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