File: examplev5.py

package info (click to toggle)
python-hole 0.9.0-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 128 kB
  • sloc: python: 680; makefile: 3
file content (71 lines) | stat: -rw-r--r-- 1,760 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
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
"""Example for the usage of the hole module."""

import asyncio
import json

import aiohttp

from hole import Hole

API_TOKEN = "YOUR_API_TOKEN"


async def main():
    """Get the data from a *hole instance."""
    async with aiohttp.ClientSession() as session:
        data = Hole("192.168.0.215", session, version=5)

        await data.get_versions()
        print(json.dumps(data.versions, indent=4, sort_keys=True))
        print(
            "Version:",
            data.core_current,
            "Latest:",
            data.core_latest,
            "Update available:",
            data.core_update,
        )
        print(
            "FTL:",
            data.ftl_current,
            "Latest:",
            data.ftl_latest,
            "Update available:",
            data.ftl_update,
        )
        print(
            "Web:",
            data.web_current,
            "Latest:",
            data.web_latest,
            "Update available:",
            data.web_update,
        )

        await data.get_data()

        # Get the raw data
        print(json.dumps(data.data, indent=4, sort_keys=True))

        print("Status:", data.status)
        print("Domains being blocked:", data.domains_being_blocked)


async def disable():
    """Get the data from a *hole instance."""
    async with aiohttp.ClientSession() as session:
        data = Hole("192.168.0.215", session, api_token=API_TOKEN)
        await data.disable()


async def enable():
    """Get the data from a *hole instance."""
    async with aiohttp.ClientSession() as session:
        data = Hole("192.168.0.215", session, api_token=API_TOKEN)
        await data.enable()


if __name__ == "__main__":
    asyncio.run(main())
    asyncio.run(disable())
    asyncio.run(enable())