How do I get the pageid from a Wikipedia page? - python-2.7

In a Flask app, or even better just using wikipedia APIs, how can I get the pageid from a Wikipedia url?
I mean from this http://en.wikipedia.org/wiki/Stack_Overflow to this http://en.wikipedia.org/wiki?curid=21721040
From the API sandbox I can work it out but only as a search from a title, not from a singular URL.
Said search example:
https://en.wikipedia.org/wiki/Special:ApiSandbox#action=query&prop=pageprops&format=json&ppprop=wikibase_item&titles=Stack%20Overflow
Can I query for it in a more straightforward way and without resorting to a wikipedia search? I mean I already know the human readable url...

No, you cannot use URLs in the API, you need to use either page names or page ids to identify articles.
Notice that the https://en.wikipedia.org/w/api.php?action=query&titles=Stack%20Overflow you found is not a "search", it's just exactly the query to get you the page id from the title. Use it.

Related

facebook graph api place search more than one type in one request

I'm using facebook graph api place search to get nearby places .
in the docs is written to send these request to get data :
https://graph.facebook.com/search?q=Restaurants&type=place&center=32.075267,34.774997&distance=600&access_token=
but i need to get not only Restaurants but also food,Clothing Store,bar and more categories but in one request . is it possible ?
No, it's not possible to search for exclusive keywords at once. Be aware that you can't even search for page categories as you seem to believe. The /search endpoint does a full text search on the respective object (page, place, event etc.).
See
https://developers.facebook.com/docs/graph-api/using-graph-api#search

Making an autocomplete field for locations using Facebook Places

I'm looking to make something similar to the location autocomplete in Facebook's "Create Event" page. It gives location name, address, and number of check-ins. Do you know how is it done? Because the Places table does not have any field for address and nubmer of checkins.
https://developers.facebook.com/docs/reference/fql/place/
I was going to use Factual, but after some trial and error, found out that facebook is more comprehensive.
Try this query. It ensures that the checkins field is also returned as part of the search request.
https://graph.facebook.com/search?q=coffee&type=place&center=37.76,-122.427&distance=1000&fields=location,name,id,checkins
There is a graph place search API.
https://graph.facebook.com/search?q=coffee&type=place

How to get external URLs likes

I'm trying to get the list of all the pages that a user "likes", both Facebook pages and external pages.
I know that the facebook pages (such as http://www.facebook.com/DealExtremeFans) I can obtain them with the "me/likes" value from the Graph.
But for a page such as (http://mashable.com/2012/01/20/advertisers-this-is-what-an-nfl-fan-looks-like-infographic/) that has a like button (under the title) I don't see how to get those likes.
Is this possible? If not, are you planning on adding support for this any time soon?
Thanks
EDIT:
According to the response below, even though they are added via the "like" button they are really "Shares".
Now my question is, how do I get those shares? what's the graph for them? I tried "me/shares" but doesn't exist.
Is there a way?
Yes it is possible, but it looks like that URL only has shares:
Click here.
And here is a link to a tutorial for getting the data via jQuery.

Django API: how to construct URLs, and handle queries?

Forgive this newbie (and possibly subjective - I don't know) question.
I want to add a REST API to my site. For example, I have a URL that is /post/ that shows all posts, and I'd like to give users a way to get all posts back in JSON.
Is is better to:
define a new API URL structure (e.g. /api/rest/post/ to return all posts in JSON)
use the existing URL structure, and allow users simply to append /json/ on the end of each URL to get JSON objects back? (e.g. /post/json/ to return all posts in JSON)
If the latter, then is there a standard way to implement it, in terms of views? Should I simply add an optional json parameter to all my views?
Thank you for your advice.
Take a look at Piston, which is a Django plugin to handle REST APIs.
Listen to the previous commenter's advise. But in particular that's probably better to use new API URL structure (/api/rest/post/ as you've said). Separating totally different kinds of functionality is always good for your project. In other words, you can place your API documentation at /api/docs/, and it will look natural. If you use same URL structure, it will be not so obvious where to place your docs.
The answer is of course also subjective.

django - the best way to combine pagination with filtering and request.POST - like stackoverflow - ajax?

I want to combine pagination with filtering. Since I have a lot of filters I do not want to send them per GET request, since the URLs get really ugly.
Since django pagination uses GET request to pass the page parameters, I do not know how I can combine these two approaches.
Any idea?
Great add-on would be: How can I combine this approach with table sort? :-)
Edit:
Actually it should work like the pagination of stackoverflow - user questions. If a user clicks on a page number one is shown the correct page, without showing the get parameters in the url.
This is the url called.
https://stackoverflow.com/api/userquestions.html?page=2&pagesize=10&userId=237690&sort=Recent
But the url shown in the browser is neat and short.
Seems to be ajax. Anybody an idea how to implement this? :)
If the URL is not shown in the browser`s address bar, I do not care about whether it is beautiful or not.
Edit: The solution:
Make an ajax update with all filter parameters passed to the view. This should help you get started with implementing ajax for your site: link
Thus the GET parameters never show up in the address bar.
have you checked the paginate application for django?
it may help you a lot, use it all the time :D
http://code.google.com/p/django-pagination/
Have you considered django-tables2? It gives you django-admin style tables without you having to write the logic yourself.
maybe you can use the urs, something like:
http://oursite.com/something/filter1/filter2/3/
the doc -> http://docs.djangoproject.com/en/1.1/topics/http/urls/
I figured out two solutions:
Instead of using just hyperlinks use it inside a POST form, i dont have any example now but i remember have used that for REST functions in Ruby on rails
Save the query info in a session.
Hope this help.