1import os
2
3import dotenv
4from cf_rules import Cloudflare
5
6dotenv.load_dotenv(".env")
7
8local_rule_file = "Bad Bots.txt"
9# "Bad Bots.txt" must exist in your expressions folder
10remote_rule_name = "Handle Bad Bots"
11
12cf = Cloudflare("expressions")
13cf.auth_key(os.environ.get("EMAIL"), os.environ.get("KEY"))
14
15domains = cf.domains # List of domains as objects
16
17# Update your rule for all domains
18for domain in domains:
19 # WARNING If you have a better plan (pro, business or enterprise), don't forget to set your plan
20 # It will increase your rules limit for the import_rule method
21 cf.set_plan(domain)
22 # import_rule is an alias of create_rule
23 c = cf.import_rule(domain, local_rule_file, remote_rule_name, "block")
24 print(c)