How to get main article for a category using wikipedia dumps? - mediawiki

Main article for category
Given any category, I need to get the main article for the same if it exists.

You can use Mediawiki action API to get the information about the category like namespace, name, sortkeyprefix. As an example the query for category:Telegraphy produced as on today
{
"batchcomplete": "",
"continue": {
"cmcontinue": "page|2c322a4c304e4032320450324032364c2a4838011701dcbddc0c|21155313",
"continue": "-||"
},
"query": {
"categorymembers": [
{
"pageid": 30010,
"ns": 0,
"title": "Telegraphy",
"sortkey": "04030650324032364c2a48385a011001c4dc0d",
"sortkeyprefix": " ",
"type": "page",
"timestamp": "2018-05-18T16:59:21Z"
},
{
"pageid": 35475502,
"ns": 0,
"title": "Acme Commodity and Phrase Code",
"sortkey": "2a2e4232042e46424246303a505a042a44300448384c2a4e32042e463032012201dcc2dcb9dcc0dc07",
"sortkeyprefix": "",
"type": "page",
"timestamp": "2012-04-12T20:44:45Z"
},
....
}
In the results, the page for which the sortkeyprefix is space ( "sortkeyprefix": " " for the article "Telegraphy") is the main article for category.
In English Wikipedia you may find sometimes the main article for the category by the use of "Template:Cat main" along with brief description. If you need to find such usages also, then you need to get the Wikitext for the category page and look for the usage of that template. (Example)

Related

Google json style guide: How to send single item response?

There is an items node in the specifications which says it is for an array of items, like paging items, youtube video list
What if I have GET request on a single item, how should the response be formatted ?
Just to one item in the array?
items:[item]
https://google.github.io/styleguide/jsoncstyleguide.xml
I don't think #tanmay_vijay's answer is correct or nuanced enough as it seems that single item responses are in arrays in the YouTube example in the docs.
{
"apiVersion": "2.0",
"data": {
"updated": "2010-02-04T19:29:54.001Z",
"totalItems": 6741,
"startIndex": 1,
"itemsPerPage": 1,
"items": [
{
"id": "BGODurRfVv4",
"uploaded": "2009-11-17T20:10:06.000Z",
"updated": "2010-02-04T06:25:57.000Z",
"uploader": "docchat",
"category": "Animals",
"title": "From service dog to SURFice dog",
"description": "Surf dog Ricochets inspirational video ...",
"tags": [
"Surf dog",
"dog surfing",
"dog",
"golden retriever",
],
"thumbnail": {
"default": "https://i.ytimg.com/vi/BGODurRfVv4/default.jpg",
"hqDefault": "https://i.ytimg.com/vi/BGODurRfVv4/hqdefault.jpg"
},
"player": {
"default": "https://www.youtube.com/watch?v=BGODurRfVv4&feature=youtube_gdata",
"mobile": "https://m.youtube.com/details?v=BGODurRfVv4"
},
"content": {
"1": "rtsp://v5.cache6.c.youtube.com/CiILENy73wIaGQn-Vl-0uoNjBBMYDSANFEgGUgZ2aWRlb3MM/0/0/0/video.3gp",
"5": "https://www.youtube.com/v/BGODurRfVv4?f=videos&app=youtube_gdata",
"6": "rtsp://v7.cache7.c.youtube.com/CiILENy73wIaGQn-Vl-0uoNjBBMYESARFEgGUgZ2aWRlb3MM/0/0/0/video.3gp"
},
"duration": 315,
"rating": 4.96,
"ratingCount": 2043,
"viewCount": 1781691,
"favoriteCount": 3363,
"commentCount": 1007,
"commentsAllowed": true
}
]
}
}
It could however be that it depends on the resource being targeted from the request. This is the way it is in the competing JSONAPI standard.
From JSONAPI standard:
A logical collection of resources MUST be represented as an array, even if it only contains one item or is empty.
You don't need to have items field for showing single item. If you're sure your API is always going to return single object, you can return it as data itself.
{
"data": {
"kind": "user",
"fields": "author,id",
"id": "bart",
"author": "Bart"
}
}
Fields such as data.kind data.fields data.etag data.id data.lang data.updated data.deleted can still be used here.
Source for snippet docs

facebook graph api sharedpost get amount of likes from the page that shared

I use the sharedpost endpoint to retrieve the pages that shared my post like this:
{post_id}/sharedposts?fields=likes.summary(1),id,created_time,from.summary(1)&limit=1500
This will return the data like:
{
"id": "{sharedpost_id}",
"created_time": "2017-05-13T23:01:51+0000",
"from": {
"name": "Page that shared",
"id": "Id of page that shared"
},
"likes": {
"data": [
],
"summary": {
"total_count": 0,
"can_like": false,
"has_liked": false
}
}
}
Now some posts get a shitload of shares so I want to filter only the shares by pages that have above a certain amount of likes.
Now I can make a second call to the api which asks for the amount of likes but I hope it would be possible to do this in the same request.
So The desired output would be:
{
"id": "{sharedpost_id}",
"created_time": "2017-05-13T23:01:51+0000",
"from": {
"name": "Page that shared",
"id": "Id of page that shared"
"likes: : "Likes of the page that shared"
},
"likes": {
"data": [
],
"summary": {
"total_count": 0,
"can_like": false,
"has_liked": false
}
}
}
So with the likes of the page included in the from.
Is this possible?
Thanks in advance!
Can be done using Field Expansion:
/post-id/sharedposts?fields=from{name,fan_count}
And if you need this not only for single posts, but for all posts in a page’s feed, you can also move that “one level up”, like so:
/page-id/feed?fields=sharedposts{from{name,fan_count}}
I am not exactly sure if that still works, if you also get shared posts by users returned - in that case it might throw an error, that fan_count is not an existing field on the user object.
This would only be relevant for posts shared by users that have logged in to your app, and granted it user_posts permission (because only then would you see those posts show in the sharedposts edge in the first place) - so if that is not applicable in your situation, it will be fine; otherwise I suggest you test this case before relying on it.

Deezer api search url album cover is missing

Since two days we got a problem with the Deezer Api on this url:
http://api.deezer.com/search/autocomplete?q=Jean
In the object returned, some fields are now missing in the album object and in the base object.
The fields which usually contain the images disappeared.
{
"id": 122440564,
"readable": true,
"title": "Aloha",
"title_short": "Aloha",
"title_version": "",
"link": "http://www.deezer.com/track/122440564",
"duration": 218,
"rank": 0,
"explicit_lyrics": false,
"preview": "http://cdn-preview-9.deezer.com/stream/9f7248e8744c135d4878ae851d8bb881-4.mp3",
"artist": {
"id": 5542423,
"name": "Møme",
"link": "http://www.deezer.com/artist/5542423",
"picture": "http://api.deezer.com/artist/5542423/image",
"picture_small": "http://cdn-images.deezer.com/images/artist/6054372bc5d6dc0a2d355d5a2d55242a/56x56-000000-80-0-0.jpg",
"picture_medium": "http://cdn-images.deezer.com/images/artist/6054372bc5d6dc0a2d355d5a2d55242a/250x250-000000-80-0-0.jpg",
"picture_big": "http://cdn-images.deezer.com/images/artist/6054372bc5d6dc0a2d355d5a2d55242a/500x500-000000-80-0-0.jpg",
"picture_xl": "http://cdn-images.deezer.com/images/artist/6054372bc5d6dc0a2d355d5a2d55242a/1000x1000-000000-80-0-0.jpg",
"tracklist": "http://api.deezer.com/artist/5542423/top?limit=50",
"type": "artist"
},
"album": {
"id": 12811488,
"title": "Aloha",
"tracklist": "http://api.deezer.com/album/12811488/tracks",
"type": "album"
},
"type": "track"
},
I checked in the Deezer Api documentation, and apparently the version doesn't change, and, based on the documentation, the album object normally contain the cover album:
http://developers.deezer.com/api/search/album
Did anyone got the same issue ? I tried to tweet them and I also sent an email to api#deezer.com.
It has been fixed, we had some side effects that are now resolved.

Create multi-level structure for firebase

I am newbie to angularjs and firebase.
I want to create a small web app for searching books. I am getting stuck at structuring database.
My database is 3 levels: Category -> Topics -> Books. For each book, I save 2 values for Book Store and Book Content.
I am trying to use flatten-type of json as below:
{
"book":{
"category":{
"finance":{
"catId": 1,
"catName": "Finance"
},
"education":{
"catId": 2,
"catName": "Education"
}
},
"topic": {
"finance":{
"topicName": "Earn some money",
"topicName": "Buy some thing"
},
"education":{
"topicName": "Learn some thing",
"topicName": "Take some class"
}
},
"book":{
"finance":{
"book1": {
"bookName": "A millionaire",
"bookContent": "This book very good"
},
"book2":{
"bookName": "New book",
"bookContent": "Content of book"
}
}
}
}
}
I want to get all books belonging to a topic, but I don't know who to structure database for it to use ng-repeat in AngularJS.
Please help me. Thanks!

WordPress jSON API how to return data with jquery?

I enabled json API successfully in a WordPress blog but I have hard time returning data with jQuery.
http://example.com/?json=1&count=1&include=title
Here is the json format. Ideally I'd like to append in a div called #homeblog, the last post title, linked to the post itself.
{
"status": "ok",
"count": 1,
"count_total": 1,
"pages": 1,
"posts": [
{
"id": 1,
"type": "post",
"slug": "hello-world",
"url": "http:\/\/localhost\/wordpress\/?p=1",
"title": "Hello world!",
"title_plain": "Hello world!",
"content": "<p>Welcome to WordPress. This is your first post. Edit or delete it, then start blogging!<\/p>\n",
"excerpt": "Welcome to WordPress. This is your first post. Edit or delete it, then start blogging!\n",
"date": "2009-11-11 12:50:19",
"modified": "2009-11-11 12:50:19",
"categories": [],
"tags": [],
"author": {
"id": 1,
"slug": "admin",
"name": "admin",
"first_name": "",
"last_name": "",
"nickname": "",
"url": "",
"description": ""
},
"comments": [
{
"id": 1,
"name": "Mr WordPress",
"url": "http:\/\/wordpress.org\/",
"date": "2009-11-11 12:50:19",
"content": "<p>Hi, this is a comment.<br \/>To delete a comment, just log in and view the post's comments. There you will have the option to edit or delete them.<\/p>\n",
"parent": 0
}
],
"comment_count": 1,
"comment_status": "open"
}
]
}
If you want to append some data returned by the JSON api to a page you would need something like:
$(document).ready(function(){
$.getJSON("http://example.com/?json=1&count=1",function(data) {
$('body').append('<div id="homeblog">'+data.posts[0].title+'</div>');
}
I have removed the include=title part of the json call because that excludes everything else. You are using getJSON to return the post data, then it is just a case of constructing your html and append ing it to the page somewhere (in my case right onto the <body> tag)
EDIT: there is a wordpress stackexchange for wordpress questions. you will have more luck asking questions like this over there.
(added a right bracket)