Skip to content

Instantly share code, notes, and snippets.

@4re
Last active August 13, 2019 09:02
Show Gist options
  • Save 4re/42b76922eef735d33b1d4805089af016 to your computer and use it in GitHub Desktop.
Save 4re/42b76922eef735d33b1d4805089af016 to your computer and use it in GitHub Desktop.
#!/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