Wikimedia Commons API query to get count of sub categories and photos in a category - categories

I want to query a Wikimedia Commons category and get the count of sub categories and photos in a category.
For example when you look at the web page "Category:Collections of the Brooklyn Museum" in Wikimedia Commons, you get the list of subcategories.
One of the subcategories
European art in the Brooklyn Museum‎ (7 C, 301 F)
has the numbers 7 C and 301 F which means this has 7 categories and 301 images.
How do I query the Wikimedia Commons to get this category and image count information of subcategories?
I tried the following queries
http://commons.wikimedia.org/w/api.php?action=query&list=categorymembers&cmlimit=100&cmtitle=Category:Collections%20of%20the%20Brooklyn%20Museum
which gives me the category members of the category.
I can do an action render query which produces the html representation from which I can scrape the 7 C and 301 F count information.
What query can I use to get this count information without the html scraping?

You can use prop=categoryinfo for this.
For example, the query:
http://commons.wikimedia.org/w/api.php?action=query&prop=categoryinfo&titles=Category:Collections%20of%20the%20Brooklyn%20Museum
returns:
<api>
<query>
<pages>
<page pageid="21253813" ns="14" title="Category:Collections of the Brooklyn Museum">
<categoryinfo size="105" pages="0" files="88" subcats="17" />
</page>
</pages>
</query>
</api>

Related

T-SQL : getting the column descriptions into a XMLSCHEMA

I have a query where I generate a XMLSCHEMA and a XML sample.
SELECT TOP (10)
filename, queue, owner, resubmitFile,
pages, system, created, server, preflightlogs, status, kit, totalkits
FROM
Preflight_analytics
FOR XML AUTO, XMLSCHEMA ('Preflight_analytics')
All my columns have a description associated with it.
Is it possible to get the column description place inside the xsd like the below sample? I use the xsd to generate documentation and the tool I use, uses the tag <xsd:documentation> to add the description to the docs - like below:
<xsd:attribute name="JobID" fixed="" use="required">
<xsd:annotation>
<xsd:documentation xml:lang="en">Vendors unique ID</xsd:documentation>
</xsd:annotation>
<xsd:simpleType>
<xsd:restriction base="sqltypes:varchar" sqltypes:localeId="1033"
sqltypes:sqlCompareOptions="IgnoreCase IgnoreKanaType IgnoreWidth"
sqltypes:sqlSortId="52">
<xsd:maxLength value="50"/>
</xsd:restriction>
</xsd:simpleType>
</xsd:attribute
I been looking over the docs here haven't found anything yet but still looking.
Thank you
Mike

Umbraco - Displaying a specific image within a macro for-each child of certain node

