From e835a5a20b14fb49e2b6bda7f970f77c5acb1ba5 Mon Sep 17 00:00:00 2001 From: Kip Gebhardt Date: Mon, 2 Mar 2015 16:22:45 -0800 Subject: [PATCH] RSS-27: Adding the remaining node-rss elements to the braider feed constructor. Adding support for site_url, feed_url, fullname, shortname. Updating kqed.js plugin --- lib/RssBraider.js | 30 +++++++++------- lib/plugins/content_encoded.js | 1 + lib/plugins/kqed.js | 36 ++++++++++++++++--- test/expected_output/dateAscOutput.xml | 12 ++++++- test/expected_output/dateDescOutput.xml | 12 ++++++- test/expected_output/fileFeedOutput.xml | 2 +- .../expected_output/fileFeedOutputPlugins.xml | 4 ++- test/feeds/date_sort.js | 1 + test/feeds/sample_feed_duplicates.js | 2 ++ test/feeds/sample_feed_plugins.js | 1 + test/index.js | 1 + 11 files changed, 82 insertions(+), 20 deletions(-) diff --git a/lib/RssBraider.js b/lib/RssBraider.js index e0b199a..971b380 100644 --- a/lib/RssBraider.js +++ b/lib/RssBraider.js @@ -69,7 +69,7 @@ RssBraider.prototype.processFeed = function(feed_name, format, callback) async.each(feed.sources, function(source, callback) { var count = source.count || feed.default_count || 10, - url = source.url || null, + url = source.feed_url || null, file_path = source.file_path || null, source_articles = []; @@ -110,10 +110,10 @@ RssBraider.prototype.processFeed = function(feed_name, format, callback) item; while ( item = stream.read() ) { - if (source.url) { - item.source_url = source.url; + if (source.feed_url) { + item.source_url = source.feed_url; } - var article = self.processItem(item); + var article = self.processItem(item, source); if (article) { source_articles.push(article); } @@ -141,10 +141,14 @@ RssBraider.prototype.processFeed = function(feed_name, format, callback) // Create new feed with these articles var options = { title : feed.meta.title, - site_url : "http://www.kqed.org", description : feed.meta.description, generator : feed.meta.generator || 'rss-braider', - feed_url : feed.meta.url, + site_url : feed.meta.site_url || null, + feed_url : feed.meta.feed_url || null, + image_url : feed.meta.image_url || null, + webMaster : feed.meta.webMaster || null, + copyright : feed.meta.copyright || null, + categories : feed.meta.categories || null, custom_namespaces : feed.custom_namespaces || [], no_cdata_fields : feed.no_cdata_fields }; @@ -172,7 +176,7 @@ RssBraider.prototype.processFeed = function(feed_name, format, callback) }; // Accepts a feed-parser item and builds a node-rss itemOptions object -RssBraider.prototype.processItem = function (item) { +RssBraider.prototype.processItem = function (item, source) { var self = this; if (!item) { @@ -195,20 +199,22 @@ RssBraider.prototype.processItem = function (item) { // Run the plugins specified by the "plugins" section of the // feed config file to build out any custom elements or // do transforms - self.runPlugins(item, itemOptions); + self.runPlugins(item, itemOptions, source); + // logger.info("returning for item.guid:" + item.guid); return itemOptions; }; -RssBraider.prototype.runPlugins = function (item, itemOptions) { +RssBraider.prototype.runPlugins = function (item, itemOptions, source) { var self = this, - feed_plugins = self.feed.plugins || []; + feed = self.feed, + feed_plugins = feed.plugins || []; // Process the item through the desired feed plugins feed_plugins.forEach(function(plugin_name){ if (self.plugins[plugin_name]) { - // logger.info("DEBUG runPlugins running " + plugin_name); - self.plugins[plugin_name](item, itemOptions); + // logger.info("DEBUG runPlugins running " + plugin_name + " for item " + item.guid + " in feed: " + feed.meta.title); + self.plugins[plugin_name](item, itemOptions, source); } else { logger.error("A plugin named '" + plugin_name + "' hasn't been registered"); } diff --git a/lib/plugins/content_encoded.js b/lib/plugins/content_encoded.js index 9e933c3..663450b 100644 --- a/lib/plugins/content_encoded.js +++ b/lib/plugins/content_encoded.js @@ -17,4 +17,5 @@ module.exports = function (item, itemOptions) { } ); } + return; }; \ No newline at end of file diff --git a/lib/plugins/kqed.js b/lib/plugins/kqed.js index d25e6c8..39847ed 100644 --- a/lib/plugins/kqed.js +++ b/lib/plugins/kqed.js @@ -1,11 +1,39 @@ // define kqed source -module.exports = function (item, itemOptions) { - if (!item || !itemOptions) { +module.exports = function (item, itemOptions, source) { + if (!item || !itemOptions || !source) { return; } - if (item.source_url) { + // Look for kqed namespace elements in source and add as custom elements for item + // Ex: + // The California Report + // the-california-report + // + // http://ww2.kqed.org/news/programs/the-california-report + // + var element; + if (source.site_url){ + element = { + 'kqed:site_url': source.site_url + }; + itemOptions.custom_elements.push(element); + } + + if (source.fullname){ + element = { + 'kqed:fullname': source.fullname + }; + itemOptions.custom_elements.push(element); + } + // add shortname using the source 'name' + element = { + 'kqed:shortname': source.name + }; + itemOptions.custom_elements.push(element); + + // Add the source's feed url to the kqed namespace of the item/article + if (item.feed_url) { itemOptions.custom_elements.push( - { 'kqed:source': item.source_url } + { 'kqed:feed_url': item.feed_url } ); } }; \ No newline at end of file diff --git a/test/expected_output/dateAscOutput.xml b/test/expected_output/dateAscOutput.xml index ba7c6de..6304e38 100644 --- a/test/expected_output/dateAscOutput.xml +++ b/test/expected_output/dateAscOutput.xml @@ -3,7 +3,7 @@ <![CDATA[Test File Feed]]> This feed comes from a file - http://www.kqed.org + http://github.com/dylang/node-rss rss-braider Wed, 31 Dec 2014 00:00:01 GMT @@ -14,6 +14,8 @@ http://ww2.kqed.org/arts/2014/12/20/rent-hike-for-dance-mission-theater-has-artists-worried-about-uncertain-future/ Sat, 20 Dec 2014 09:00:22 GMT + A Sample Feed + sample_feed Stepping out of BART at 24th and Mission at most hours of the day, one is likely to hear the pulse of African drums, hip-hop or salsa emanating from the second-floor studios of Dance Brigade’s Dance Mission Theater. But that music may not continue forever.

The performance space and dance school …read more

Source:: Arts News

@@ -30,6 +32,8 @@ http://ww2.kqed.org/arts/?p=10220517 Sat, 20 Dec 2014 14:00:47 GMT + A Sample Feed + sample_feed Until February 5, 2015, you can visit the main branch of the San Francisco Public Library and be momentarily transported through space and time to the early days of the Exploratorium via the life and work of Bob Miller, who died in 2007.

The transportation isn’t entirely complete, especially when unavoidable elements of the library’s physical space interrupt the installation of vitrines, wall text and objects. But reading first-hand accounts by Miller’s colleagues of his various contributions to both the Exploratorium and scientific discovery, I wished I’d wandered the museum with him at any point in his twenty year tenure. Documentation and ephemera will never be as entertaining as the man himself, but Light Walk: Bob Miller and the Exploratorium presents one man’s creativity, playfulness and lasting impact on an institution, leaving the viewer itching for the simple tools of his trade: sunlight, paper and an irrepressible curiosity.

Light Walk is installed on the library’s fourth floor, rubbing elbows with the art, music and recreation collections. Four large cases present short anecdotes about Miller and related materials from the Exploratorium archives: photographs, magazine clippings, patent documents and museum publications. The bits and pieces coalesce into a picture of Miller — much like his Light Walk, an exploration of sunlight, shadow, refraction and perception builds on basic demonstrations to build a larger understanding of the natural world.

@@ -56,6 +60,8 @@ http://ww2.kqed.org/arts/?p=10231062 Sun, 21 Dec 2014 14:00:08 GMT + A Sample Feed + sample_feed Tonight is midwinter, Yule, the solstice – the longest night. During winter’s dark depths, San Franciscans with an urge to seek the light will find a wealth of illuminated art pieces blinking and blazing around town. Some, like Caruso’s Dream, are permanent installations. Others, like Blumen Lumen and a selection of illuminated works at the Exploratorium through Jan. 4, will be gone in a flash. Many, such as the Flaming Lotus Girls’ SOMA, on Pier 14, come out of the Burning Man movement. All feel appropriate to this season, when we celebrate the sun’s return with fire.

If you’re interested in visiting the city’s illuminated installations, the SF Travel Association has compiled a map and a list of tours and other events. (KQED critic Christian Frock rates the 16 works listed on the map as ranging “from meh to spectacular” — read her commentary. ) A free light art bike tour this Saturday will give cyclists a chance to shine. Meanwhile, enjoy Peter Ruocco’s video exploration of these dazzling works.

]]>
@@ -71,6 +77,8 @@ http://ww2.kqed.org/arts/?p=10230592 Mon, 22 Dec 2014 14:00:32 GMT + A Sample Feed + sample_feed In early November, the Yerba Buena Center for the Arts (YBCA) hosted Clas/sick Hip-Hop: 1993 Edition, a night of live music featuring over 20 MCs performing new takes on hop-hop hits from 1993, with live instrumentation arranged by two notable Bay Area composers—JooWan Kim and Kev Choice. The year’s importance was twofold: not only did YBCA first open its doors in 1993, but hip-hop itself saw serious successes, both artistically and commercially, that led to the form becoming a part of the mainstream.

Songs that were performed include Snoop Dogg’s “Gin And Juice,” Digable Planets’ “Rebirth of Slick (Cool Like Dat),” and many others. Read a statement from the curator of the event, Marc Bamuthi Joseph, here. (Also, we asked Joseph to pick his Top 5 hip-hop songs from 1993, which you can read here.)

Enjoyed that? Watch this performance, by Ensemble Mik Nawooj, of the Wu-Tang Clan’s “C.R.E.A.M.” from that same night.

@@ -88,6 +96,8 @@ http://ww2.kqed.org/arts/?p=10189953 Tue, 23 Dec 2014 14:00:41 GMT + A Sample Feed + sample_feed Hands up, umbrellas out, hoodies on, fists raised — the icons of protest have long played a significant role in movements of social change and revolution. From flower power to Rosie the Riveter to the rainbow flag, icons have momentous social potency and live on as cultural currency that is exchanged, needed and protected sometimes long past the initial movements of their birth.

Icons are sought after and are coming to be needed more and more. Perhaps it is easier to understand an image than it is to know the world, let alone how to change it.

Uploading an icon to a profile picture or posting a response or article bleeds into thousands who are doing the same and suddenly an entire social media feed is parroting the same visual calls. Today, protest icons are disseminated rapidly and with such reach that, while the news is mired in arguing over factual evidence of whether or not Mike Brown’s hands were actually raised or not, the image has already hit the streets. There thousands of protesters begin to raise their hands and take photos with their hoodies pulled tight or make videos of themselves dumping buckets of ice over their heads.

diff --git a/test/expected_output/dateDescOutput.xml b/test/expected_output/dateDescOutput.xml index 80e0e7f..22fb1bc 100644 --- a/test/expected_output/dateDescOutput.xml +++ b/test/expected_output/dateDescOutput.xml @@ -3,7 +3,7 @@ <![CDATA[Test File Feed]]> This feed comes from a file - http://www.kqed.org + http://github.com/dylang/node-rss rss-braider Wed, 31 Dec 2014 00:00:01 GMT @@ -13,6 +13,8 @@ http://ww2.kqed.org/arts/?p=10222283 Fri, 26 Dec 2014 14:00:18 GMT + A Sample Feed + sample_feed The year just ending wasn’t a terrible one for movies, but it will be remembered as depressingly uninspired. Earnest craftsmanship is the mantra of the moment, particularly in the risk-phobic American cinema. Consider the siege we’ve endured (especially since Labor Day) of serious, solid movies — including Gone Girl, Foxcatcher, Exodus: Gods and Kings, American Sniper, The Imitation Game, Unbroken, A Most Violent Year and Still Alice — that demanded our attention for long hours and repaid us with the briefest flashes of transcendent joy, insight or pathos.

It was no easy task summoning memorable moments from the year’s morass, yet here in chronological order are the sequences that, for me, best captured the vitality and intelligent power that movies are capable of expressing.

ida2

@@ -59,6 +61,8 @@ http://ww2.kqed.org/arts/?p=10238611 Fri, 26 Dec 2014 02:00:10 GMT + A Sample Feed + sample_feed

Cy Musiker and David Wiegand share their picks for great events around the Bay Area this week.

@@ -99,6 +103,8 @@ http://ww2.kqed.org/arts/?p=10238600 Wed, 24 Dec 2014 21:05:45 GMT + A Sample Feed + sample_feed Above: Ensemble Mik Nawooj (EMN), led by music director, composer/pianist JooWan Kim, reinterprets Wu-Tang Clan’s “C.R.E.A.M.” at YBCA’s Clas/Sick Hip Hop: 1993 Edition.

joowanEnsemble Mik Nawooj (EMN) is the brainchild of composer/pianist JooWan Kim, who introduces western-European classical techniques into hip-hop, rock, and pop. The group’s lineup includes traditional Pierrot ensemble instrumentation (flute, clarinet, violin, cello and piano) with a lyric soprano, deep funk drums, a heavy contrabass and two featured MCs. Kim is a classically trained composer who holds degrees from Berklee College of Music and San Francisco Conservatory of Music.

“Nobody has ever attempted anything like this on such a large scale, or with such sophistication.” – NPR

@@ -117,6 +123,8 @@ http://ww2.kqed.org/arts/?p=10238610 Wed, 24 Dec 2014 19:00:34 GMT + A Sample Feed + sample_feed Above: Kev Choice Ensemble reinterprets Saafir’s “Light Sleeper” at YBCA’s Clas/Sick Hip Hop: 1993 Edition.

Oakland-based artist Kev Choice is a pianist, MC, producer, bandleader, sideman, music historian and urban griot dedicated to cultural expression. Through his band Kev Choice Ensemble, he produces and performs his own material, including original jazz and classical compositions as well as classical, jazz, and funk-inspired hip-hop.

kev

@@ -136,6 +144,8 @@ http://ww2.kqed.org/arts/?p=10218934 Wed, 24 Dec 2014 14:00:19 GMT + A Sample Feed + sample_feed The intent wasn’t always to create a million paintings. Speaking of his early art-making days with his brothers-in-arms back in high school, where the seeds of the idea were planted, artist Jason McHenry says, “We actually just used them like currency, kind of. We would make little mini paintings. That’s how it started… just amassing a bunch of these things, you know? We would all just push each other to make a new version of our own currency — like one dollar bills and five dollar bills.”

McHenry and his best friend Chris Dyer are the only two that stuck to it over the years. Now the project has a name, One Thousand Thousand, and a mission to produce one million paintings. Although the impetus was simply to make as much art as possible surrounded by his friends, it eventually took McHenry down an often solitary path. Today he is reaching out to other artists to participate in the project to assure the goal is reached in his lifetime.

One Thousand Thousand is Christopher Dyer and Jason McHenry,” McHenry is quick to point out. “I honestly do more of the work, produce more pieces; he’s a senior executive at a company in Denver. We’re like partners in crime artistically. All the big projects that we’ve done, we’ve done together. So we push each other that way.”

diff --git a/test/expected_output/fileFeedOutput.xml b/test/expected_output/fileFeedOutput.xml index 72a2dea..316fe66 100644 --- a/test/expected_output/fileFeedOutput.xml +++ b/test/expected_output/fileFeedOutput.xml @@ -3,7 +3,7 @@ <![CDATA[Test File Feed]]> This feed comes from a file - http://www.kqed.org + http://github.com/dylang/node-rss rss-braider Wed, 31 Dec 2014 00:00:01 GMT diff --git a/test/expected_output/fileFeedOutputPlugins.xml b/test/expected_output/fileFeedOutputPlugins.xml index 0a55037..f9c4f54 100644 --- a/test/expected_output/fileFeedOutputPlugins.xml +++ b/test/expected_output/fileFeedOutputPlugins.xml @@ -3,7 +3,7 @@ <![CDATA[Test File Feed]]> This feed comes from a file - http://www.kqed.org + http://github.com/dylang/node-rss rss-braider Wed, 31 Dec 2014 00:00:01 GMT @@ -13,6 +13,8 @@ http://ww2.kqed.org/arts/?p=10222283 Fri, 26 Dec 2014 14:00:18 GMT + A Sample Feed + sample_feed The year just ending wasn’t a terrible one for movies, but it will be remembered as depressingly uninspired. Earnest craftsmanship is the mantra of the moment, particularly in the risk-phobic American cinema. Consider the siege we’ve endured (especially since Labor Day) of serious, solid movies — including Gone Girl, Foxcatcher, Exodus: Gods and Kings, American Sniper, The Imitation Game, Unbroken, A Most Violent Year and Still Alice — that demanded our attention for long hours and repaid us with the briefest flashes of transcendent joy, insight or pathos.

It was no easy task summoning memorable moments from the year’s morass, yet here in chronological order are the sequences that, for me, best captured the vitality and intelligent power that movies are capable of expressing.

ida2

diff --git a/test/feeds/date_sort.js b/test/feeds/date_sort.js index 7e64a4a..ad64076 100644 --- a/test/feeds/date_sort.js +++ b/test/feeds/date_sort.js @@ -20,6 +20,7 @@ var feed = { "name" : "sample_feed", "count" : 5, "file_path" : __dirname + "/../input_files/sample_feed.xml", + "fullname" : "A Sample Feed" }, ] diff --git a/test/feeds/sample_feed_duplicates.js b/test/feeds/sample_feed_duplicates.js index fe98329..79124ed 100644 --- a/test/feeds/sample_feed_duplicates.js +++ b/test/feeds/sample_feed_duplicates.js @@ -20,6 +20,8 @@ var feed = { "name" : "sample_feed", "count" : 1, "file_path" : __dirname + "/../input_files/sample_feed_duplicates.xml", + "fullname" : "A Sample Feed" + }, ] diff --git a/test/feeds/sample_feed_plugins.js b/test/feeds/sample_feed_plugins.js index 018dbec..25f8a7f 100644 --- a/test/feeds/sample_feed_plugins.js +++ b/test/feeds/sample_feed_plugins.js @@ -20,6 +20,7 @@ var feed = { "name" : "sample_feed", "count" : 1, "file_path" : __dirname + "/../input_files/sample_feed.xml", + "fullname" : "A Sample Feed" }, ] }; diff --git a/test/index.js b/test/index.js index a5b9e9e..b9d967b 100644 --- a/test/index.js +++ b/test/index.js @@ -62,6 +62,7 @@ test('deduplicate feed from file', function(t) { if (err) { return t.fail(err); } + // console.log(data); t.equal(data, expectedOutput.fileFeedOutputPlugins); }); });