diff options
| author | Asbjørn Sloth Tønnesen <ast@a5n.dk> | 2024-11-07 21:50:31 +0000 | 
|---|---|---|
| committer | Asbjørn Sloth Tønnesen <ast@a5n.dk> | 2024-11-07 21:50:31 +0000 | 
| commit | a7611f3b46c69539473fba3c056d5002314299bc (patch) | |
| tree | 1f1c5e90b6d9c01652dc32eb6dfefe92ee1a3357 | |
| parent | 1f5cebcc57313ecc446929af90a6383f91edbf4f (diff) | |
| download | peeringdb-simplesync-a7611f3b46c69539473fba3c056d5002314299bc.tar.gz peeringdb-simplesync-a7611f3b46c69539473fba3c056d5002314299bc.tar.xz peeringdb-simplesync-a7611f3b46c69539473fba3c056d5002314299bc.zip  | |
make domain name configurable
Also change from peeringdb.com to www.peeringdb.com,
so we don't have to get redirected on every request.
Signed-off-by: Asbjørn Sloth Tønnesen <ast@a5n.dk>
| -rw-r--r-- | config.py.sample | 4 | ||||
| -rwxr-xr-x | sync.py | 7 | 
2 files changed, 8 insertions, 3 deletions
diff --git a/config.py.sample b/config.py.sample index 0f8deeb..05a0650 100644 --- a/config.py.sample +++ b/config.py.sample @@ -2,6 +2,10 @@  # Config keys  # ===========  # +# domain_name: PeeringDB domain name +#   Defaults to "www.peeringdb.com", +#   but can eg. be set to "beta.peeringdb.com" for testing +#  # db_conn_str: libpq database connection string  #   https://www.postgresql.org/docs/current/libpq-connect.html#LIBPQ-CONNSTRING  # @@ -19,6 +19,7 @@ import logging  from config import get_config  schema_name = get_config().get('db_schemad', 'peeringdb') +domain_name = get_config().get('domain_name', 'www.peeringdb.com')  #logging.basicConfig(level=logging.DEBUG) @@ -106,7 +107,7 @@ def last_updated(kind):      return int(last)  def fetch_objects(s, kind, extra_params): -    endpoint = f'https://peeringdb.com/api/{kind:s}' +    endpoint = f'https://{domain_name:s}/api/{kind:s}'      params = {              'depth': 0,              'status__in': 'ok,pending,deleted', @@ -138,7 +139,7 @@ def initial_sync(s, kind):  def sync_table(s, kind):      test_table(kind) -    endpoint = f'https://peeringdb.com/api/{kind:s}' +    endpoint = f'https://{domain_name:s}/api/{kind:s}'      last = last_updated(kind)      if last is None:          last = int(time.time()) - 3600 @@ -176,7 +177,7 @@ def main():      req_agent = s.headers.get('User-Agent')      s.headers.update({'User-Agent': f'peeringdb-simplesync/0.1 {req_agent:s}'}) -    spec_url = find_spec(s, 'https://peeringdb.com/apidocs/') +    spec_url = find_spec(s, f'https://{domain_name:s}/apidocs/')      s.headers.update({'Accept': 'application/x-yaml'})      r = s.get(spec_url)  | 