Umbraco newbie here. I've researched a tonne but can't seem to find what I' looking for.
I have a site with a slider on the homepage, the slider is sitting in a macro which is using a for-each (of a nodes children) with a final goal to display the 'heroImage' image from that doctype. I cant post images as a newbie to this site, but heres my content structure:
HOME
PORTFOLIO
- First Item
- Another Item
ABOUT
CONTACT US
Home, Portfolio, ABOUT and CONTACT US are "Landing Pages" document types, and the children under Portfolio (First Item and Another Item) are "Portfolio Entries" document types. Below is the code on "Landing Page" calling the Slideshow macro.
Portfolio Entry has fields:
heroImage
images
body
Slideshow macro obviously being the highlight there. Easy enough. Heres my macro code where you'll see I'm trying to display the heroImage of the node in question for each 'for-each'.
<xsl:template match="/">
<!-- slider -->
<div id="slideshow">
<div id="slider" class="nivoSlider">
<xsl:for-each select="umbraco.library:GetXmlNodeById(1081)/*[#isDoc and position() < 4]">
<xsl:variable name="mediaId" select="umbraco.library:GetMedia(#id, 'false')/data [#alias = 'umbracoFile']" />
<xsl:if test="$mediaId > 0">
<xsl:variable name="mediaNode" select="umbraco.library:GetMedia($mediaId, 0)" />
<xsl:if test="count($mediaNode/data) > 0 and string($mediaNode/data[#alias='umbracoFile']) != ''">
<img src="{$mediaNode/data[#alias='umbracoFile']}" alt="[image]" />
</xsl:if>
</xsl:if>
</xsl:for-each>
</div>
</div>
<!-- data-transition="slideInLeft" -->
<script type="text/javascript">
$(window).load(function() {
$('#slider').nivoSlider();
});
</script>
</xsl:template>
I feel like im so close, and ran out of search queries as most of the solutions I found were dependant on the imageId being passed onto the macro from the other side of the macro which wouldn't work.
Hope Ive explained this enough and thanks in advance for your help!
First of all, it looks like you're hardcoding the parent node id. In the code you just provided, it seems to only be getting the children of the node with id 1081. From reading what you just posted, it would seem that on all landing pages, you want to display their individual portfolio entries.
Either way, I would stay away from hardcoding IDs. If the node id changes in any way(user deletes the node, it gets exported as a package to the live environment, etc), your code will stop working. I'd just use $currentPage instead.
Judging by your filter, I imagine you only want the first 3 items to show in the slider. The code seems correct, but you seem to be using the old schema and its associated xpath. If you're using a newer version of Umbraco, the way you reference node data in xslt would have changed. I would guess that you've found many code examples and tried merging them together, without realising they wouldn't call the same schema.
This wiki link will provide more information, and hopefully fix your problem if you're using the wrong xpath.

Facebook FQL returning inconsistent results?

I've got a question around why some items are not returning via a Facebook FQL query.
The following query:
https://api.facebook.com/method/fql.query?query=select%20page_id,%20name,%20type,%20fan_count%20from%20page%20where%20name=%27Bauhaus%27%20and%20type%20=%20%27MUSICIAN/BAND%27%20order%20by%20fan_count%20desc
Is supposed to return me pages whose name = 'Bauhaus' and type is 'Musician/Band'. The result is:
<fql_query_response list="true">
<page>
<page_id>186907181359330</page_id>
<name>Bauhaus</name>
<type>MUSICIAN/BAND</type>
<fan_count>1</fan_count>
</page>
<page>
<page_id>175833025805207</page_id>
<name>Bauhaus</name>
<type>MUSICIAN/BAND</type>
<fan_count>0</fan_count>
</page>
</fql_query_response>
If I then add a constraint, page_id=109194179106090, which doesn't appear in the above list: https://api.facebook.com/method/fql.query?query=select%20page_id,%20name,%20type,%20fan_count%20from%20page%20where%20page_id%20=%20109194179106090, I get this result:
<fql_query_response list="true">
<page>
<page_id>109194179106090</page_id>
<name>Bauhaus</name>
<type>MUSICIAN/BAND</type>
<fan_count>100527</fan_count>
</page>
</fql_query_response>
Why should adding a constraint return me an item that isn't in the original query?
In FQL, adding a constraint of a page id automatically adds it to the query, assuming that you know exactly what you want and won't be narrowing it down by other criteria.

iPhone: How to handle Core Data relationships

