The sorting by date works (and is necessary because BBC feeds are not always sorted chronologicaly) but I'm dashed if I can get the bulleting of recent feeds to work when the skin has more than one feed that can be displayed and flipped through using ArrowNext, Grabber and ArrowPrevious meters.
All I want to do is bullet those items that are new since the last time the [MeasureFeed] was updated according to #UpdateRate# but ignore any changes resulting from the display being updated by using ArrowNext, Grabber or ArrowPrevious.
The bits of code I've added to the Evereader.ini file are limited to:
Code: Select all
[Variables]
LatestPost1=0
LatestPost2=0
LatestPost3=0
URL1=http://feeds.bbci.co.uk/news/rss.xml?edition=uk
URL2=http://feeds.bbci.co.uk/news/science_and_environment/rss.xml
URL3=http://feeds.bbci.co.uk/news/technology/rss.xml
[MeasureLuaScript]
TimedUpdate=1
-->> -- Added for sorting BBC feeds / bulleting latest feeds ----------<<
and
-->> END of added stuff ------------------------------------------------<<
Code: Select all
PROPERTIES = {
FeedMeasureName = '';
MultipleFeeds = 0;
VariablePrefix = '';
MinItems = 0;
FinishAction = '';
-->> -- Added for sorting BBC feeds / bulleting latest feeds ----------<<
TimedUpdate = 0
-->> END of added stuff ------------------------------------------------<<
}
-- When Rainmeter supports escape characters for bangs, use this function to escape quotes.
function ParseSpecialCharacters(sString)
sString = string.gsub(sString, '\"', '')
return sString
end
function Initialize()
sFeedMeasureName = PROPERTIES.FeedMeasureName
iMultipleFeeds = tonumber(PROPERTIES.MultipleFeeds)
sVariablePrefix = PROPERTIES.VariablePrefix
iMinItems = tonumber(PROPERTIES.MinItems)
sFinishAction = PROPERTIES.FinishAction
tFeeds = {}
tTitles = {}
tLinks = {}
tDates = {}
-->> -- Added for sorting BBC feeds / bulleting latest feeds ----------<<
iTimedUpdate = tonumber(PROPERTIES.TimedUpdate)
tmText = {"Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec"}
tmNum = {"01", "02", "03", "04", "05", "06", "07", "08", "09", "10", "11", "12"}
-->> END of added stuff ------------------------------------------------<<
end
function Update()
-----------------------------------------------------------------------
-- INPUT FEED(S)
if iMultipleFeeds == 1 then
iNumberOfFeeds = tonumber(SKIN:GetVariable(sVariablePrefix..'NumberOfFeeds'))
for i = 1, iNumberOfFeeds do
tFeeds[i] = SKIN:GetVariable(sVariablePrefix..'FeedMeasureName'..i)
end
iCurrentFeed = tonumber(SKIN:GetVariable(sVariablePrefix..'CurrentFeed'))
msRaw = SKIN:GetMeasure(tFeeds[iCurrentFeed])
else
msRaw = SKIN:GetMeasure(sFeedMeasureName)
end
sRaw = msRaw:GetStringValue()
-----------------------------------------------------------------------
-- DETERMINE FEED FORMAT AND CONTENTS
sPatternFeedTitle = '.-<title.->(.-)</title>'
sPatternItemTitle = '.-<title.->(.-)</title>'
if string.match(sRaw, 'xmlns:gCal') then
sRawCounted, iNumberOfItems = string.gsub(sRaw, '<entry', "")
sPatternFeedLink = '.-<link.-rel=.-alternate.-href=\'(.-)\''
sPatternItem = '<entry.-</entry>'
sPatternItemLink = '.-<link.-href=\'(.-)\''
sPatternItemDate = '.-When: (.-)<'
elseif string.match(sRaw, '<subtitle>rememberthemilk.com</subtitle>') then
sRawCounted, iNumberOfItems = string.gsub(sRaw, '<entry', "")
sPatternFeedLink = '.-<link.-rel=.-alternate.-href="(.-)"'
sPatternItem = '<entry.-</entry>'
sPatternItemLink = '.-<link.-href="(.-)"'
sPatternItemDate = '<span class="rtm_due_value">(.-)</span>'
elseif string.match(sRaw, '<rss.-version=".-".->') then
sRawCounted, iNumberOfItems = string.gsub(sRaw, '<item', "")
sPatternFeedLink = '.-<link.->(.-)</link>'
sPatternItem = '<item.-</item>'
sPatternItemLink = '.-<link.->(.-)</link>'
sPatternItemDesc = '.-<description.->(.-)</description>'
sPatternItemDate = '.-<pubDate.->(.-)</pubDate>'
else
sRawCounted, iNumberOfItems = string.gsub(sRaw, '<entry', "")
sPatternFeedLink = '.-<link.-href="(.-)"'
sPatternItem = '<entry.-</entry>'
sPatternItemLink = '.-<link.-href="(.-)"'
sPatternItemDesc = '.-<summary.->(.-)</summary>'
sPatternItemDate = '.-<updated.->(.-)</updated>'
end
-----------------------------------------------------------------------
-- ERRORS
sFeedTitle, sFeedLink = string.match(sRaw, sPatternFeedTitle..sPatternFeedLink)
if not sFeedTitle then
FeedError('Matching Error', '', 'No valid feed was found.')
return 'Error: matching feed URL.'
elseif iNumberOfItems == 0 then
FeedError(sFeedTitle, '', 'Empty.')
return 'Error: empty feed.'
end
-----------------------------------------------------------------------
-- CREATE DATABASE
sFeedTitle = ParseSpecialCharacters(sFeedTitle)
sFeedLink = ParseSpecialCharacters(sFeedLink)
iInit = 0
for i = 1, iNumberOfItems do
iItemStart, iItemEnd = string.find(sRaw, sPatternItem, iInit)
sItem = string.sub(sRaw, iItemStart, iItemEnd)
tTitles[i] = string.match(sItem, sPatternItemTitle)
tTitles[i] = ParseSpecialCharacters(tTitles[i])
tLinks[i] = string.match(sItem, sPatternItemLink)
tLinks[i] = ParseSpecialCharacters(tLinks[i])
if string.match(sItem, sPatternItemDate) then
tDates[i] = string.match(sItem, sPatternItemDate)
tDates[i] = ParseSpecialCharacters(tDates[i])
else
tDates[i] = ''
end
iInit = iItemEnd + 1
end
-->> -- Added for sorting BBC feeds / bulleting latest feeds ----------<<
-- SET LATEST POST, TIDY UP THE DATE STRING, SORT FEEDS BY DATE
sMostRecent = SKIN:GetVariable('LatestPost'..iCurrentFeed)
for i = 1, iNumberOfItems do
for j = 1, 12 do
tDates[i] = string.gsub(tDates[i], tmText[j] , tmNum[j] )
end
tDates[i] = string.sub(tDates[i], 12, 15)..string.sub(tDates[i], 9, 10)..string.sub(tDates[i],6, 7)..string.sub(tDates[i],17, 18)..string.sub(tDates[i],20,21)..string.sub(tDates[i],23,24)
if tonumber(tDates[i]) > tonumber(sMostRecent)
then tTitles[i] = "• "..tTitles[i]
else tTitles[i] = " "..tTitles[i] end
end
tItems = {}
for i = 1, iNumberOfItems do
table.insert(tItems, { iTitle = tTitles[i], iLinks = tLinks[i], iPub = tDates[i] } )
end
tPubDate_idx = {}
for k, v in pairs( tItems ) do tPubDate_idx[ v.iPub ] = k end
tPubDate_Array = {}
for k, v in pairs(tPubDate_idx) do table.insert(tPubDate_Array, k) end
table.sort(tPubDate_Array, function(a,b) return a > b end)
-->> END of added stuff ------------------------------------------------<<
-----------------------------------------------------------------------
-- OUTPUT
SKIN:Bang('!SetVariable "'..sVariablePrefix..'NumberOfItems" "'..iNumberOfItems..'"')
SKIN:Bang('!SetOption "'..sVariablePrefix..'FeedTitle" "Text" "'..sFeedTitle..'"')
SKIN:Bang('!SetOption "'..sVariablePrefix..'FeedTitle" "LeftMouseUpAction" "'..sFeedLink..'"')
SKIN:Bang('!SetOption "'..sVariablePrefix..'FeedTitle" "ToolTipText" "'..sFeedLink..'"')
-->> -- Added for sorting BBC feeds / bulleting latest feeds ----------<<
-- SET LATEST FEED DATE/TIME
if iTimedUpdate == 1 then
SKIN:Bang('!SetVariable "LatestPost'..iCurrentFeed..'" "'..tostring(tPubDate_Array[1])..'"')
end
for i, v in ipairs(tPubDate_Array) do
iPubdate = v
recnum = tPubDate_idx[iPubdate]
Record = tItems[recnum]
SKIN:Bang('!SetOption "'..sVariablePrefix..'FeedItem'..i..'" "Text" "'..Record.iTitle..'"')
SKIN:Bang('!SetOption "'..sVariablePrefix..'FeedItem'..i..'" "LeftMouseUpAction" "'..Record.iLinks..'"')
end
-->> END of added stuff ------------------------------------------------<<
-----------------------------------------------------------------------
-- FINISH ACTION
if sFinishAction ~= '' then
SKIN:Bang(sFinishAction)
end
return 'Success!'
end
---------------------------------------------------------------------
-- SWITCHERS
function SwitchToNext()
-->> -- Added for sorting BBC feeds / bulleting latest feeds ----------<<
iTimedUpdate = 0
-->> END of added stuff ------------------------------------------------<<
iCurrentFeed = iCurrentFeed%iNumberOfFeeds + 1
SKIN:Bang('!SetVariable "'..sVariablePrefix..'CurrentFeed" "'..iCurrentFeed..'"')
Update()
end
function SwitchToPrevious()
-->> -- Added for sorting BBC feeds / bulleting latest feeds ----------<<
iTimedUpdate = 0
-->> END of added stuff ------------------------------------------------<<
iCurrentFeed = iCurrentFeed - 1 + (iCurrentFeed ==1 and iNumberOfFeeds or 0)
SKIN:Bang('!SetVariable "'..sVariablePrefix..'CurrentFeed" "'..iCurrentFeed..'"')
Update()
end
function FeedError(sErrorName, sErrorLink, sErrorDesc)
SKIN:Bang('!SetOption "'..sVariablePrefix..'FeedTitle" "Text" "'..sErrorName..'"')
SKIN:Bang('!SetOption "'..sVariablePrefix..'FeedTitle" "LeftMouseUpAction" "'..sErrorLink..'"')
SKIN:Bang('!SetOption "'..sVariablePrefix..'FeedTitle" "ToolTipText" "'..sErrorLink..'"')
SKIN:Bang('!SetOption "'..sVariablePrefix..'FeedItem1" "Text" "'..sErrorDesc..'"')
end
;---------------------------------------------------------------------
; METADATA
[Metadata]
Name=Evereader (Universal Feed Reader Prototype)
Config=Evereader
Description=This skin displays the contents of any Atom or RSS feed. | Thanks to Jeffrey Morley for his help in conceiving and writing this skin and script.
Instructions=Set "NumberOfFeeds" as the number of feeds you would like to use. (Though the Lua script can handle an indefinite number of feeds, the skin itself only supports three.) Set Feed1MeasureName, Feed2MeasureName, and Feed3MeasureName as the section names of each WebParser measure.
Version=0.3
Tags=Reader | Feed | RSS | Atom | Lua
License=Creative Commons Attribution-Noncommercial-Share Alike 3.0
Variant=1