View unanswered posts | View active topics

Reply to topic  [ 10 posts ] 
User avatar

Joined: Mon Sep 08, 2008 3:16 pm
Posts: 227
Location: Elk Grove, California
Post Test for feed-level values outside {%REPEAT% FeedItems} loop
In a Channel Report, is it possible to test for feed-item-level values outside of a {%REPEAT% FeedItems}{%/REPEAT%} loop?
I'm thinking that the answer is no, and it's not a big deal as I could always write a post-processing command to remove the empty Channel headings, but I just thought I'd ask.

Like maybe I'd only like to output the Channel-level information if the Channel contains certain metadata.

Here's an example:
Code:
{%?GROUP-ITEMS-BY-CHANNEL%}

  {%REPEAT% Channels-IfGroupingItems}

    {%?ITEM-METADATA% geo/longitude}
<!--
Add some Channel-level header info, outputing the channel name, etc. only if the Channel contains geo/longitude metadata
-->
    {%ENDIF%} <!-- ITEM-METADATA% geo/longitude -->
  {%/REPEAT%} <!-- Channels-IfGroupingItems -->
{%ENDIF%} <!-- GROUP-ITEMS-BY-CHANNEL -->

I've tried the above example as well as things like:

{%?ITEM-METADATA% FeedItems/geo/longitude}
{%ENDIF%}

Should I go the post-processing route?

Thanks for entertaining these wacky ideas! :lol:


Sun Dec 12, 2010 4:10 am
Profile
Site Admin
User avatar

Joined: Fri Feb 07, 2003 8:48 am
Posts: 2902
Location: Melbourne, Australia
Post Re: Test for feed-level values outside {%REPEAT% FeedItems}
kevotheclone wrote:
I'm thinking that the answer is no

You think right, you can't. It doesn't make any sense since you need the context of a particular feed item. In your example, when you check for the presence of geo metadata in a feed item, which feed item is it supposed to check? There could be many in that report or channel summary.

I think you're assuming that either all feed items will have it, or none of them will, which may or may not be the case. You could maybe iterate through the feed items and if you find one that has geo metadata, set a flag, then generate your channel header code based on that flag.


Sun Dec 12, 2010 6:57 am
Profile WWW
User avatar

Joined: Mon Sep 08, 2008 3:16 pm
Posts: 227
Location: Elk Grove, California
Post Re: Test for feed-level values outside {%REPEAT% FeedItems}
support wrote:
I think you're assuming that either all feed items will have it, or none of them will, which may or may not be the case.

Actually I was thinking of a SOME, ANY or EXISTS kind of thing. If one or more Channel's feed items contains the desired Metadata, then output the Channel-level information and continue processing the feed items, where I can filter on a feed-item-by-feed-item basis.

I didn't think this {%?ITEM-METADATA% geo/longitude} would work, but I hoped that something like this {%?ITEM-METADATA% FeedItems/geo/longitude} or {%?FeedItems% ITEM-METADATA/geo/longitude} would work.

Of course the post-processing command allows me a way to remove the excess Channel-level information, and since this output format is well-formed XML it's pretty easy to process. So it's not a big deal that I can't do this directly in a Channel Report; Awasu still provides a way to achieve my goal.


Tue Dec 14, 2010 7:31 pm
Profile
Site Admin
User avatar

Joined: Fri Feb 07, 2003 8:48 am
Posts: 2902
Location: Melbourne, Australia
Post Re: Test for feed-level values outside {%REPEAT% FeedItems}
kevotheclone wrote:
Of course the post-processing command allows me a way to remove the excess Channel-level information

It'd be better if everything could be self-contained in the report template - it's one less thing the user has to set up.

I was thinking something like this:
Code:
    iterate over all channels:
    {
        if channel has geo metadata then
            set javascript flag
    }
    ...
    if javascript flag is set then
        generate channel header code


Wed Dec 15, 2010 5:12 am
Profile WWW
User avatar

Joined: Mon Sep 08, 2008 3:16 pm
Posts: 227
Location: Elk Grove, California
Post Re: Test for feed-level values outside {%REPEAT% FeedItems}
support wrote:
It'd be better if everything could be self-contained in the report template - it's one less thing the user has to set up.
I agree that's why I asked the question.

Background
This Channel Report generates Keyhole Markup Language (KML) an XML vocabulary used by Google Earth and geographic programs. Since it's XML there is no embedded JavaScript that can act upon a flag and delete the "excessive elements".

There are two solutions to the problem of excessive Channel-level elements. Luckily Awasu already provides the functionality to implement both of these solutions:
  1. Delete the "excessive elements" with a post-processing command
  2. Don't create the "excessive elements" to begin with

1. Delete the excessive elements with a post-processing command
As a way to exercise my slowly-fading Python skills, I whipped up a post-processing script that removes <Folder> elements if they do not contain any <Placemark> children elements.

Code:
# --- GLOBAL DEFINITIONS ----------------------------------------------

import os
import win32com.client
import sys

# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -

def removeEmptyFolders( kmlFilePath ) :
    domDoc = win32com.client.Dispatch( "MSXML.DOMDocument" )
    domDoc.load( kmlFilePath );

    docNode = xml.selectSingleNode( "/kml/Document" )
    emptyFolders = xml.selectNodes( "/kml/Document/Folder[not(Placemark)]" )

    for i in range( emptyFolders.length ) :
        docNode.removeChild( emptyFolders.item( i ) )

    xml.save( kmlFilePath )
   
    return domDoc.xml

