It is currently June 16th, 2019, 9:41 am

Reader

Discuss the use of Lua in Script measures.
Ganbou-Ki
Posts: 13
Joined: October 18th, 2011, 10:21 am

Re: [Proof of Concept] Universal Feed Reader

Ganbou-Ki » November 2nd, 2011, 10:25 am

I've been trying to play around with this skin for a while now, although I don't have much experience with Rainmeter; just this and the Illustro RSS feed (which was fine, but google reader only seems to support 9 feeds). Since posting the code here would be impractical, and I can't seem to upload an attachment of the code file, what do I need under the MeasureFeed and MeasureLuaScript headings, and do I need measureLink and measureItem headings (e.g. measureLink1, measureItem1) as seen in the Illustro skin? Are the FeedItem headings (e.g. FeedItem1) meant to be under Meters, and what should be under those?

Some basic questions I know - I've scoured the thread for all the examples shown and nothing seems to be working, other than my title appearing as #FeedTitle#, my first feed saying "No valid feed was found.", and the rest saying #ItemTitle2# or #ItemTitle5# and so forth (despite it seeming, to me, that there's no difference between the 1st feed code and all other feed code). I left the lua script untouched.

Many thanks to the creator of this skin, and equal thanks to anyone who can provide some help here!
User avatar
Mordasius
Posts: 1059
Joined: January 22nd, 2011, 4:23 pm
Location: GMT +8

Re: [Proof of Concept] Universal Feed Reader

Mordasius » November 2nd, 2011, 2:19 pm

Ganbou-Ki wrote: Since posting the code here would be impractical, and I can't seem to upload an attachment of the code file, ....
I think it will be much easier for someone to help you if you could 'cut' all the code from your skin and 'paste' it inside

Code: Select all

....[Code] brackets here.
Ganbou-Ki
Posts: 13
Joined: October 18th, 2011, 10:21 am

Re: [Proof of Concept] Universal Feed Reader

Ganbou-Ki » November 3rd, 2011, 4:36 am

Mordasius wrote:I think it will be much easier for someone to help you if you could 'cut' all the code from your skin and 'paste' it inside code brackets here.
Hm yeah I hadn't had enough caffeine at that stage, and seemed to forget that the code window would utilise a scrollbar instead of making a giant post >_> anywho,

Code: Select all

[Rainmeter]
Update=1000

[Variables]
NumberOfFeeds=1
FeedMeasureName1=MeasureFeed
;FeedMeasureName2=MeasureFeed2
;FeedMeasureName3=MeasureFeed3
fontName=Tahoma
textSize=8
colorBar=235,170,0,255
colorText=255,255,255,205
CurrentFeed=1

[MeasureFeedParser]
Measure=Script
ScriptFile="omnireader.lua"
FeedMeasureName=MeasureFeed
MultipleFeeds=1

[MeasureFeed]
Measure=Plugin
Plugin=Plugins\WebParser.dll
URL=http://www.google.com/reader/view/feed/#feedURL#?n=24
RegExp=(?siU) (.*)$
;RegExp="(?siU)<h1>(.*)</h1>#getItem##getItem##getItem##getItem##getItem##getItem##getItem##getItem##getItem##getItem##getItem##getItem##getItem##getItem##getItem##getItem##getItem##getItem##getItem##getItem##getItem##getItem##getItem##getItem#"
DecodeCharacterReference=1
UpdateRate=60
NumberOfItems=24
;FeedLink=[MeasureFeed]
;FeedTitle=%1
ItemLink1=[measureLink1]
ItemTitle1=[measureItem1]
ItemLink2=[measureLink2]
ItemTitle2=[measureItem2]

[MeasureLuaScript]
Measure=Script
ScriptFile="omnireader.lua"
Disabled=1
FeedMeasureName=MeasureFeed
MultipleFeeds=1
NumberOfFeeds=1
TimedUpdate=1

[measureLink1]
Measure=Plugin
Plugin=WebParser.dll
Url=[MeasureFeed]

