It is currently February 25th, 2021, 10:29 pm

Reuters RSS feed

RSS, ATOM and other feeds, GMail, Stocks, any information retrieved from the internet
User avatar
jsmorley
Developer
Posts: 21546
Joined: April 19th, 2009, 11:02 pm
Location: Fort Hunt, Virginia, USA

Reuters RSS feed

Post by jsmorley »

Reuters_1.0.rmskin
1.png
Skin:

Code: Select all

[Rainmeter]
Update=1000
AccurateText=1
MouseScrollDownAction=[!Refresh]

[Metadata]
Name=Reuters
Author=Jeffrey Morley
Information=Description: | List of the 10 latest items from Reuters News. | Scroll down to refresh. 
Version=Sep 23, 2017
License=Creative Commons Attribution-Non-Commercial-Share Alike 3.0

[Variables]
FontFace=Fira Sans
FontColor=255,255,255,255
SkinWidth=421
NewMinutes=10
NewColor=207,250,213,255

[MeasureReuters]
Measure=Plugin
Plugin=WebParser
URL=http://feeds.reuters.com/reuters/topNews
RegExp=(?siU)^(.*)$
UpdateRate=120
ForceReload=1
FinishAction=[!UnpauseMeasure MeasureLuaScript][!UpdateMeasure MeasureLuaScript]
DecodeCharacterReference=1

[MeasureLuaScript]
Measure=Script
ScriptFile=Reuters.lua
UpdateDivider=-1
Paused=1

