40 lines
1.1 KiB
Python
40 lines
1.1 KiB
Python
|
import argparse
|
||
|
from time import sleep
|
||
|
from datetime import datetime
|
||
|
from dnsocial.dns import find_last_int, query_txt
|
||
|
|
||
|
|
||
|
def parse_args() -> argparse.Namespace:
|
||
|
parser = argparse.ArgumentParser(
|
||
|
prog='subscribe', description="Subscribe to a feed on DNS social",
|
||
|
)
|
||
|
parser.add_argument('-d', '--domain', required=True, help="Domain to post to")
|
||
|
parser.add_argument('-i', '--interval', required=False, help="Seconds between polling", type=int, default=5)
|
||
|
|
||
|
args = parser.parse_args()
|
||
|
return args
|
||
|
|
||
|
def subscribe(domain:str, interval:float=5):
|
||
|
# find the last integer from the last post
|
||
|
last_int = find_last_int(domain)
|
||
|
|
||
|
print(f'Beginning subscription at {last_int}.{domain}')
|
||
|
|
||
|
try:
|
||
|
while True:
|
||
|
query_domain = f"{last_int}.{domain}"
|
||
|
post = query_txt(query_domain)
|
||
|
if post is not None:
|
||
|
print(f"{datetime.now().isoformat()} - {query_domain}: {post}")
|
||
|
last_int += 1
|
||
|
|
||
|
sleep(interval)
|
||
|
|
||
|
except KeyboardInterrupt:
|
||
|
print('Ending subscription')
|
||
|
|
||
|
|
||
|
def main():
|
||
|
args = parse_args()
|
||
|
subscribe(args.domain, args.interval)
|