diff options
Diffstat (limited to 'home-modules/pandoc/german_abbreviations.txt.gup')
| -rwxr-xr-x | home-modules/pandoc/german_abbreviations.txt.gup | 35 |
1 files changed, 35 insertions, 0 deletions
diff --git a/home-modules/pandoc/german_abbreviations.txt.gup b/home-modules/pandoc/german_abbreviations.txt.gup new file mode 100755 index 00000000..abcab1da --- /dev/null +++ b/home-modules/pandoc/german_abbreviations.txt.gup | |||
| @@ -0,0 +1,35 @@ | |||
| 1 | #!/usr/bin/env nix | ||
| 2 | #!nix shell --impure --expr `` | ||
| 3 | #!nix with (import (builtins.getFlake ''nixpkgs'') {}); | ||
| 4 | #!nix python3.withPackages (ps: with ps; [ requests ]) | ||
| 5 | #!nix `` --command python3 | ||
| 6 | |||
| 7 | import requests | ||
| 8 | import json | ||
| 9 | import sys | ||
| 10 | import re | ||
| 11 | import subprocess | ||
| 12 | |||
| 13 | def wiki_cont(url, params): | ||
| 14 | continue_params = None | ||
| 15 | while True: | ||
| 16 | req_params = params | ||
| 17 | if continue_params is not None: | ||
| 18 | req_params |= continue_params | ||
| 19 | json_data = requests.get(url, req_params).json() | ||
| 20 | if "query" in json_data: | ||
| 21 | yield json_data["query"] | ||
| 22 | if "continue" not in json_data: | ||
| 23 | break | ||
| 24 | else: | ||
| 25 | continue_params = json_data["continue"] | ||
| 26 | |||
| 27 | out_re = re.compile(r"[^ ]*[^ 0-9][^ ]*\.") | ||
| 28 | |||
| 29 | subprocess.run(["gup", "--always"], check=True) | ||
| 30 | |||
| 31 | with open(sys.argv[1], 'w') as out: | ||
| 32 | for query in wiki_cont("https://de.wiktionary.org/w/api.php", {"action": "query", "list": "categorymembers", "cmtitle": "Kategorie:Abkürzung_(Deutsch)", "format": "json"}): | ||
| 33 | for item in map(lambda i: i["title"], query["categorymembers"]): | ||
| 34 | if out_re.fullmatch(item): | ||
| 35 | print(item, file=out) | ||