[TextStyle]
W=(#SkinWidth# - 25)
H=16
X=9
Y=0R
InlineSetting=Face | #FontFace#
InlineSetting2=Size | 11
InlineSetting3=Color | #FontColor#
InlineSetting4=Weight | 400
SolidColor=0,0,0,1
Padding=5,5,5,5
StringAlign=Left
ClipString=1
AntiAlias=1
ToolTipType=1
ToolTipWidth=250

[MeterBackGround]
Meter=Shape
Shape=Rectangle 1,1,421,308 | StrokeWidth 2 | StrokeColor 110,110,110,255 | Fill Color 0,0,0,255

[MeterLogo]
Meter=Image
ImageName=#@#Images\Reuters.png
X=14
Y=8
LeftMouseUpAction=["http://www.reuters.com/"]

[MeterHeader]
Meter=String
X=10R
Y=16
H=18
Padding=0,0,0,0
AntiAlias=1
Text=Reuters Top News
InlineSetting=Face | #FontFace#
InlineSetting2=Size | 11
InLineSetting3=Weight | 500
InlineSetting4=Color | 233,119,19,255

[MeterTitle1]
Meter=String
MeterStyle=TextStyle
Y=11R
SolidColor=40,40,40,255
UpdateDivider=-1

[MeterTitle2]
Meter=String
MeterStyle=TextStyle
UpdateDivider=-1

[MeterTitle3]
Meter=String
MeterStyle=TextStyle
SolidColor=40,40,40,255
UpdateDivider=-1

[MeterTitle4]
Meter=String
MeterStyle=TextStyle
UpdateDivider=-1

[MeterTitle5]
Meter=String
MeterStyle=TextStyle
SolidColor=40,40,40,255
UpdateDivider=-1

[MeterTitle6]
Meter=String
MeterStyle=TextStyle
UpdateDivider=-1

[MeterTitle7]
Meter=String
MeterStyle=TextStyle
SolidColor=40,40,40,255
UpdateDivider=-1

[MeterTitle8]
Meter=String
MeterStyle=TextStyle
UpdateDivider=-1

[MeterTitle9]
Meter=String
MeterStyle=TextStyle
SolidColor=40,40,40,255
UpdateDivider=-1

[MeterTitle10]
Meter=String
MeterStyle=TextStyle
UpdateDivider=-1
Lua:

Code: Select all

function Initialize()

	measureReuters = SKIN:GetMeasure('MeasureReuters')
	newMinutes = SKIN:GetVariable('NewMinutes')
	newColor = SKIN:GetVariable('NewColor')
	fontColor = SKIN:GetVariable('FontColor')
	
	monthNum = {
	['Jan'] = '1',
	['Feb'] = '2',
	['Mar'] = '3',
	['Apr'] = '4',
	['May'] = '5',
	['Jun'] = '6',
	['Jul'] = '7',
	['Aug'] = '8',
	['Sep'] = '9',
	['Oct'] = '10',
	['Nov'] = '11',
	['Dec'] = '12'
	}

	patternItem = '<item>(.-)</item>'
	patternItemTitle = '<title>(.-)</title>'
	patternItemLink = '<link>(.-)</link>'
	patternItemDate = '<pubDate>(.-)</pubDate>'
	
end

function Update()

	local entireSite = measureReuters:GetStringValue()
	
	BuildTables(entireSite)
	
	for i = 1, 10 do
		
		SKIN:Bang('!SetOption', 'MeterTitle'..i, 'Text', tTitles[i])
		SKIN:Bang('!SetOption', 'MeterTitle'..i, 'LeftMouseUpAction', tLinks[i])
		
		local timeNow = os.time(os.date('!*t'))
		local timeItem = tDates[i]
		local timeDiff = os.difftime(timeNow, timeItem)
		local timeDifferenceFormat = ConvertSeconds(timeDiff)
		
		if timeDifferenceFormat['mins'] == 1 then minText = "minute" else minText="minutes" end
		if timeDifferenceFormat['hours'] == 1 then	hourText = "hour" else hourText="hours" end
		if timeDifferenceFormat['days'] == 1 then dayText = "day" else dayText="days" end
	
		if timeDiff <= 86400 then
			if timeDiff < 3600 then
				ageDisplay = timeDifferenceFormat['mins']..' '..minText..' ago'
			else	
				ageDisplay = timeDifferenceFormat['hours']..' '..hourText..' '..timeDifferenceFormat['mins']..' '..minText..' ago'
			end	
		else
			ageDisplay = timeDifferenceFormat['days']..' '..dayText..' '..timeDifferenceFormat['hours']..' '..hourText..' '..timeDifferenceFormat['mins']..' '..minText..' ago'
		end		

		if timeDiff / 60 <= tonumber(newMinutes) then
			SKIN:Bang('!SetOption', 'MeterTitle'..i, 'InlineSetting3', 'Color | '..newColor)
		else
			SKIN:Bang('!SetOption', 'MeterTitle'..i, 'InlineSetting3', 'Color | '..fontColor)
		end
		
		SKIN:Bang('!SetOption', 'MeterTitle'..i, 'ToolTipText', tTitles[i]..'#CRLF##CRLF#'..ageDisplay)			

	end
		
	SKIN:Bang('!UpdateMeter', '*')
	SKIN:Bang('!Redraw')

end	

function BuildTables(inText)

	tLinks = {}
	tTitles = {}
	tDates = {}
	tCombined = {}

	init = 0
	
	for i = 1, 10 do
		
		itemStart, itemEnd, itemContent = string.find(inText, patternItem, init)
		
		local itemTitle = string.match(itemContent, patternItemTitle)
		local ItemLink = string.match(itemContent, patternItemLink)		
		local itemDate = string.match(itemContent, patternItemDate)

		tCombined[i] = TimeStamp(itemDate)..'||'..itemTitle..'||'..ItemLink
		
		init = itemEnd + 1
		
	end

	table.sort(tCombined, function(a,b) return a>b end)

	for i = 1, 10 do
	
		local tSplit = SplitString(tCombined[i], '||')
		tTitles[i] = tSplit[2]
		tLinks[i] = tSplit[3]
		tDates[i] = tSplit[1]
		
	end
	
end

function TimeStamp(itemDate)
   
   -- feed date format: Mon, 25 Sep 2017 11:22:34 -0400
	local day, monthText, year, hour, min, sec =
	string.match(itemDate, '.-, (.-) (.-) (.-) (.-):(.-):(.-) ')
	month = monthNum[monthText]

	local zhours, zminutes = string.match(itemDate, ' (.%d%d)(%d%d)$')
	if not zhours then zhours = 0 end
	if not zminutes then zminutes = 0 end
   
	local localTime = os.time({year=year, month=month, day=day, hour=hour, min=min, sec=sec, isdst=false})
	local utcTime = localTime - ((tonumber(zhours)*3600) + (tonumber(zminutes)*60))
   
	return utcTime

end

function ConvertSeconds(secondsDiff)
    
	local daysDiff = (secondsDiff / 86400)
	local daysRemainder = (secondsDiff % 86400)
	local hoursDiff = (daysRemainder / 3600)
	local hoursRemainder = ((secondsDiff - 86400) % 3600)
	local minsDiff = (hoursRemainder / 60)
	
	local convertedSeconds = {days = math.floor(daysDiff); hours = math.floor(hoursDiff); mins = math.floor(minsDiff)}	
	
	return convertedSeconds
	
end

function SplitString(inString, inPattern)

	local outTable = {}
	local findPattern = '(.-)' .. inPattern
	local lastEnd = 1
	
	local currentStart, currentEnd, foundString = inString:find(findPattern, 1)
	
	while currentStart do
		if currentStart ~= 1 or foundString ~= '' then
			table.insert(outTable, foundString)
		end
		lastEnd = currentEnd + 1
		currentStart, currentEnd, foundString = inString:find(findPattern, lastEnd)
	end
	
	if lastEnd <= #inString then
		foundString = inString:sub(lastEnd)
		table.insert(outTable, foundString)
	end

	return outTable

end
You do not have the required permissions to view the files attached to this post.
User avatar
eclectic-tech
Rainmeter Sage
Posts: 4226
Joined: April 12th, 2012, 9:40 pm
Location: Cedar Point, Ohio, USA

Re: Reuters RSS feed

Post by eclectic-tech »

Well done, Sir! :thumbup:

Are you planning to add pictures? ... ;-)
CraftyC
Posts: 4
Joined: October 21st, 2017, 9:04 pm

Re: Reuters RSS feed

Post by CraftyC »

Registered to say thanks!