forked from lucaswerkmeister/tool-lexeme-forms
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathlanguage_names.py
28 lines (23 loc) · 856 Bytes
/
language_names.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
import sys
import mwapi
import toolforge
_language_info = None
_user_agent = toolforge.set_user_agent('lexeme-forms', email='mail@lucaswerkmeister.de')
def load_language_info():
session = mwapi.Session(
'https://meta.wikimedia.org',
user_agent=_user_agent,
)
response = session.get(action='query',
meta='languageinfo',
liprop='autonym',
formatversion='2')
if 'continue' in response:
print('WARNING: MediaWiki languageinfo incomplete, continue={}'.format(response['continue']),
file=sys.stderr)
return response['query']['languageinfo']
def autonym(code):
global _language_info
if _language_info is None:
_language_info = load_language_info()
return _language_info.get(code, {}).get('autonym')