# -*- coding: utf-8 -*- """Which site is which, and which of them may be named. Two sites are measured. One is the author's own and is named. The other is a client's, read with its owner's agreement on the condition that it is not identified, so everything downstream keys on an alias and the mapping from alias to host lives in `sites.local.json`, which is in the never-publish set beside `raw/`. That is not decoration. A paper that anonymises a site in its prose and then writes the real hostname into a CSV filename has not anonymised anything, so the alias is applied at the point the raw log is read and no later stage ever sees a host at all. The public description of an anonymous site is here, in the open, because a reader needs to know what kind of site produced the numbers even when they cannot know which one it is. """ import io import json import os HERE = os.path.dirname(os.path.abspath(__file__)) LOCAL = os.path.join(HERE, 'sites.local.json') # alias -> what a reader is told about it. No hostname appears in this table. PUBLIC = { 'broikos.gr': dict( named=True, what='the author\'s own portfolio and research site', category='professional portfolio and published research', robots='names five AI crawlers and allows them on purpose'), 'practice-a': dict( named=False, # One step wider than the truth on purpose. The reader needs to know # what kind of site produced the numbers; the specific profession does # no work in any claim here and narrows the field considerably in a # country this size. what='a Greek single-practitioner professional practice with a blog ' 'and online booking', category='professional services, single practitioner', robots='no AI-specific rules, so the default applies and every crawler ' 'is allowed'), } def _map(): if os.path.exists(LOCAL): try: return json.load(io.open(LOCAL, encoding='utf-8')) except Exception: # noqa: BLE001 return {} return {} def alias(host): """The published name for a host. Falls back to the host when it is named.""" return _map().get(host, host) def describe(al): return PUBLIC.get(al, dict(named=True, what='', category='', robots='')) def aliases(): return sorted(PUBLIC) def outdir(al): d = os.path.join(HERE, 'sites', al) os.makedirs(d, exist_ok=True) return d