From ad29acd7b7194f2042c563cd0446544decbf00fb Mon Sep 17 00:00:00 2001 From: Janet Date: Mon, 23 Jan 2017 19:47:06 -0500 Subject: [PATCH] feat: fortune parser (#84) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * feat: fortune parser For some reason, the dek doesn’t appear in the local version of the article I selected. I tried parsing the meta tag containing og:description but it’s not working, and the description is slightly longer than the dek in the original article. I’m not sure why, but for the lead image, the meta tag for og:image is not parsing the image url. :( * feat: fortune redesigned, so re-did extractor * fix: added timezone --- fixtures/fortune.com/1485216994169.html | 1 + src/extractors/custom/fortune.com/index.js | 48 ++++++++++ .../custom/fortune.com/index.test.js | 87 +++++++++++++++++++ src/extractors/custom/index.js | 1 + 4 files changed, 137 insertions(+) create mode 100644 fixtures/fortune.com/1485216994169.html create mode 100644 src/extractors/custom/fortune.com/index.js create mode 100644 src/extractors/custom/fortune.com/index.test.js diff --git a/fixtures/fortune.com/1485216994169.html b/fixtures/fortune.com/1485216994169.html new file mode 100644 index 000000000..f66cce227 --- /dev/null +++ b/fixtures/fortune.com/1485216994169.html @@ -0,0 +1 @@ +Amazon Alexa: 6 Can’t-Miss Gadgets Powered by the Digital Assistant | Fortune.com
Amazon Echo speaker Jason Cipriani

Here Are 6 Can’t-Miss Gadgets Powered by Amazon’s Alexa Assistant

Updated: Dec 15, 2016 2:57 PM UTC

The Amazon Echo Dot, the retailer’s puck-shaped smart speaker, is is killing it this year. Part of its success comes from its Alexa artificial intelligence software, which makes Amazon’s Echo lineup able to respond to your questions, play music, set timers and do lots of other useful stuff.

But if you haven’t picked up an Echo device yet, that doesn’t mean you can’t give Alexa a go. Lots of third-party gadget makers are adding Alexa to their gear. From walkie talkies to watches, you can take Alexa with you wherever you go — even if it’s just into another room.

Car Talk

The auto industry may be abuzz with self-driving cars, but having cars that can speak with Amazon Alexa will really get people talking. Currently in final testing, three Ford @ford models featuring the company’s SYNC platform will be able to speak with Alexa by the end of the year. The Ford Focus Electric, Fusion Energi, and C-Max Energi will be able to do everything from play your favorite music or crank up your thermostat with the push of a steering wheel button — and a voice command. BMW and Genesis (Hyundai’s luxury brand) vehicles are also destined to get the Amazon-linked technology, as the companies announced at CES 2016.

Stereo Speaker of the House

Reviews are mixed on the Echo speakers’ sound quality. One alternative for better audio could be to pair an Echo Dot with a better-quality Bluetooth boom box. But for some audiophiles, even that might not be good enough. Instead, for $160, Jam Voice provides stereo sound as well as access to Alexa. The $80 third-party Bluetooth speaker provides push-button access to Alexa, and can pair with another Jam (which is why the full setup costs $160) creating a pair of satellite speakers, perfect for filling a room with sound or spreading music across a floor. And with your hours of battery life, it also doubles as a good portable sound machine.

Watch What You Say

Apple Watch (aapl) users may be big Siri fans, but if you want to get Alexa on your wrist, you’ll have to go with a less obvious choice. The Martian mVoice line of smartwatches have analog looks but digital smarts, connecting wearers to Amazon’s (amzn) digital assistant technology. Starting at $295, the watches come with access to Alexa’s 5,000 skills right out of the box.

Paging Alexa

Whether they’re down the hall or across the world, people want to communicate with each other, and that’s the thought behind the $199 Nucleus Intercom. Designed with a simple user interface in mind, the one-pound, HD webcam-clad system has an eight-inch screen, stereo speakers, and runs on both Wi-Fi and Ethernet. It can be wall-mounted or perched on a table, has big buttons that make it great for older (or younger) users and a physical shutter to cover the camera when you need privacy. And with Alexa integration, users can also talk to Amazon’s voice assistant, letting them do everything from adding milk to their grocery list to turning on the lights.

Get Data Sheet, Fortune’s technology newsletter

Walking and Talking

Smartphones are incredibly convenient — until you need to pick one up and tap at a bunch of tiny icons just to send a quick communique to a friend or co-worker. Orion Labs Onyx, a $129 walkie talkie-like communicator (two-packs cost $199) can pair with your iOS or Android device to do that at the push of a broach (or bauble, however you want to describe it). The little circular wearable can latch onto your clothing and put communications within easy reach — including to Amazon Alexa. Tapping on it will let Onyx perform any Alexa-linked skill that Echos can do, minus playing music (because it wasn’t designed to be a speaker). The Amazon integration will be enabled in the first quarter of 2017, but the device itself is available now.

For more, read: This Las Vegas Resort Is Installing Amazon Alexa in Every Hotel Room

Get the Message

If the kitchen is the hub of the house, and Alexa is the hub of your smart home, it only makes sense to put an Amazon-linked device in the kitchen. Invoxia’s Triby, a $199 portable speaker and message center, is an excellent way to integrate Alexa into your home without adding extra clutter to your countertop. Backed with magnets, the speaker affixes firmly to your refrigerator. The device’s e-ink display lets people send notes to the device via the Triby app, and when the message arrives, a little flag pops out of the side to alert users. And you can call out to Alexa without having to push a button — perfect for when you’re up to your knuckles in a recipe.

This article originally appeared on Time.com.

\ No newline at end of file diff --git a/src/extractors/custom/fortune.com/index.js b/src/extractors/custom/fortune.com/index.js new file mode 100644 index 000000000..4678cb19f --- /dev/null +++ b/src/extractors/custom/fortune.com/index.js @@ -0,0 +1,48 @@ +export const FortuneComExtractor = { + domain: 'fortune.com', + + title: { + selectors: [ + 'h1', + ], + }, + + author: { + selectors: [ + ['meta[name="author"]', 'value'], + ], + }, + + date_published: { + selectors: [ + '.MblGHNMJ', + ], + + timezone: 'UTC', + }, + + lead_image_url: { + selectors: [ + ['meta[name="og:image"]', 'value'], + ], + }, + + content: { + selectors: [ + ['picture', 'article.row'], + 'article.row', + ], + + // Is there anything in the content you selected that needs transformed + // before it's consumable content? E.g., unusual lazy loaded images + transforms: { + }, + + // Is there anything that is in the result that shouldn't be? + // The clean selectors will remove anything that matches from + // the result + clean: [ + + ], + }, +}; diff --git a/src/extractors/custom/fortune.com/index.test.js b/src/extractors/custom/fortune.com/index.test.js new file mode 100644 index 000000000..0630e7f1d --- /dev/null +++ b/src/extractors/custom/fortune.com/index.test.js @@ -0,0 +1,87 @@ +import assert from 'assert'; +import fs from 'fs'; +import URL from 'url'; +import cheerio from 'cheerio'; + +import Mercury from 'mercury'; +import getExtractor from 'extractors/get-extractor'; +import { excerptContent } from 'utils/text'; + +describe('FortuneComExtractor', () => { + describe('initial test case', () => { + let result; + let url; + beforeAll(() => { + url = + 'http://fortune.com/2016/12/15/amazon-alexa-gadgets/'; + const html = + fs.readFileSync('./fixtures/fortune.com/1485216994169.html'); + result = + Mercury.parse(url, html, { fallback: false }); + }); + + it('is selected properly', () => { + // This test should be passing by default. + // It sanity checks that the correct parser + // is being selected for URLs from this domain + const extractor = getExtractor(url); + assert.equal(extractor.domain, URL.parse(url).hostname); + }); + + it('returns the title', async () => { + // To pass this test, fill out the title selector + // in ./src/extractors/custom/fortune.com/index.js. + const { title } = await result; + + // Update these values with the expected values from + // the article. + assert.equal(title, 'Here Are 6 Can’t-Miss Gadgets Powered by Amazon’s Alexa Assistant'); + }); + + it('returns the author', async () => { + // To pass this test, fill out the author selector + // in ./src/extractors/custom/fortune.com/index.js. + const { author } = await result; + + // Update these values with the expected values from + // the article. + assert.equal(author, 'John Patrick Pullen, TIME'); + }); + + it('returns the date_published', async () => { + // To pass this test, fill out the date_published selector + // in ./src/extractors/custom/fortune.com/index.js. + const { date_published } = await result; + + // Update these values with the expected values from + // the article. + assert.equal(date_published, '2016-12-15T14:57:00.000Z'); + }); + + it('returns the lead_image_url', async () => { + // To pass this test, fill out the lead_image_url selector + // in ./src/extractors/custom/fortune.com/index.js. + const { lead_image_url } = await result; + + // Update these values with the expected values from + // the article. + assert.equal(lead_image_url, 'https://fortunedotcom.files.wordpress.com/2016/05/amazon-echo-2.jpg?w=720'); + }); + + it('returns the content', async () => { + // To pass this test, fill out the content selector + // in ./src/extractors/custom/fortune.com/index.js. + // You may also want to make use of the clean and transform + // options. + const { content } = await result; + + const $ = cheerio.load(content || ''); + + const first13 = excerptContent($('*').first().text(), 13); + + // Update these values with the expected values from + // the article. + assert.equal(first13, 'The Amazon Echo Dot, the retailer’s puck-shaped smart speaker, is is killing it'); + }); + }); +}); diff --git a/src/extractors/custom/index.js b/src/extractors/custom/index.js index 0534fa790..0e173e5c3 100644 --- a/src/extractors/custom/index.js +++ b/src/extractors/custom/index.js @@ -51,3 +51,4 @@ export * from './thoughtcatalog.com'; export * from './www.nj.com'; export * from './www.inquisitr.com'; export * from './www.nbcnews.com'; +export * from './fortune.com';