Post Reply
User avatar
kevotheclone
Posts: 245
Joined: Mon Sep 08, 2008 7:16 pm
Location: Elk Grove, California

Bug, Feature, or PEBKAC

Post by kevotheclone » Fri Jan 05, 2018 8:36 am

I tried to create a TSV report template, but I'm having a problem.
  • I only want feed items that have one or more categories, that's why I have the {%?ITEM-METADATA% category/id}{%@%}{%ENDIF%} qualification.
  • For each row I only want the following fields: Awasu ID, Feed Item Title, and a single Category
Here's the template:

Code: Select all

{%REPEAT% FeedItems}{%REPEAT% category}{%?ITEM-METADATA% category/id}"{%ITEM-METADATA% awasuId}"	"{%ITEM-METADATA% name! encode=csv chars="}"	"{%@%}"{%ENDIF%}
{%/REPEAT%}{%/REPEAT%}
Here's an excerpt of the output:
"7915" ""John Hodgman and others read the After On audiobook"
"7915" ""John Hodgman and others read the After On audiobook"
"7915" ""John Hodgman and others read the After On audiobook"
"7916" ""This 101-year old woman is having a good time making snowballs"
"7916" ""This 101-year old woman is having a good time making snowballs"
"7916" ""This 101-year old woman is having a good time making snowballs"
"7917" ""Rock your way to crushed garlic"
"7917" ""Rock your way to crushed garlic"
"7918" ""Man with stick calmly convinces charging elephant not to run him over"
"7918" ""Man with stick calmly convinces charging elephant not to run him over"
"7919" ""Two GOP lawmakers: ""It's time for Jeff Sessions to go"""
"7919" ""Two GOP lawmakers: ""It's time for Jeff Sessions to go"""
"7919" ""Two GOP lawmakers: ""It's time for Jeff Sessions to go"""
"7920" ""Wonderful article about dogs"
"7920" ""Wonderful article about dogs"
"7920" ""Wonderful article about dogs"


The problem is that some of the feed item's titles have a quotation mark character in them so I wanted to escape the quotation mark (see Awasu ID 7919 above).
I tried various values of encode= with and without chars=", but I haven't found the right combination to make it work.
Note the double quotation mark before the Feed Item Title, but there isn't a double quotation mark after the Feed Item Title.
And with some combinations the Category doesn't even show up at all, like in the excerpt above.
If I remove the encode= and chars=" attributes the Categories do appear in the output, but the quotation marks aren't getting escaped.

I could fix the file in a post-processing step, but I thought I'd ask you if this is a bug :( , a feature :wink:, or a PEBKAC :facepalm:?
Thanks in advance for your help!!!

User avatar
support
Site Admin
Posts: 3073
Joined: Fri Feb 07, 2003 12:48 pm
Location: Melbourne, Australia
Contact:

Re: Bug, Feature, or PEBKAC

Post by support » Fri Jan 05, 2018 8:58 am

G'day, good to see you're still around and Awasu'ing :)
kevotheclone wrote:
Fri Jan 05, 2018 8:36 am
Here's the template:

Code: Select all

{%REPEAT% FeedItems}{%REPEAT% category}{%?ITEM-METADATA% category/id}"{%ITEM-METADATA% awasuId}"	"{%ITEM-METADATA% name! encode=csv chars="}"	"{%@%}"{%ENDIF%}
{%/REPEAT%}{%/REPEAT%}
The problem is with this bit:

Code: Select all

"{%ITEM-METADATA% name! encode=csv chars="}"
You're trying to wrap the entire thing in double quotes, and specify double-quote as a special character, but you haven't escaped the double quote. So, this is actually being parsed as chars being assigned the value "}" (i.e. a single closing brace), and the {%ITEM-METADATA%} isn't being closed properly (which explains why some values are not showing up at all, because the template control hasn't been defined properly).

The way to write this is chars=\" or chars="\"", although it's actually not necessary, since double-quote will be handled automatically if you specify encode=csv.

BTW, if you set the output file to have a .CSV extension, you won't even need the encode=csv, since Awasu will assume that everything needs to be encoded for CSV. Everything gets wrapped in double-quotes automatically, so all you actually need is this:

Code: Select all

{%ITEM-METADATA% awasuId},{%ITEM-METADATA% name!},{%@%}

User avatar
kevotheclone
Posts: 245
Joined: Mon Sep 08, 2008 7:16 pm
Location: Elk Grove, California

Re: Bug, Feature, or PEBKAC

Post by kevotheclone » Thu Jan 11, 2018 12:41 am

support wrote:G'day, good to see you're still around and Awasu'ing :)
I'll keep Awasu'ing until the day I die. I've been a little quiet in 2017 due to some health problems, but I'm getting better now.

I thought I might have been doing something wrong as you've thoroughly debugged and tested Awasu to the point where I never find a bug.
:oops: I really should have tried escaping the double quote with the backslash, as that's a common escaping in many programming languages.
support wrote:BTW, if you set the output file to have a .CSV extension, you won't even need the encode=csv...
Wow that's nice to know, it makes this even easier.

Thanks again! Hopefully I'll add a new extension to Awasu's Wiki in 2018.

User avatar
support
Site Admin
Posts: 3073
Joined: Fri Feb 07, 2003 12:48 pm
Location: Melbourne, Australia
Contact:

Re: Bug, Feature, or PEBKAC

Post by support » Thu Jan 11, 2018 6:54 am

kevotheclone wrote:
Thu Jan 11, 2018 12:41 am
I've been a little quiet in 2017 due to some health problems, but I'm getting better now.
Ah, sorry to hear that. I thought you were enjoying all your new-found free time, out on the golf course or something like that... :-)
kevotheclone wrote:
Thu Jan 11, 2018 12:41 am
I thought I might have been doing something wrong as you've thoroughly debugged and tested Awasu to the point where I never find a bug.
*cough* You're obviously not trying hard enough :| Push harder!

Most of 3.1.1 (coming out Real Soon Now) is because of awasu.user reporting bugs or performance problems or asking for features and TBH, because it was mostly related to the search engine (which I don't use much), I had been a bit slack :oops: and neglected that part of Awasu. But he whipped me into action, and Awasu is that much better because of it.
kevotheclone wrote:
Thu Jan 11, 2018 12:41 am
Thanks again! Hopefully I'll add a new extension to Awasu's Wiki in 2018.
Cool, looking forward to it ::-):

Post Reply

Return to “Awasu - Bug Reports”