# --- MAIN ------------------------------------------------------------

# get the KML file to process
if len( sys.argv ) != 2 :
    print "Usage:" , os.path.split(sys.argv[0])[1] , "<kml-file>"
    sys.exit( 1 )
kmlFilePath = sys.argv[ 1 ]

# process the template file
removeEmptyFolders( kmlFilePath )

2. Don't create the excessive elements to begin with
The "excessive <Folder> elements" were being created because I source this KML Channel Report from a folder named "GEO" which has geographically-related feeds. Some of the feeds in this folder have the geo/latitude and geo/longitude Metadata and some don't. The feed that don't have this Metadata cause the empty <Folder> elements to be generated.

I can easily solve this problem by:
  1. Creating a Folder that contains only feeds that contain geo/latitude and geo/longitude Metadata and sourcing the KML Channel Report from this Folder. Since Awasu allows Channels to me in multiple folders this is easy to accomplish.
  2. Adding some unique text (maybe "geo_metadata") as a "tag" to the description of each Channel that contains geo/latitude and geo/longitude Metadata, create a Channel Filter that only includes Channels containing "geo_metadata" in the Channel description and sourcing the KML Channel Report form this Channel Filter.

So you see this really isn't much of a problem if I had organized my Channels differently, but I thought I'd ask the question about one could test for feed-level values outside {%REPEAT% FeedItems} loop, just in case it was possible and I'd somehow missed it.


Thu Dec 16, 2010 9:14 pm
Profile
Site Admin
User avatar

Joined: Fri Feb 07, 2003 8:48 am
Posts: 2902
Location: Melbourne, Australia
Post Re: Test for feed-level values outside {%REPEAT% FeedItems}
kevotheclone wrote:
Since it's XML there is no embedded JavaScript that can act upon a flag and delete the "excessive elements".

Hey, look what I found :-)

Awasu supports this:
Code:
{%UNDEFINE% paramName}

so you could use this to manage a flag. There's no corresponding {%DEFINE%} command (IIRC, it was tricky to do it "properly") but I think I can sneak in a simple implementation for the next release.

In the meantime, you could use one of the existing parameters that Awasu creates for you (e.g. watermark-image-url) to flag whether or not geo metadata was found i.e. this is initially set, so you iterate through the feed items and if you find geo metadata, undefine it. Then, test for this flag and if it's not set, generate the necessary XML content.


Sat Dec 18, 2010 12:23 am
Profile WWW
User avatar

Joined: Mon Sep 08, 2008 3:16 pm
Posts: 227
Location: Elk Grove, California
Post Re: Test for feed-level values outside {%REPEAT% FeedItems}
{%UNDEFINE% paramName} is pretty cool... you're always planning ahead.

It almost worked, but it looks like we'd need the corresponding {%DEFINE% paramName}.

I followed the steps you outlined, and the first Channel in the Report doesn't have the Metadata and it is not displayed (good!). But the next Channel in the Report has the Metadata, so {%UNDEFINE% watermark-image-url} get undefined properly and the Channel is displayed, but after processing this Channel there no way to re-define watermark-image-url so all subsequent Channels are displayed regardless of whether they contain the Metadata or not (not so good).

I have no control over the order of the Channels in the Channel Report, do I?

Maybe If I could undefine some {%CHANNEL-METADATA%} value that I know appears in every Channel but isn't needed for this report?

Anyway, it's not really an issue given Awasu's flexible folder structure and Channel Filters, but it's something to think about in the future.


Sun Dec 19, 2010 4:59 am
Profile
Site Admin
User avatar

Joined: Fri Feb 07, 2003 8:48 am
Posts: 2902
Location: Melbourne, Australia
Post Re: Test for feed-level values outside {%REPEAT% FeedItems}
kevotheclone wrote:
{%UNDEFINE% paramName} is pretty cool... you're always planning ahead.

You give me far too much credit. IIRC, I was trying to put in a quick hack to work-around some behaviour that someone was complaining about :roll:

I'll add in support for {%DEFINE%} and get a new build out to you.


Sun Dec 19, 2010 7:40 am
Profile WWW
User avatar

Joined: Mon Sep 08, 2008 3:16 pm
Posts: 227
Location: Elk Grove, California
Post Re: Test for feed-level values outside {%REPEAT% FeedItems}
support wrote:
I'll add in support for {%DEFINE%} and get a new build out to you.

Wow! Thanks for the quick turnaround on this! :bow:
How many times have I said this in the past? I'm happily repeating myself.

I didn't even have to use watermark-image-url; I defined my own variable name has-geo-metadata and it worked perfectly. :coolthumb:

I'll add this to Awasu's wiki tomorrow.

Thanks again! For all the cool updates you've made in 2010, thanks! :-D


Tue Dec 21, 2010 5:50 am
Profile
Site Admin
User avatar

Joined: Fri Feb 07, 2003 8:48 am
Posts: 2902
Location: Melbourne, Australia
Post Re: Test for feed-level values outside {%REPEAT% FeedItems}
kevotheclone wrote:
I'll add this to Awasu's wiki tomorrow.

Jeez, I was kinda hoping you would drag your feet on this one, given that no-one else will have the build I sent you with the new feature in it :roll: :)


Tue Dec 21, 2010 6:19 am
Profile WWW
Display posts from previous:  Sort by  
Reply to topic   [ 10 posts ] 

Who is online
Users browsing this forum: No registered users and 1 guest

You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
Jump to:  
cron