Last active
August 13, 2019 09:02
-
-
Save 4re/42b76922eef735d33b1d4805089af016 to your computer and use it in GitHub Desktop.
Helper to update https://github.com/looki/kanji-highlighter
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env python3 | |
import json | |
import urllib3 | |
import certifi | |
__version__ = '0.1.0' | |
def main(): | |
apiroot = 'https://www.wanikani.com/api/v2' | |
key = '' | |
http = urllib3.PoolManager(cert_reqs='CERT_REQUIRED', ca_certs=certifi.where()) | |
headers = {'Authorization': 'Token token={}'.format(key)} | |
for level in range(1, 61): | |
query = '{}/subjects?type=kanji&levels={}'.format(apiroot, level) | |
request = http.request('GET', query, headers=headers) | |
data = json.loads(request.data.decode('utf-8')) | |
kanjis = '' | |
for item in data['data']: | |
kanjis += item['data']['character'] | |
print(' /*{}{}:*/ "{}"{}'.format(' ' if level < 10 else '', | |
level, | |
kanjis, | |
',' if level < 60 else '')) | |
if __name__ == "__main__": | |
main() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment