Get a string out of an array\object in yahoo pipes? - yahoo-pipes

I have a pipe which is attempting to extract a youtube id from a youtube channel feed.
I have:
Fetch Feed -> Sub Element (item.link) -> Truncate (After 1) -> Regex (blah) -> Output
My problem is the output is:
0
content ABGmhMBBGgw
I can't seem to put this output into a string builder because it's an object (maybe array?).
So how can I extract the raw string out of this object array thing I have now.

As an option, you can use the pipe module called "create RSS" and make it's tittle from regexp result.
It will contain desired string as title instead of given 0, but will be an array anyway.

A demo showing how to extract latest video from a Youtube channel and embed into a webpage, all done with javascript and a Yahoo Pipe can be found at... http://lovelogic.net/z_tuts/ytgrab3.html
Just right click to view the page source and learn how the JSON from the yahoo pipe is decoded then swapped into the HTML, details of the pipe itself can be found here http://pipes.yahoo.com/pipes/pipe.info?_id=19431b877cc39a2d5fe8efa00bd86009

Related

Liquid - parse YAML front matter in string

I'm running a Jekyll site that uses JSON as data in my _data folder. I'm looping through the file like normal doing things like {% for item in site.data.resources.items %} just fine. However, I'd like to parse YAML front matter that is within a string.
Example:
\n---\nblog: http://google.com\nbackground-img: http://www.ew.com/sites/default/files/i/2013/07/23/Dumb-and-Dumber.jpg\nbuttonText: Download\n---\n
How can I have Liquid parse this within my Jekyll site so I can use it like so:
<img src="{{background-img}}>Image
or something similar?
EDIT: To clarify, that string is in front matter format in a text file that I'm retrieving through an ajax call. So that string is the response I get back and the format won't be changing. My hope was that Liquid could somehow parse this string and look for a front matter type format. If not, I will revert back my JavaScript methods.
This is impossible.
Liquid/YML is being parsed while generating the site and your JSON string comes available long after the site has been generated: It only exists after the moment the JSON request for the string has been succesful.
However, you can use javascript, as you already mentioned. Simply split the string on \n for your key-value pairs and split on : for your key and value. Then use jQuery (or plain javascript) to write the results to the DOM.
Good luck!

Get Pinterest RSS feed for board with special characters

Normally, to get the RSS feed for a Pinterest board, you simply add ".rss" to the end of the URL.
For example, for the board at http://www.pinterest.com/philchairez/mega-man-x/, you can get the RSS feed from http://www.pinterest.com/philchairez/mega-man-x.rss.
If a board has a special character in its name, usually, it seems like Pinterest has simply removed the special characters from the assigned URL.
For example, this board is named "film + music + books + games" and its URL is http://www.pinterest.com/claramechelle/film-music-books-games/ (notice that the '+' characters are excluded).
Another example: "Kids diy games + musical instruments", http://www.pinterest.com/sammijjohno/kids-diy-games-musical-instruments/
Getting the RSS feeds for these boards works as expected:
http://www.pinterest.com/claramechelle/film-music-books-games.rss
http://www.pinterest.com/sammijjohno/kids-diy-games-musical-instruments.rss
However, URLs for some boards sometimes include the URL encoding of a special character. For example, this board is named "Dungeons + Dragons":
http://www.pinterest.com/lizardskingirl/dungeons-%2B-dragons/
And this board is named "Game Art + UI/HUD":
http://www.pinterest.com/portableneko/game-art-%2B-uihud/
Adding ".rss" to these URLs does not work:
http://www.pinterest.com/lizardskingirl/dungeons-%2B-dragons.rss
http://www.pinterest.com/portableneko/game-art-%2B-uihud.rss
You'll just get redirected to the user's board list. If you try to simply remove the special character like the other URLs, you'll get a 404.
Does anyone know how to get the RSS feed for boards like this?
Try this
http://pinterest.com/[username]/feed.rss
For example, my username is "sharp", so my RSS feed can be found at:
http://pinterest.com/sharp/feed.rss
Source:
http://www.quora.com/Does-Pinterest-have-plans-to-allow-for-RSS-feeds-for-a-users-specific-pinboards
You can get the rss feed if you replace the character encoding with the actual '+', and then tack '.rss' to the end:
http://www.pinterest.com/portableneko/game-art-%2B-uihud becomes:
http://www.pinterest.com/portableneko/game-art-+-uihud.rss
Renaming a board doesn't change its internal name, so if you have renamed a board see if you can remember its original name and generate the .rss URL from that.

Yahoo pipes: how can I add an additional nodes/elements to RSS/feed items

I am merging two feeds using Yahoo pipes and using the output feed on a website. However, as would like to identify the "feed source" for each item in the output feed. Is it possible to manipulate the original feeds so I can add another node/element to the feed items?
Thanks
One way to do that is using the Regex operator. Let's say you want to add a new field called source. You could use Regex with parameters:
In: item.source
replace: .*
with: (the text you want)
See it in action here:
http://pipes.yahoo.com/janos/7a3b9993cfc143d414fe7b637b1bd95a
That is, I have two feeds, I added a source attribute in the first with value "Question 1" and in the second with value "Question 2".
As an added bonus interesting undocumented Yahoo Pipes hack, I used one more Regex after the Union to make the source appear in the title.
However, this only adds the attribute to the node in the pipe debugger. You can use it for further processing, like I added it here to the title, it won't create a <source> tag in the output. That's because the RSS output of Yahoo Pipes removes all other fields that are not in the RSS standard. You can still see it in the JSON output though.

Make an arrays of links contained in one big string

I have a big string ( a html code from web page).
Now the problem is how to parse the links to images.
I want to make an array of all the links to images in that web page.
I know how to do this i java but I do not know how to do the parse strings and do a string manipulations in shell. I know there are many tricks and I guess this can be easy done.
in the end I want to get something like this
#!/bin/bash
read BIG_STRING <<< $(curl some_web_page_with_links_to_images.com)
#parse the big string and fill the LINKS variable
# fill this with the links to image somewhow (.jpg and .png only)
#after the parsing the LINKS should look like this
LINKS=("www.asd.com/asd1.jpg" "www.asd.com/asd.jpg" "www.asd.com/asd2123.jpg")
#I need the parsing and to fill the LINKS variable with the links from the web page
# get length of an array
tLen=${#LINKS[#]}
for (( i=0; i<${tLen}; i++ ));
do
echo ${LINKS[$i]}
done
Thanks, for the responses you saved me days of frustrations
Why not start with the right tool? Parsing HTML is hard, especially with sed. If you have the mojo tool from the Mojolicious project you can do this:
mojo get http://example.com a attr href
And then just check whether each line ends with jpg, png, or whatever.
It's hard to offer more than approximations. Let's assume all interesting links are href="" attributes, and there's at most one href attribute per line (And the links are also one line only, actually I'm not sure if newlines are allowed inside URLs.
Let's assume your sourcefile is called test.html.
The following should print all links under these assumptions:
sed -n 's/.*\<href="\([^"]*\)".*/\1/p' test.html
To understand how this works, you should know what regular expressions are and have read up a tutorial on sed (particularly how the s ubstitute command works)

How can I do a Get on an InputStream?

One annoying thing of encoded packages is that they have to be in a separate file. If we want to distribute a simple self contained app (encoded), we need to supply two files: the app "interface", and the app package.
If I place all the content of the encoded file inside a string, and transform that string into an InputStream, I'm halfway to view that package content as a file.
But Get, that to my knowledge is the only operation (also used by Needs) that has the decoding function, doesn't work on Streams. It only works on real files.
Can someone figure out a way to Get a Stream?
Waiting for Mathematica to arrive on my iPhone so couldn't test anything, but why don't you write the string to a temporary file and Get that?
Update
Here's how to do it:
encoded = ToFileName[$TemporaryDirectory, "encoded"];
Export[encoded, "code string", "Text"]; (*export encrypted code to temp file *)
It's important to copy the contents of the code string from the ASCII file containing the encoded code using an ASCII editor and paste it between existing empty quotes (""). Mathematica will then do automatic escaping of backslashes and quotes that may be in the code. This file has been made earlier using Encode. Can't do it here in the sample code as SO's Markdown messes with the string.
Get[encoded] (* get encrypted code and decode *)
DeleteFile[encoded] (* Remove temp file *)
Final Answer
Get doesn't appear to be necessary for decoding. ImportString does work as well:
ImportString["code string", "NB"]
As above, paste your encoded tekst from an ASCII editor straight between the "" and let MMA do the escaping.
I don't know of a way to Get a Stream, but you could store the encoded data in your single package, write it out to a temp file, then read the temp file back in with Get.
Just to keep things up to date:
Get works with streams since V9.0.

Resources