I am a super beginner and decided to try to create a project where I have to use an API so that I can advance my skills. I feel like I am in way over my head though I am sure this task would be simple for an advanced programmer.
I am using the Merriam Webster's Dictionary API to try to define some Spanish song lyrics. Through using the lyricsgenius module I was able to print the lyrics to a song, and now my issue is figuring out how to use the dictionary API to pull the definition for a specific word that I give it, and print it out. All I have done so far is this:
import requests
response = requests.get('https://dictionaryapi.com/api/v3/references/spanish/json/test?key=mykey').json()
print(response)
When I run this I get what seems to be to be a huge array of dictionaries filled with data that I do not understand, and I am very confused what I am supposed to do in order to get the result that I want. Am I supposed to alter the URL to let it know what specific information I want? How do I even go about figuring out what to do? The API Documentation site is also very difficult to understand as a beginner. Thank you for your help.
Related
I'm trying to get all the users that are currently making use of a particular flair. Is there a way to get the users of a flair if I have the flair object itself?
I saw that others did this by accessing the 'user' key in the flair object like so: flair['user'], but those posts were made years ago and I guess PRAW stopped supporting this method somewhere along the line, because when I try this, I get this error: KeyError: flair['user']
I've looked at the PRAW documentation and haven't seen any way of getting the current users of a flair, so I wonder if anyone has any suggestions I can check out.
I've thought of just iterating over every post and getting their author_flair_text attribute, but that's too slow and doesn't even fit in my overall code.
This is the code:
def clearFlairsFromPreviousHolders(subreddit):
userList = []
for flair in subreddit.flair.templates:
if "Poster for Week" in flair['text']:
print(flair['user'])
subreddit.flair.update(userList, text='')
I'm trying to clear the flairs of all users that are currently using the flairs that contain a certain keyword.
I expected to get a list of users who were using the flairs at the time, but instead I got a KeyError.
Any help would be appreciated.
Got the reason lol
Looks like flair['user'] only works when you generate flairs with subreddit.flair(limit=None), as opposed to subreddit.flair.templates, which is what I used.
Yeah, pretty easy fix but it's weird that I couldn't find that in the documentation. Or maybe I just didn't look hard enough.
Im working with Maltego and I would like to add entities to a graph from a server through an api.
Is that possible?
I would say that it is not possible but in a project are asking me to do that and I don't know how to do it. I've been looking for information for a few days and I can't find anything.
Thanks in advance.
I have not tested anything because reading the documentation I do not see it possible.
I am a flask beginner and recently I am doing my first project which is searching cocktails using flask and API.
So, here is the snippet of my flask code
#app.route('/search' ,methods=[ "POST"])
def search():
value = request.form['search']
cocktailAPI = requests.get(
f'https://www.thecocktaildb.com/api/json/v1/1/search.php?s={value}'
)
value = request.form['search']
print(value)
return f'ff'
My thought is like searching things on google, no matter what I am typing google can find the most relative information for me.
Is it possible to do that? for instance, if I type 'margarite' in which 'margarita' is correct, the flask will try to find the correct word in my API and give me a response.
Thank you!
What you're trying to achieve is called fuzzy search, and is a whole problem on its own.
This is not so hard though, considering that the list of existing cocktails is quite already known.
So here a way you could follow:
Build a list of existing cocktail names; you could for instance retrieve the whole list through Thecocktaildb API (though it requires a contribution), or create a list manually (as this is not likely to evolve much)
Once user enters a name, return the closest cocktail names from your list, using some distance metrics of your own (Wikipedia article provides some clues)
Request Thecocktaildb API for this cocktail.
Happy coding!
I use a twitter bot and try hard to filter out tweets from my retweets that share inappropriate content.
Thus I want to filter all tweets out of my retweets that have "possibly_sensitive:true".
The bot is in python and I use the stream api method, have already imported tweepy and twystream.
the first approach i tried was to
elif jsonData['possibly_sensitive']
within a several steps query to filter out things i dont want to retweet. It wont even work a single time, basically the output hasnt changed at all.
the second approach was to enhance the track command for the stream.filter alike
keyword = "#hashtag filter:possibly_sensitive"
or tried this too:
keyword = "#hashtag possibly_sensitive:false"
as nothing works and I cannot really find other answers that helped me so far I am this desperated and joined stackoverflow.
Pls help me! Thanks
In the search API, try -filter:safe
I'm trying to integrate reactjs with Odoo, and successfully created components. Now my problem is that I cant get the JSON via odoo. The odoo programmer has to write special api request to make this happen. This is taking more time and code repetitions are plenty.
I tried may suggestions and none worked.
Is there a better way to convert the browse objects, that odoo generate, to JSON ?
Note: Entirely new to python and odoo, please forgive my mistakes, if any mentioned above.
maybe this will help you:
Step 1: Create js that runs reqiest to /example_link
Step 2: Create controller who listens that link #http.route('/example_link', type="json")
Step 3: return from that function json return json.dumps(res) where res is python dictionary and also dont forget to import json.
Thats all, it's not very hard, hope I helped you, good luck.