Skip to content
Branch: master
Find file Copy path
Fetching contributors…
Cannot retrieve contributors at this time
29 lines (26 sloc) 879 Bytes
utils = require 'lib/utils'
Config = require 'config'
Service = require 'services/base/service'
ReadingScore = require 'lib/reading-score'
module.exports = class NewscatService extends Service
constructor: ->
# listen to PageVisit add event
@subscribeEvent 'add:PageVisit', @categorize
categorize: (pageVisit) ->
pageUrl = pageVisit.attributes.url
return if pageUrl == null
# console.log "sending #{pageUrl} to newscat for nomz"
url: Config.newscatEndpoint + "?url=#{pageUrl}"
).done((data) ->
category: data['best-category']
title: data.title
content: data.content
wordCount: data.word_count
readingScore: (new ReadingScore($(data.content).text())).fleschKincaid()
).fail((data) ->
# console.log "Ajax request failed"
# console.log data
You can’t perform that action at this time.