39 lines
1.1 KiB
Python
39 lines
1.1 KiB
Python
import json
|
|
import requests
|
|
import time
|
|
import logging
|
|
|
|
RECORDS_FILE = "records.json"
|
|
ENDPOINT = "https://hatecomputers.club"
|
|
API_KEY = open('apikey.secret', 'r').read().strip()
|
|
|
|
class HatecomputersDNSAdapter:
|
|
def __init__(self, endpoint, api_key):
|
|
self.endpoint = endpoint
|
|
self.session = requests.Session()
|
|
self.headers = {'Authorization': 'Bearer ' + api_key}
|
|
self.session = requests.Session()
|
|
|
|
def post_record(self, record):
|
|
endpoint = self.endpoint + "/dns"
|
|
logging.info("adding", record, "at", endpoint)
|
|
|
|
self.session.post(endpoint, headers=self.headers, data=record)
|
|
|
|
def post_records(self, dns_entries, sleep_time=300):
|
|
for record in dns_entries:
|
|
self.post_record(record)
|
|
|
|
logging.info("sleeping", sleep_time)
|
|
time.sleep(sleep_time)
|
|
|
|
if __name__ == "__main__":
|
|
logging.basicConfig()
|
|
logging.root.setLevel(logging.NOTSET)
|
|
|
|
records_file = open(RECORDS_FILE, 'r')
|
|
dns_records = json.load(records_file)
|
|
|
|
adapter = HatecomputersDNSAdapter(ENDPOINT, API_KEY)
|
|
adapter.post_records(dns_records)
|