Without much success, I've been trying to retrieve images (and extracts) from all posts in a certain category.
Here's a query to get the images from the main page, but I haven't found a query for specific categories.
api.php?action=query&prop=images&titles=Main%20Page
Using search seemed more promising, but still it's not what I'm looking for.
api.php?action=query&list=search&format=jsonfm&srsearch=incategory:Marine_mammals
The second query could've been a good starting point if it provided page IDs.
What you want is to use the categorymembers generator, by adding &generator=categorymembers&gcmtitle=Category%3AMarine_mammals in place of &titles. Since I discovered generators I barely remember using the API for anything else. I'd also recommend sticking to mainspace. So for example,
https://en.wikipedia.org/w/api.php?action=query&prop=images&format=json&imlimit=10&generator=categorymembers&gcmtitle=Category%3AMarine_mammals&gcmnamespace=0&gcmlimit=50
Gives:
{"query-continue":{"images":{"imcontinue":"60257|Ursus_maritimus_4_1996-08-04.jpg"}},"query":{"pages":{"149269":{"pageid":149269,"ns":0,"title":"Blubber"},"19289045":{"pageid":19289045,"ns":0,"title":"Instituto Via Delphi"},"2178272":{"pageid":2178272,"ns":0,"title":"List of marine mammals of Australia"},"60257":{"pageid":60257,"ns":0,"title":"Marine mammal","images":[{"ns":6,"title":"File:Desmostylus2DB.jpg"},{"ns":6,"title":"File:Estuary-mouth.jpg"},{"ns":6,"title":"File:FL fig04.jpg"},{"ns":6,"title":"File:Humpback Whale underwater shot.jpg"},{"ns":6,"title":"File:Hydrurga leptonyx edit1.jpg"},{"ns":6,"title":"File:Maldivesfish2.jpg"},{"ns":6,"title":"File:Oceanic whale pump - journal.pone.0013255.g001.tiff"},{"ns":6,"title":"File:PikiWiki Israel 15217 Dolphin.JPG"},{"ns":6,"title":"File:Sea lion family.JPG"},{"ns":6,"title":"File:Sea otter cropped.jpg"}]},"36425597":{"pageid":36425597,"ns":0,"title":"Marine mammals as food"},"3703749":{"pageid":3703749,"ns":0,"title":"Marine otter"},"644379":{"pageid":644379,"ns":0,"title":"North Atlantic Marine Mammal Commission"},"1336536":{"pageid":1336536,"ns":0,"title":"Sea mink"},"567471":{"pageid":567471,"ns":0,"title":"Sea otter"},"2764345":{"pageid":2764345,"ns":0,"title":"United States Navy Marine Mammal Program"}}}}
Related
I'm working with MapBox Geocoding API to have suggestions of addresses in the location search feature of my website.
The following is a sample call:
https://api.mapbox.com/geocoding/v5/mapbox.places/Zur.json?country=ch&limit=5&proximity=8.765.432&language=en-GB&access_token=***
My goal is to enforce the api to return only results that include a zipcode.
For example if I input "Zur" (limiting the search to Swiss) I get the following:
- Zürich, Zürich, Switzerland
- Zürich, Switzerland
- Zürich Airport, Flughafenstrasse, Kloten, Zürich 8302, Switzerland
- Zurich, Buchs, Zürich 8107, Switzerland
The expected results should be without the first two lines, as they don't have a zipcode.
I tried implementing myself the removal of results without the zipcode on client side (just after I got an answer from the api), but it is a suboptimal solution (for example it doesn't ensure to have enough results).
I was not able to find such feature in MapBox. Is there a better solution out of there?
Just add ?types=address
See all list of types:
https://docs.mapbox.com/api/search/geocoding/#data-types
I want to get minimal information of a Wikipedia page using MediaWiki API like DuckDuckGo. For example for Steve Carell: https://duckduckgo.com/?q=steve+carell&t=hp&ia=news&iax=about
How can I get this information with a Wikipedia url (eg https://en.wikipedia.org/wiki/Steve_Carell) in HTML format?
You can use the MediaWiki API for that. There's an extension, TextExtracts, which is exactly for that (and it is installed on Wikipedia).
In your case, e.g.:
https://en.wikipedia.org/w/api.php?action=query&prop=extracts&exsentences=1&titles=Steve%20Carell
will return something like:
<p class=\"mw-empty-elt\">\n</p>\n\n<p class=\"mw-empty-elt\">\n \n</p>\n<p><b>Steven John Carell</b> (<span></span>; born August 16, 1962) is an American actor, comedian, producer, writer and director.</p>
You can customize how many sentences (or characters) the API returns, as well, please consult the API documentation for that.
There's also the way to retrieve the short description, which is saved at Wikidata (and visible in the mobile view of Wikipedia). This call would be:
https://en.wikipedia.org/w/api.php?action=query&prop=pageprops&titles=Steve_Carell
This returns the following property in the pageprops of the page:
"wikibase-shortdesc": "American actor"
This may fit better depending on your use case.
You can even get both of the results with a single, combined, request:
https://en.wikipedia.org/w/api.php?action=query&prop=extracts|pageprops&exsentences=1&titles=Steve_Carell
I want to parameterize my gherkin feature file steps by taking data from some other JSON file. Any suggestions for this. I searched almost everywhere but couldn't find answers.
I am aware of scenario where examples being used with multiple values for a variable using scenario outline in gherkin feature file but not looking for that.
Currrently I am using like this and below values in quotes are being passed to step definitions
Scenario: Buy last coffee
Given There is "Starbucks" coffee
And I added "Sugarless" syrup
Expected: I want to get data of variables from JSON file or any other file also and pass these data values to step definition functions. is it possible?
gherkin feature file:
Scenario: Buy last coffee
Given There is "${data.coffeeshop}" coffee
And I added "${data.sugarType}" syrup
data.json:
{
"coffeeshop": "starbucks",
"sugarType": "Sugarless",
}
Its a common Cucumber anti-pattern to try and inject data into feature files. Its difficult to do partly because it goes against the whole ethos of writing good feature files.
The way Cucumber wants you to work is to push the details down and to abstract the process so that the feature is not doing any programming (looping, iterating over steps etc.). You can improve your practice here by thinking about what is in the json file and why you want to iterate over it.
Your json file seems to want to iterate over a number of coffee shops to see if they can make a coffee. So your feature could give the group of coffee shops a name and then talk about whether the group of shops can do something. Perhaps something like
Scenario: Seattle coffee shops can make an iced mocha
Given our coffee shops are located in Seattle
Then our coffee shops can make an iced mocha
and implement the scenarios
Given 'our coffee shops are located in Seattle' do
#coffee_shops = get_seattle_coffee_shops
end
Then 'our coffee shops can make an iced mocha' do
#coffee_shops.each do | shop |
assert can_make_recipe(
shop: shop,
recipe: Recipes::IcedMocha
)
end
end
The above is a very crude start, and I would pull out more code from the step definitions into helper methods. The key part I'm trying to illustrate here is that the scenario and steps are know working with a group of coffee shops rather than just one coffee shop
In your scenario the helper method get_seattle_coffee_shops would load and process your json to get your data. Because this processing has been pushed down from the feature file (non-code) into code this operation is now much easier to implement. This "Pushing the How Down" is a very important technique when Cuking, and is how you should approach any problem which involves programming feature files.
I have implemented similar approach recently. I am matching json data based on scenario name. the json will look like this.In this way, you can dynamically match test data with your scenarios.
{
"scenario1":
{
"coffeeshop": "starbucks",
"sugarType": "Sugarless"
},
"scenario2":
{
"coffeeshop": "starbucks",
"sugarType": "Sugarless"
}
}
your feature file will look like this,
Scenario: senario1
Given There is coffee
And I added syrup
Scenario: senario2
Given There is coffee
And I added syrup
If possible, i want to return the results in Json or XML format. Is there any ways to do so? Earlier I did it using freebase.com but it is now deprecated. Please help.
This query would look a lot like the one to get the list of all films on Wikidata but adding another filter:
instead of http://wdq.wmflabs.org/api?q=claim[31:11424] (return all the entities marked as instances of film), you would do
http://wdq.wmflabs.org/api?q=claimCLAIM[31:11424] AND CLAIM[495:884] (return all the entities marked as instances of film and South Korea (Q884) as country of origin (P495))
http://wdq.wmflabs.org/api?q=claimCLAIM[31:11424] AND CLAIM[495:423] (the same for North Korea (Q423))
Then to parse the results and get the entities data, it would be the same as for the list of all the films
Remarques:
you will probably need to encode those URLs to get something that looks like: http://wdq.wmflabs.org/api?q=CLAIM%5B31%3A11424%5D%20AND%20CLAIM%5B495%3A884%5D
here is the full API documentation. Notice that this is an experimental API, which might be replaced in the coming year
The overview on Wikipedia may be more complete than Wikidata, as you've noticed yourself also. However, I could only find overviews per year, such as on https://en.wikipedia.org/wiki/List_of_South_Korean_films_of_2015.
To get a list of titles from that page, you would first retreive the raw wikicode of the page: https://en.wikipedia.org/w/index.php?action=raw&title=List_of_South_Korean_films_of_2015, and then run a regular expression such as /\{lang\|[^\|]+\|([^\}]+)/g on the code.
This returns a list of 149 titles.
I'm searching for a particular item that is listed as available for in-store pickup only, but not in my area.
I'd like to use the API to find out which stores do have that item in stock so I can phone a friend that lives in one of those areas and get them to pick it up.
So... How can I list the stores that have a particular item in stock?
Answer
The geographic center of the United States is 39°50' (39.8333), -98°35' (-98.5833)
The width United States is approximately 3,000 miles.
So if we search a radius of 2000 miles in any direction from that point we get:
http://api.remix.bestbuy.com
/v1/stores(area(39.8333,-98.5833,2000mi))
+products(sku=YOUR_SKU_ID)
?format=json
&pageSize=100
&page=1
&show=storeId,storeType,city,region,name,products.name,products.sku,products
&apiKey=YOUR_API_KEY
http://api.remix.bestbuy.com/v1/stores(area(39.8333,-98.5833,2000mi))+products(sku=6461052)?format=json&pageSize=100&page=1&show=storeId,storeType,city,region,name,products.name,products.sku,products&apiKey=YOUR_API_KEY
And you'll be surprised that while 1419 stores have Black Ink'd Skullcandy Earbuds in stock the day before Christmas, 0 of them have the Marth Amiibo, and 67 have the Star Fox Amiibo... who knew?
The API does provide a way to check for product availability in specific stores. Here is an example query (you need to substitute in your own apiKey) that uses coordinates and a radius within which to search:
http://api.remix.bestbuy.com/v1/stores(area(44.882942,-93.2775,10mi))+products(sku=6461052)?apiKey=yourApiKey&format=json&show=storeId,storeType,city,region,name,products.name,products.sku,products
There is documentation about this feature here:
https://developer.bestbuy.com/documentation/stores-api#documentation/stores-api-in-store-availability
You will find in the documentation that you can also search for availability at a specific store, or use a postal code. But I think using the coordinates may fit the case described in your question best.