# using python 3.5 e.g. https://github.com/wordnik/wordnik-python3
from wordnik import swagger, WordApi, WordsApi, WordListApi, WordListsApi, AccountApi
apiUrl = 'http://api.wordnik.com/v4'
apiKey = "<my api key>"
client = swagger.ApiClient(apiKey, apiUrl)
account_api = AccountApi.AccountApi(client)
word_api = WordApi.WordApi(client)
words_api = WordsApi.WordsApi(client)
word_list_api = WordListApi.WordListApi(client)
word_lists_api = WordListsApi.WordListsApi(client)
username = "andrewtatham"
password = "<my password>"
auth_token = account_api.authenticate(username, password).token
# I can get my list ok e.g. https://wordnik.com/lists/hello-world
my_lists = account_api.getWordListsForLoggedInUser(auth_token)
for my_list in my_lists:
print("{username}, {name}, {numberWordsInList}, {description}, {permalink}".format(**my_list.__dict__))
list_words = word_list_api.getWordListWords(permalink=my_list.permalink, auth_token=auth_token)
for word in list_words:
print(word.word)
# andrewtatham, hello world, 2, this description intentionally left blank, hello-world
# world
# hello
# but I can't get other peoples lists e.g. https://wordnik.com/lists/twitter-loves
list_words = word_list_api.getWordListWords(permalink="twitter-loves", auth_token=auth_token)
# urllib.error.HTTPError: HTTP Error 403: Forbidden
#
# File "/Users/andrewtatham/twitterpibot/twitterpibot/logic/wordnikwrapper.py", line 34, in <module>
# list_words = word_list_api.getWordListWords(permalink="twitter-loves", auth_token=auth_token)
# File "/Library/Frameworks/Python.framework/Versions/3.5/lib/python3.5/site-packages/wordnik/WordListApi.py", line 242, in getWordListWords
# postData, headerParams)
# File "/Library/Frameworks/Python.framework/Versions/3.5/lib/python3.5/site-packages/wordnik/swagger.py", line 73, in callAPI
# request = urllib.request.urlopen(requestParams)
I hadn’t intended to add/remove words from the list. I wanted readonly access to these other lists to use as source data for a twitter bot of some kind.
Hadn’t worked it out in any more detail than that yet. Was just finding interesting lists to use.
Any idea when the next version of the api will be? and what likelihood this feature will be in it?
Thanks
> <mailto:wordnik-api+unsub...@googlegroups.com>.
>> > <mailto:wordnik-api+unsub...@googlegroups.com>.