It is currently May 10th, 2024, 11:38 am

Doubly encoded Chinese HTML entity

Get help with creating, editing & fixing problems with skins
chingyawhao
Posts: 7
Joined: August 29th, 2012, 3:53 am

Doubly encoded Chinese HTML entity

Post by chingyawhao »

I'm a newbie in writing rainmeter coding...I was just recently editing other people's codes for personal use

Just then, I ran into http://gdata.youtube.com/feeds/base/users/tvb/uploads?alt=rss&v=2&orderby=published ...

I want to parse the site but was stuck when I found some doubly encoded Chinese HTML entity such as 文

I saw other posts indicating the problem http://rainmeter.net/forum/viewtopic.php?f=14&t=6814 but there wasn't any solution given.

If only I can substitute & to & first before using DecodeCharacterReference

Is that even possible..?

Please help me....
User avatar
MerlinTheRed
Rainmeter Sage
Posts: 889
Joined: September 6th, 2011, 6:34 am

Re: Doubly encoded Chinese HTML entity

Post by MerlinTheRed »

Hm, I don't know if there is a built-in way of handling this, but in the worst case you might use Download=1 on the WebParser measure to get the whole text file, then use a Lua script to read the file and replace the symbols, then use another WebParser with DecodeCharacterReference to read the file and replace the unicode codes (at least I think that should be possible).
Have more fun creating skins with Sublime Text 2 and the Rainmeter Package!
chingyawhao
Posts: 7
Joined: August 29th, 2012, 3:53 am

Re: Doubly encoded Chinese HTML entity

Post by chingyawhao »

Thanks for ur reply...

However...I had never wrote a lua script before...I think I ll give it a try but I might take time...

U mentioned download=1...
I tried but I couldn't find the file downloaded

I tried specify downloadfile=page.txt
All I get is just a blank 'downloadfile' folder
I m sorry...did I did something wrong..?
User avatar
MerlinTheRed
Rainmeter Sage
Posts: 889
Joined: September 6th, 2011, 6:34 am

Re: Doubly encoded Chinese HTML entity

Post by MerlinTheRed »

Normally, if you add both download=1 and downloadfile=page.txt to the WebParser measure, a file "page.txt" should be created in your skin's folder and contain all the page source code. Can you post your code here? (in code tags please)
Have more fun creating skins with Sublime Text 2 and the Rainmeter Package!
chingyawhao
Posts: 7
Joined: August 29th, 2012, 3:53 am

Re: Doubly encoded Chinese HTML entity

Post by chingyawhao »

Ok...heres the code...but I only copied some of it I think is important...is this enough..?
One more thing...once I wrote these codes "Download=1 DownloadFile=page.txt" in...the description stopped displaying


[Variables]
GET=.*<title>(.+)</title>.*img alt="" src=\"(.+)\".*;span>(.+).</span.*Views:</span>\s(.*)&.*<link>(.+)&

[VIDEO]
Measure=Plugin
Plugin=Plugins\WebParser.dll
UpdateRate=10000
Url=http://gdata.youtube.com/feeds/base/users/TVB/uploads?alt=rss&v=2&orderby=published
RegExp="(?siU)<title>(.+)</title>.*<title>(.+)</title>.*<link>(.+)</link>.*<link>(.+)</link>#GET##GET##GET##GET##GET##GET##GET##GET#"
FinishAction=!RainmeterUpdate "#CURRENTCONFIG#"

[T1]
Measure=Plugin
Plugin=Plugins\WebParser.dll
Url=[VIDEO]
StringIndex=5
DecodeCharacterReference=1

[D1]
Measure=Plugin
Plugin=Plugins\WebParser.dll
Url=[VIDEO]
StringIndex=7
DecodeCharacterReference=1
Download=1
DownloadFile=page.txt

[Title1]
MeasureName=T1
Meter=STRING
X=135
Y=120
FontSize=10
FontFace=Segoe UI
AntiAlias=1
ClipString=1

