summaryrefslogtreecommitdiff
path: root/format.py
diff options
context:
space:
mode:
Diffstat (limited to 'format.py')
-rwxr-xr-xformat.py59
1 files changed, 59 insertions, 0 deletions
diff --git a/format.py b/format.py
new file mode 100755
index 0000000..466d8d7
--- /dev/null
+++ b/format.py
@@ -0,0 +1,59 @@
+#!/usr/bin/env python3
+
+# SPDX-License-Identifier: CC0-1.0
+#
+# Copyright (C) 2022 Wojtek Kosior <koszko@koszko.org>
+#
+# Available under the terms of Creative Commons Zero v1.0 Universal.
+
+import json
+import random
+import click
+import sys
+from pathlib import Path
+
+here = Path(__file__).resolve().parent
+
+trans = {
+ 'en': {
+ 'blessed_male': 'blessed',
+ 'blessed_female': 'blessed',
+ 'saint_female': 'saint',
+ 'saint_male': 'saint',
+ 'meet_krk_saints': 'Meet Kraków saints! '
+ },
+ 'pl': {
+ 'blessed_male': 'błogosławiony',
+ 'blessed_female': 'błogosławiona',
+ 'saint_female': 'święta',
+ 'saint_male': 'święty',
+ 'meet_krk_saints': 'Poznaj świętych krakowskich!'
+ }
+}
+
+saints = json.loads((here / 'saints.json').read_text())
+
+@click.command()
+@click.option('-i', '--saint-id', default='-1', type=click.types.INT,
+ show_default=True, help='which saint to format (-1 for random)')
+def main(saint_id):
+ if saint_id == -1:
+ [(saint_id, saint)] = random.sample([*saints.items()], 1)
+ else:
+ saint_id = str(saint_id)
+ saint = saints.get(saint_id)
+
+ if saint is None:
+ print('No such saint!', file=sys.stderr)
+ return sys.exit(1)
+
+ title_key = f'{saint["title"]}_{saint["gender"]}'
+
+ for lang in ('en', 'pl'):
+ tr = trans[lang]
+ print(f'{tr["meet_krk_saints"]} #{saint_id}: {tr[title_key]} {saint["name"]}')
+
+ print(f'https://pl.wikipedia.org/wiki/{saint["wikipedia_name"]}')
+
+if __name__ == '__main__':
+ main()