Yes, you can create a script to do that but if you don’t have customers/users from x country, you can block the entire country using ipset as @nu01 suggested.
The source to get the list of ips https://github.com/ipverse/rir-ip
1.- Create an ipset using the above repo as source, example source url for ru:
https://raw.githubusercontent.com/ipverse/rir-ip/refs/heads/master/country/ru/ipv4-aggregated.txt
2.- Once the new ipset has been added, you can create new firewall rules to DROP connections from that ipset.
More info:
how-do-i-setup-an-ipset-blacklist-or-whitelist
how-can-i-open-or-block-a-port-or-ip