[Desc1]
MeasureName=D1
Meter=STRING
X=138
Y=145
FontSize=10
FontFace=Segoe UI
AntiAlias=1
ClipString=1
User avatar
MerlinTheRed
Rainmeter Sage
Posts: 889
Joined: September 6th, 2011, 6:34 am

Re: Doubly encoded Chinese HTML entity

Post by MerlinTheRed »

You put Download=1 etc. on the main measure. Once you do that, WebParser will no longer parse the site of the url (so you can't use "child" measures of this WebParser measure). It will just download the file and do nothing else. You'll need a second WebParser measure to parse the file from disk. It might look something like this:

Code: Select all

[Variables]
GET=.*<title>(.+)</title>.*img alt="" src=\"(.+)\".*;span>(.+).</span.*Views:</span>\s(.*)&.*<link>(.+)&

[Downloader]
Measure=Plugin
Plugin=WebParser
UpdateRate=10000
Url=http://gdata.youtube.com/feeds/base/users/TVB/uploads?alt=rss&v=2&orderby=published
FinishAction=!UpdateMeasure "VIDEO"
Download=1
DownloadFile=#ROOTCONFIGPATH#page.txt

[VIDEO]
Measure=Plugin
Plugin=WebParser
UpdateRate=10000
Url=file://#ROOTCONFIGPATH#page.txt
RegExp="(?siU)<title>(.+)</title>.*<title>(.+)</title>.*<link>(.+)</link>.*<link>(.+)</link>#GET##GET##GET##GET##GET##GET##GET##GET#"
FinishAction=!Update "#CURRENTCONFIG#"
DecodeCharacterReference=1

[T1]
Measure=Plugin
Plugin=Plugins\WebParser.dll
Url=[VIDEO]
StringIndex=5

[D1]
Measure=Plugin
Plugin=Plugins\WebParser.dll
Url=[VIDEO]
StringIndex=7

[Title1]
MeasureName=T1
Meter=STRING
X=135
Y=120
FontSize=10
FontFace=Segoe UI
AntiAlias=1
ClipString=1

[Desc1]
MeasureName=D1
Meter=STRING
X=138
Y=145
FontSize=10
FontFace=Segoe UI
AntiAlias=1
ClipString=1
You use the first measure to download the page source and the second one to parse the downloaded file's contents. You can then use a Lua script to modify the downloaded file as needed before parsing it with the second WebParser, but that's a different story.
Have more fun creating skins with Sublime Text 2 and the Rainmeter Package!
chingyawhao
Posts: 7
Joined: August 29th, 2012, 3:53 am

Re: Doubly encoded Chinese HTML entity

Post by chingyawhao »

Oo...I see...I'll try that later...need to get dinner 1st...
Thanks a lot...
chingyawhao
Posts: 7
Joined: August 29th, 2012, 3:53 am

Re: Doubly encoded Chinese HTML entity

Post by chingyawhao »

I tried the codings...it works...now it had created a text file
Thanks...

Now...I'll just have to figure out a way to change the file downloaded...
chingyawhao
Posts: 7
Joined: August 29th, 2012, 3:53 am

Re: Doubly encoded Chinese HTML entity

Post by chingyawhao »

I got it...I got it..!
Finally...we succeeded
Thank you so much...

This is my & eliminator.lua

function Initialize()

end

function Update()
local file1=io.open(SKIN:MakePathAbsolute('DownloadFile\\page.txt'), 'r')
local filedata=file1:read('*all')
local newfiledata=string.gsub(filedata,"&","&")
file1:close()

local file2=io.open(SKIN:MakePathAbsolute('DownloadFile\\edited.txt'), 'w+')
file2:write(newfiledata)
file2:close()
end

MerlinTheRed...I ll be lost without you...thank you so much...my friend
User avatar
MerlinTheRed
Rainmeter Sage
Posts: 889
Joined: September 6th, 2011, 6:34 am

Re: Doubly encoded Chinese HTML entity

Post by MerlinTheRed »

Nice :). And you even got the Lua script figured out by yourself. Glad I could help :)
Have more fun creating skins with Sublime Text 2 and the Rainmeter Package!