[measureItem1]
Measure=Plugin
Plugin=WebParser.dll
Url=[MeasureFeed]
DecodeCharacterReference=1

[measureLink2]
Measure=Plugin
Plugin=WebParser.dll
Url=[MeasureFeed]

[measureItem2]
Measure=Plugin
Plugin=WebParser.dll
Url=[MeasureFeed]
DecodeCharacterReference=1

; ----------------------------------
; STYLES are used to "centralize" options
; ----------------------------------

[styleTitle]
StringAlign=CENTER
StringStyle=BOLD
StringEffect=SHADOW
FontEffectColor=0,0,0,50
FontColor=#colorText#
FontFace=#fontName#
FontSize=8
AntiAlias=1
ClipString=1

[styleLeftText]
StringAlign=LEFT
; Meters using styleLeftText will be left-aligned.
StringCase=NONE
StringEffect=SHADOW
FontEffectColor=0,0,0,20
FontColor=#colorText#
FontFace=#fontName#
FontSize=#textSize#
AntiAlias=1
ClipString=1

[styleSeperator]
SolidColor=255,255,255,45

; ----------------------------------
; METERS display images, text, bars, etc.
; ----------------------------------

[meterTitle]
Meter=STRING
MeterStyle=styleTitle
MeasureName=MeasureFeed
;Text="%1 Live RSS Feed"
Text=#FeedTitle#
LeftMouseUpAction=#FeedLink#
ToolTipText=#FeedLink#
X=110
Y=20
W=190
H=18

[meterSeperator1]
Meter=IMAGE
MeterStyle=styleSeperator
X=31
Y=52
W=190
H=1

[meterSeperator2]
Meter=IMAGE
MeterStyle=styleSeperator
X=31
Y=72
W=190
H=1

[meterSeperator3]
Meter=IMAGE
MeterStyle=styleSeperator
X=31
Y=92
W=190
H=1

[meterSeperator4]
Meter=IMAGE
MeterStyle=styleSeperator
X=31
Y=112
W=190
H=1

[meterSeperator5]
Meter=IMAGE
MeterStyle=styleSeperator
X=220
Y=32
W=190
H=1

[meterSeperator6]
Meter=IMAGE
MeterStyle=styleSeperator
X=220
Y=52
W=190
H=1

[meterSeperator7]
Meter=IMAGE
MeterStyle=styleSeperator
X=220
Y=72
W=190
H=1

[meterSeperator8]
Meter=IMAGE
MeterStyle=styleSeperator
X=220
Y=92
W=190
H=1

[meterSeperator9]
Meter=IMAGE
MeterStyle=styleSeperator
X=220
Y=112
W=190
H=1

[meterSeperator10]
Meter=IMAGE
MeterStyle=styleSeperator
X=409
Y=32
W=190
H=1

[meterSeperator11]
Meter=IMAGE
MeterStyle=styleSeperator
X=409
Y=52
W=190
H=1

[meterSeperator12]
Meter=IMAGE
MeterStyle=styleSeperator
X=409
Y=72
W=190
H=1

[meterSeperator13]
Meter=IMAGE
MeterStyle=styleSeperator
X=409
Y=92
W=190
H=1

[meterSeperator14]
Meter=IMAGE
MeterStyle=styleSeperator
X=409
Y=112
W=190
H=1

[meterSeperator15]
Meter=IMAGE
MeterStyle=styleSeperator
X=598
Y=32
W=190
H=1

[meterSeperator16]
Meter=IMAGE
MeterStyle=styleSeperator
X=598
Y=52
W=190
H=1

[meterSeperator17]
Meter=IMAGE
MeterStyle=styleSeperator
X=598
Y=72
W=190
H=1

[meterSeperator18]
Meter=IMAGE
MeterStyle=styleSeperator
X=598
Y=92
W=190
H=1

