11## Copyright © 2023, Alex J. Champandard. Licensed under MIT; see LICENSE! ⚘
22
3+ import re
34import textwrap
45
56import click
67
7- from weboptout import check_domain_reservation , rsv
8+ from weboptout import check_domain_reservation , check_url_reservation , rsv
89from weboptout .types import Status
910
1011
@@ -13,17 +14,13 @@ def main():
1314 pass
1415
1516
16- @main .command ()
17- @click .argument ('domains' , nargs = - 1 )
18- def check (domains ):
19- print (f"\n \033 [1;97m{ 'Domain' :22} Opt-Out\033 [0m\n " )
20-
21- for domain in domains :
22- res = check_domain_reservation (domain , use_database = True )
17+ def _run_checks (check_fn , sources ):
18+ for source in sources :
19+ res = check_fn (source )
2320 if res == rsv .YES :
24- print (f" { domain :24 } ✓" )
21+ print (f" { source :23 } ✓" )
2522 else :
26- print (f" { domain :24 } ?" )
23+ print (f" { source :23 } ?" )
2724
2825 for record in res .process :
2926 print (
@@ -38,5 +35,29 @@ def check(domains):
3835 print ()
3936
4037
38+ @main .command ()
39+ @click .argument ('domains' , nargs = - 1 )
40+ def check_domain (domains ):
41+ print (f"\n \033 [1;97m{ 'Domain' :22} Opt-Out\033 [0m\n " )
42+ return _run_checks (check_domain_reservation , domains )
43+
44+
45+ @main .command ()
46+ @click .argument ('urls' , nargs = - 1 )
47+ def check_url (urls ):
48+ print (f"\n \033 [1;97m{ 'Link' :22} Opt-Out\033 [0m\n " )
49+ return _run_checks (check_url_reservation , urls )
50+
51+
52+ @main .command ()
53+ @click .argument ('sources' , nargs = - 1 )
54+ def check (sources ):
55+ if all (re .match ("^https?://" , src ) for src in sources ):
56+ return check_url (sources )
57+ if all (not re .match ("^https?://" , src ) for src in sources ):
58+ return check_domain (sources )
59+ raise NotImplementedError
60+
61+
4162if __name__ == "__main__" :
4263 main ()
0 commit comments