Add a script to output the domains data as a list

This will be useful for putting into a database (it would be hard to
do so in its current, linked format).
This commit is contained in:
Chris Hill-Scott
2019-02-12 13:27:56 +00:00
parent 978719cd20
commit 8e3ab35b9a

30
domains.py Executable file
View File

@@ -0,0 +1,30 @@
#!/usr/bin/env python
# -*- coding: utf-8 -*-
import os
import yaml
from app.utils import AgreementInfo
_dir_path = os.path.dirname(os.path.realpath(__file__))
with open('{}/app/domains.yml'.format(_dir_path)) as source:
data = yaml.load(source)
for domain, details in data.items():
if isinstance(details, dict):
# Were looking at the canonical domain
data[domain]['domains'] = [domain]
for domain, details in data.items():
if isinstance(details, str):
# This is an alias, lets add it to the canonical domain
data[AgreementInfo(domain).canonical_domain]['domains'].append(domain)
out_data = [
details for domain, details in data.items()
if isinstance(details, dict)
]
print(yaml.dump(out_data)) # noqa