[meterSeperator19]
Meter=IMAGE
MeterStyle=styleSeperator
X=598
Y=112
W=190
H=1

[meterSeperator20]
Meter=IMAGE
MeterStyle=styleSeperator
X=787
Y=32
W=190
H=1

[meterSeperator21]
Meter=IMAGE
MeterStyle=styleSeperator
X=787
Y=52
W=190
H=1

[meterSeperator22]
Meter=IMAGE
MeterStyle=styleSeperator
X=787
Y=72
W=190
H=1

[meterSeperator23]
Meter=IMAGE
MeterStyle=styleSeperator
X=787
Y=92
W=190
H=1

[meterSeperator24]
Meter=IMAGE
MeterStyle=styleSeperator
X=787
Y=112
W=190
H=1

[FeedItem1]
Meter=STRING
MeterStyle=styleLeftText
;MeasureName=measureItem1
X=31
Y=40
W=190
H=14
Text=#ItemTitle1#
LeftMouseUpAction=#ItemLink1#
ToolTipText=#ItemLink1#
;LeftMouseUpAction=!Execute [#ItemLink1#]
DynamicVariables=1

[FeedItem2]
Meter=STRING
MeterStyle=styleLeftText
;MeasureName=measureItem2
X=31
Y=60
W=190
H=14
Text=#ItemTitle2#
LeftMouseUpAction=#ItemLink2#
ToolTipText=#ItemLink2#
;LeftMouseUpAction=!Execute [#ItemLink2#]
DynamicVariables=1

[FeedItem3]
Meter=STRING
MeterStyle=styleLeftText
;MeasureName=measureItem3
X=31
Y=80
W=190
H=14
Text=#ItemTitle3#
LeftMouseUpAction=#ItemLink3#
ToolTipText=#ItemLink3#
;LeftMouseUpAction=!Execute [#ItemLink3#]
DynamicVariables=1

[FeedItem4]
Meter=STRING
MeterStyle=styleLeftText
;MeasureName=measureItem4
X=31
Y=100
W=190
H=14
Text=#ItemTitle4#
LeftMouseUpAction=#ItemLink4#
ToolTipText=#ItemLink4#
;LeftMouseUpAction=!Execute [#ItemLink4#]
DynamicVariables=1

[FeedItem5]
Meter=STRING
MeterStyle=styleLeftText
;MeasureName=measureItem5
X=220
Y=20
W=190
H=14
Text=#ItemTitle5#
LeftMouseUpAction=#ItemLink5#
ToolTipText=#ItemLink5#
;LeftMouseUpAction=!Execute [#ItemLink5#]
DynamicVariables=1

[FeedItem6]
Meter=STRING
MeterStyle=styleLeftText
;MeasureName=measureItem6
X=220
Y=40
W=190
H=14
Text=#ItemTitle6#
LeftMouseUpAction=#ItemLink6#
ToolTipText=#ItemLink6#
;LeftMouseUpAction=!Execute [#ItemLink6#]
DynamicVariables=1

[FeedItem7]
Meter=STRING
MeterStyle=styleLeftText
;MeasureName=measureItem7
X=220
Y=60
W=190
H=14
Text=#ItemTitle7#
LeftMouseUpAction=#ItemLink7#
ToolTipText=#ItemLink7#
;LeftMouseUpAction=!Execute [#ItemLink7#]
DynamicVariables=1

[FeedItem8]
Meter=STRING
MeterStyle=styleLeftText
;MeasureName=measureItem8
X=220
Y=80
W=190
H=14
Text=#ItemTitle8#
LeftMouseUpAction=#ItemLink8#
ToolTipText=#ItemLink8#
;LeftMouseUpAction=!Execute [#ItemLink8#]
DynamicVariables=1

[FeedItem9]
Meter=STRING
MeterStyle=styleLeftText
;MeasureName=measureItem9
X=220
Y=100
W=190
H=14
Text=#ItemTitle9#
LeftMouseUpAction=#ItemLink9#
ToolTipText=#ItemLink9#
;LeftMouseUpAction=!Execute [#ItemLink9#]
DynamicVariables=1

[FeedItem10]
Meter=STRING
MeterStyle=styleLeftText
;MeasureName=measureItem10
X=409
Y=20
W=190
H=14
Text=#ItemTitle10#
LeftMouseUpAction=#ItemLink10#
ToolTipText=#ItemLink10#
;LeftMouseUpAction=!Execute [#ItemLink10#]
DynamicVariables=1

[FeedItem11]
Meter=STRING
MeterStyle=styleLeftText
;MeasureName=measureItem11
X=409
Y=40
W=190
H=14
Text=#ItemTitle11#
LeftMouseUpAction=#ItemLink11#
ToolTipText=#ItemLink11#
;LeftMouseUpAction=!Execute [#ItemLink11#]
DynamicVariables=1

[FeedItem12]
Meter=STRING
MeterStyle=styleLeftText
;MeasureName=measureItem12
X=409
Y=60
W=190
H=14
Text=#ItemTitle12#
LeftMouseUpAction=#ItemLink12#
ToolTipText=#ItemLink12#
;LeftMouseUpAction=!Execute [#ItemLink12#]
DynamicVariables=1

[FeedItem13]
Meter=STRING
MeterStyle=styleLeftText
;MeasureName=measureItem13
X=409
Y=80
W=190
H=14
Text=#ItemTitle13#
LeftMouseUpAction=#ItemLink13#
ToolTipText=#ItemLink13#
;LeftMouseUpAction=!Execute [#ItemLink13#]
DynamicVariables=1

[FeedItem14]
Meter=STRING
MeterStyle=styleLeftText
;MeasureName=measureItem14
X=409
Y=100
W=190
H=14
Text=#ItemTitle14#
LeftMouseUpAction=#ItemLink14#
ToolTipText=#ItemLink14#
;LeftMouseUpAction=!Execute [#ItemLink14#]
DynamicVariables=1
EDIT: There's obviously many things wrong with the above code, but most worryingly it made my laptop heat up considerably (and made Rainmeter run much slower). I chopped around 10 degrees celsius off of the CPU temperature according to SpeedFan by just disabling this skin. O.O
User avatar
Mordasius
Posts: 1059
Joined: January 22nd, 2011, 4:23 pm
Location: GMT +8

Re: [Proof of Concept] Universal Feed Reader

Mordasius » November 3rd, 2011, 9:37 am

Ganbou-Ki wrote:EDIT: There's obviously many things wrong with the above code, but most worryingly it made my laptop heat up considerably....
I'm rather surprised you even managed to get it to run because it gets stuck right away looking for the #feedURL# variable in [MeasureFeed]. It also seems to have two measures running the "omnireader.lua" script which is probably why you got odd outputs like the #FeedTitle#, "No valid feed was found." and #ItemTitle2# reported in your first post. To be honest, I'd be tempted to download the latest version of EverReader from the 1st post in this thread and start again.

I'm sure someone could help if you start with a working version and then explain what it is you want to change. :)
Ganbou-Ki
Posts: 13
Joined: October 18th, 2011, 10:21 am

Re: [Proof of Concept] Universal Feed Reader

Ganbou-Ki » November 4th, 2011, 9:12 am

Oh wow. I didn't even see there was an example skin posted. </derp>. The only thing I'm really after now is to have a character limit on the feed titles, and preferably have a '...' suffix if the character limit is surpassed (I've made the mouseover text display the full title anyway). I'm assuming you change this in the lua file?
User avatar
Mordasius
Posts: 1059
Joined: January 22nd, 2011, 4:23 pm
Location: GMT +8

Re: [Proof of Concept] Universal Feed Reader

Mordasius » November 4th, 2011, 10:48 am

Ganbou-Ki wrote:The only thing I'm really after now is to have a character limit on the feed titles, and preferably have a '...' suffix if the character limit is surpassed
Sounds like you need to use the "Clipstring=1" setting which you can read about here. Then all you'll have to do is add the following to the [FeedTitle] meter:

Code: Select all

[FeedTitle]
Meter=STRING
...
W=300
ClipString=1
Ganbou-Ki
Posts: 13
Joined: October 18th, 2011, 10:21 am

Re: [Proof of Concept] Universal Feed Reader

Ganbou-Ki » November 5th, 2011, 10:50 am

Mordasius wrote:Sounds like you need to use the "Clipstring=1" setting which you can read about here. Then all you'll have to do is add the following to the [FeedTitle] meter:
Thanks! All done now. Cheers for the help :)
User avatar
smurfier
Moderator
Posts: 1937
Joined: January 29th, 2010, 1:43 am
Location: Willmar, MN

Re: [Proof of Concept] Universal Feed Reader

smurfier » January 22nd, 2012, 5:47 pm

I've decided to update the script to reflect a couple changes to Rainmeter and to optimize the code thanks to a few things I've learned.

*** Requires Rainmeter 2.3 r1405 or higher ***

With this version:
  • Set FeedMeasureName on the measure to a Pipe delimited list of the measures you want the script to use.
    • No need to set MultipleFeeds=1
    • Example: FeedMeasureName=MeasureFeed1|MeasureFeed2|MeasureFeed3
  • Change to a certain feed using the SwitchTo() function.
    • Example: !CommandMeasure "Lua" "SwitchTo(3)"
  • Set Sub on the measure to a substitute string to be used on all measures. This is instead of placing the substitute on each individual webparser measure.

Code: Select all

function Initialize()
	Set={
		vPrefix=SELF:GetOption('VariablePrefix',''),
		mItems=SELF:GetNumberOption('MinItems',0),
		Finish=SELF:GetOption('FinishAction',''),
		Sub=SELF:GetOption('Sub',''),
		}
	Matches={
		'xmlns:gCal',
		'<subtitle>rememberthemilk.com</subtitle>',
		'<rss.-version=".-".->',
		}
	sPatternFeedLink={
		'.-<link.-rel=.-alternate.-href=\'(.-)\'',
		'.-<link.-rel=.-alternate.-href="(.-)"',
		'.-<link.->(.-)</link>',
		'.-<link.-href="(.-)"',
		}
	sPatternItem={
		'<entry.-</entry>',
		'<entry.-</entry>',
		'<item.-</item>',
		'<entry.-</entry>',
		}
	sPatternItemLink={
		'.-<link.-href=\'(.-)\'',
		'.-<link.-href="(.-)"',
		'.-<link.->(.-)</link>',
		'.-<link.-href="(.-)"',
		}
	sPatternItemDate={
		'.-When: (.-)<',
		'<span class="rtm_due_value">(.-)</span>',
		'.-<pubDate.->(.-)</pubDate>',
		'.-<updated.->(.-)</updated>',
		}
	iCurrentFeed=1
	Measures={}
	for a in string.gmatch(SELF:GetOption('FeedMeasureName',''),'[^%|]+') do
		table.insert(Measures,SKIN:GetMeasure(a))
	end
	SKIN:Bang('!SetVariable','NumberOfFeeds',#Measures)
end

function Update()
	SKIN:Bang('!SetVariable','CurrentFeed',iCurrentFeed)
	tTitles,tLinks,tDates={},{},{}
	-- INPUT FEED
	sRaw=Substitute(Measures[iCurrentFeed]:GetStringValue(),Set.Sub)
	-- DETERMINE FEED FORMAT AND CONTENTS
	FeedType=4
	for i=1,3 do if string.match(sRaw,Matches[i]) then FeedType=i break end end
	-- CREATE DATABASE
	sFeedTitle,sFeedLink=string.match(sRaw,'.-<title.->(.-)</title>'..sPatternFeedLink[FeedType])
	for sItem in string.gmatch(sRaw,sPatternItem[FeedType]) do
		table.insert(tTitles,string.match(sItem,'.-<title.->(.-)</title>'))
		table.insert(tLinks,string.match(sItem,sPatternItemLink[FeedType]))
		table.insert(tDates,string.match(sItem,sPatternItemDate[FeedType]) or '')
	end
	-- ERRORS
	if not sFeedTitle then
		FeedError('Matching Error','','No valid feed was found.')
		return 'Error: matching.'
	elseif #tTitles==0 then
		FeedError(sFeedTitle,'','Empty.')
		return 'Error: empty feed.'
	end
	-- OUTPUT
	for k,v in pairs({
		NumberOfItems=#tTitles,
		FeedTitle=sFeedTitle,
		FeedLink=sFeedLink,
	}) do SKIN:Bang('!SetVariable',Set.vPrefix..k,v) end
	for i=1,(Set.mItems>#tTitles and Set.mItems or #tTitles) do
		SKIN:Bang('!SetVariable',Set.vPrefix..'ItemTitle'..i, tTitles[i])
		SKIN:Bang('!SetVariable',Set.vPrefix..'ItemLink'..i, tLinks[i] or 'No item found.')
		SKIN:Bang('!SetVariable',Set.vPrefix..'ItemDate'..i, tDates[i])
	end
	-- FINISH ACTION   
	if Set.Finish~='' then SKIN:Bang(Set.Finish) end
	return 'Success!'
end
-- SWITCHERS
function SwitchToNext()
	iCurrentFeed=iCurrentFeed%#Measures+1
	Update()
end

function SwitchToPrevious()
	iCurrentFeed=iCurrentFeed==1 and #Measures or iCurrentFeed-1
	Update()
end

function SwitchTo(a)
	iCurrentFeed=tonumber(a)
	Update()
end

function FeedError(sErrorName,sErrorLink,sErrorDesc)
	for k,v in pairs({
		FeedTitle=sErrorName,
		FeedLink=sErrorLink,
		ItemTitle1=sErrorDesc,
		ItemLink1='',
		ItemDate1='',
	}) do SKIN:Bang('!SetVariable',Set.vPrefix..k,v) end
	for i=2,Set.mItems do
		SKIN:Bang('!SetVariable',Set.vPrefix..'ItemTitle'..i,'')
		SKIN:Bang('!SetVariable',Set.vPrefix..'ItemLink'..i,'')
		SKIN:Bang('!SetVariable',Set.vPrefix..'ItemDate'..i,'')
	end
end

function Substitute(Val,Sub)
	Val=tostring(Val)
	Sub='"'..string.gsub(Sub,'%[','%%%[')..'"'
	local Strip=function(a) return string.match(a,'^[\'"](.*)[\'"]$') or '' end
	for a in string.gmatch(Sub,'[^,]+') do
		local l,r=string.match(a,'(.*):(.*)')
		Val=string.gsub(Val,Strip(l),Strip(r))
	end
	return Val
end
GitHub | DeviantArt | Tumblr
This is the song that never ends. It just goes on and on my friends. Some people started singing it not knowing what it was, and they'll continue singing it forever just because . . .
astyagi2
Posts: 15
Joined: February 11th, 2012, 5:48 am

Re: [Proof of Concept] Universal Feed Reader

astyagi2 » February 12th, 2012, 3:13 am

I don't know what is wrong with my machine but none of your feed is working for me. I am using your Daily - News skin which I downloaded from deviantArt and latest rainmeter on Window XP:( :( :(
User avatar
smurfier
Moderator
Posts: 1937
Joined: January 29th, 2010, 1:43 am
Location: Willmar, MN

Re: [Proof of Concept] Universal Feed Reader

smurfier » February 12th, 2012, 3:35 am

Are there any errors in the Log tab of the About window?
GitHub | DeviantArt | Tumblr
This is the song that never ends. It just goes on and on my friends. Some people started singing it not knowing what it was, and they'll continue singing it forever just because . . .