File: custom_configuration.py

package info (click to toggle)
python-pyfunceble 4.2.29.dev-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 4,108 kB
  • sloc: python: 27,413; sh: 142; makefile: 27
file content (48 lines) | stat: -rw-r--r-- 1,580 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
"""
This is an example about how we can update the configuration while developping on top
of PyFunceble.
"""

import PyFunceble.facility
from PyFunceble import DomainAvailabilityChecker

# We preset the indexes (from .PyFunceble.yaml) that we want to update.
CUSTOM_CONFIGURATION_INDEX_VALUE_TO_SET = {
    "lookup": {"whois": False, "dns": False},
    "cli_testing": {"db_type": "csv"},
}

if __name__ == "__main__":
    # We parse our custom indexes to PyFunceble before starting to use it.
    PyFunceble.facility.ConfigLoader.start()
    PyFunceble.facility.ConfigLoader.custom_config = (
        CUSTOM_CONFIGURATION_INDEX_VALUE_TO_SET
    )

    # From now, each call of test so in this example PyFuncebleTest,
    # will not try to get/request the WHOIS record.

    DOMAINS = ["google.com", "github.com"]

    print("Start with global custom configuration.")
    for DOMAIN in DOMAINS:
        # This should return None.
        print(DOMAIN, DomainAvailabilityChecker(DOMAIN).get_status().whois_record)
    print("End with global custom configuration.\n")

    print("Start with local setting.")
    for DOMAIN in DOMAINS:
        print(f"Start of WHOIS record of {DOMAIN} \n")

        # This part should return the WHOIS record.

        # This will - at each call we manually overwrite the configurated value.
        print(
            DOMAIN,
            DomainAvailabilityChecker(DOMAIN, use_whois_lookup=True)
            .get_status()
            .whois_record,
        )

        print(f"End of WHOIS record of {DOMAIN} \n")
    print("End with local setting.")