I'm new to Core Data and databases in general. Now I need to parse a XML and store the contents in Core Data. The XML looks something like this:
<books>
<book id="123A" name="My Book">
<page id="95D" name="Introduction">
<text id="69F" type="header" value="author text"/>
<text id="67F" type="footer" value="author text"/>
</page>
<page id="76F" name="Chapter 1">
<text id="118" type="selection">
<value data="1">value1</value>
<value data="2">value2</value>
<value data="3">value3</value>
</text>
</page>
</book>
<book id="124A"...
From my understanding I would need four Entities, like "Books", "Book", "Pages" and "Text". I wonder how to set the relationships correctly and how to add for example a Page object to a Book object and how to retrieve a Text object attribute's value? The tutorials I have found mostly deal with one Entity so I didn't really get the idea.. Gtrateful for any help!
No, you'd need three entities. You can think of "Books" as the CoreData database you're using. The CoreData database then includes a number of entities called book.
I think the data model you have is a bit weird, but I guess it makes sense for your application. To map it to CoreData I would:
Add the entities Book, Page, Text
Add a bookId, pageId, textId to them, respectively.
Then add a relation from Page to Book, and from Text to Page.
By then you should be able to print out a whole book by asking for all Pages that have
Book = the book you're interested in
and then order all those Pages by their pageId
and in order, ask for all texts that have
Page = the current page
then order those Texts by their textId.
What might be a problem is that a Text can have multiple Values, as seen in your XML above. You could use this by adding another entity called Value, but I would probably solve it by adding the attributes "value" and "type" to the Text entity directly. (You could then use "value" as a second sort key when printing out a page.
Check out these links:
http://developer.apple.com/iphone/library/documentation/Cocoa/Conceptual/CoreData/
http://developer.apple.com/cocoa/coredatatutorial/index.html (for regular Cocoa, but the same principles hold so this should help)

Displaying entries per category in ExpressionEngine

So, I've searched, and found a few posts that kinda get me what I want, but it still doesn't quite work. This post especially seemed closest to what I was trying to achieve, and I built my code off of it: http://expressionengine.com/forums/viewthread/168142/
To explain; I have a series of entries, each entry is assigned to only one category. I'd like to list out these categories and, beneath each category, list out the entries with one of their custom fields. Like so:
Category 1
Item 1
Item 2
Category 2
Item 1
Item 2
So, here's my code as it stands now, which lists out the categories, but doesn't spit out any of the entries at all:
{exp:channel:categories channel="faq-question" style="linear"}
<section class="faq-category-container closed">
<h1 class="faq-category-header">{category_name}</h1>
<dl>
{exp:query sql="
SELECT title, url_title AS urlt, cat_id
FROM exp_channel_titles
NATURAL JOIN exp_category_posts
WHERE channel_id = '7' AND cat_id = '{category_id}'
ORDER BY title ASC"
}
{embed="jazz-camp/faq-cat-list" faqlink="{urlt}"}
{/exp:query}
</dl>
</section><!-- end .faq-category -->
{/exp:channel:categories}
And the embedded template it references:
{exp:channel:entries channel="faq-question" url_title="{embed:faqlink}"}<!-- entry -->
<dt>{title}</dt>
<dd>
{faq_content}
</dd>
{/exp:channel:entries}
Any help would be most appreciated!
This may be a very basic example of what you're after:
{exp:channel:categories style="linear"}
<h1>{category_name}:</h1>
{exp:channel:entries category="{category_id}" dynamic="no"}
<p>{my_custom_field}</p>
{/exp:channel:entries}
{/exp:channel:categories}
So, here's what I ended up with at the end (courtesy of some help over at the EE boards):
{exp:channel:categories channel="faq-camp" style="linear" show_empty="no"}
<section class="faq-category-container closed">
<h1 class="faq-category-header">{category_name}</h1>
<div class="faq-questions-container">
<dl>
{embed="jazz-camp/faq-cat-list" faqlink="{category_id}" faqparent="faq-camp"}
</dl>
</div><!-- end .faq-questions-container -->
</section><!-- end .faq-category -->
{/exp:channel:categories}
And as for the embed, it looks like this:
{exp:channel:entries channel="{embed:faqparent}" category="{embed:faqlink}" dynamic="no"}<!-- entries -->
<dt>{title}</dt>
<dd>
{faq_answer}
</dd>
{/exp:channel:entries}
The reason for the embed has to do with how things are pulled in with regards to getting the correct channel entries; simply having the {exp:channel:entries} inline in the page didn't quite work.
The Category Archive tag might be helpful to you:
http://ellislab.com/expressionengine/user-guide/modules/channel/category_archive.html