It is currently October 27th, 2021, 10:42 pm

help in parsing todo.txt using regexp

Help with creating, editing & fixing problems with skins
aidayong
Posts: 18
Joined: June 22nd, 2011, 7:59 am

help in parsing todo.txt using regexp

Post by aidayong »

i would like to parse todolist txt with this format
2011-01-27 repair kelisa water part ?25/02/2011 @errand
2011-03-08 buy printer @shop
2011-03-09 buy scanjet @shop
2011-04-07 list down rmtr alarm criteria +rmtr
2011-04-10 surf n search how to create android +apk
2011-04-16 buy treadwalk @shop
2011-04-22 buy genographic kit @shop
2011-05-04 update resume @computer
2011-05-07 saline nose @home
2011-05-07 send painting for frame @anywhere
2011-05-12 read menon chapter1 @home
2011-05-22 recode vbs to identify allergic @computer +allergic
2011-05-26 recode inbox to add location +inbox
So i have been trying using webparser plugin with regexp to parse certain line containing context eg. @shop n keep hitting road blocks because of the breakline.

Most that i could get was capturing the first line containing @shop with

Code: Select all

[Shop1]
Measure=Plugin
Plugin=WebParser.dll
Url=file://D:\Dropbox\My_Text\todo.txt
RegExp="(?iU)([0-9]{4}-[0-9]{2}-[0-9]{2}\s(.*)@shop)"
StringIndex=1
UpdateRate=10
Debug=1
now i couldnt capture next line containing @shop because i remove the (?s). any thoughts or idea?
User avatar
santa_ryan
Posts: 397
Joined: June 22nd, 2010, 4:11 am

Re: help in parsing todo.txt using regexp

Post by santa_ryan »

so you want to extract only the lines that have an "@" symbol in them?
I have three rules when I'm trying to help you.
  • Don't get mad when you don't understand something
  • Be VERY specific with what you ask for.
    The more specific you are, the higher the quality of support you receive.
  • Do not just copy and paste what I put in examples and come back saying it doesn't work.
    It does work, but I purposely left blanks that you need to fill for your specific needs.
aidayong
Posts: 18
Joined: June 22nd, 2011, 7:59 am

Re: help in parsing todo.txt using regexp

Post by aidayong »

yup just line containing context @shop. any ideas.
User avatar
jsmorley
Developer
Posts: 22374
Joined: April 19th, 2009, 11:02 pm
Location: Fort Hunt, Virginia, USA

Re: help in parsing todo.txt using regexp

Post by jsmorley »

I wouldn't use WebParser at all in this case... You have a local file, and you want to read it and detect strings in it on a line by line basis. It will be a lot easier and MUCH more powerful and flexible if we do it in Lua.

Test.txt:

Code: Select all

2011-01-27 repair kelisa water part ?25/02/2011 @errand
2011-03-08 buy printer @shop
2011-03-09 buy scanjet @shop
2011-04-07 list down rmtr alarm criteria +rmtr
2011-04-10 surf n search how to create android +apk
2011-04-16 buy treadwalk @shop
2011-04-22 buy genographic kit @shop
2011-05-04 update resume @computer
2011-05-07 saline nose @home
2011-05-07 send painting for frame @anywhere
2011-05-12 read menon chapter1 @home
2011-05-22 recode vbs to identify allergic @computer +allergic
2011-05-26 recode inbox to add location +inbox
Test.ini:

Code: Select all

[Rainmeter]
Update=1000
DynamicWindowSize=1

[MeasureScript]
Measure=Script
ScriptFile=#CURRENTPATH#Test.lua
FileName=#CURRENTPATH#Test.txt
ToDoType=@shop
UpdateDivider=-1

[TextStyle]
X=0
Y=2R
FontFace=Arial
FontSize=11
FontColor=255,255,255,255
SolidColor=0,0,0,1
AntiAlias=1

[MeterHeader]
Meter=String
MeterStyle=TextStyle
X=0
Y=1
H=18
W=235
SolidColor=0,0,0,255
Text=Enter Search
LeftMouseUpAction=!CommandMeasure "MeasureInput" "ExecuteBatch 1"

[MeasureInput]
Measure=Plugin
Plugin=InputText.dll
X=0
Y=0
H=18
W=235
FontFace=Arial
FontSize=11
FontColor=255,255,255,255
SolidColor=0,0,0,255
Command1=!Execute [!SetOption MeasureScript ToDoType "$UserInput$][!UpdateMeasure MeasureScript #CURRENTCONFIG#]

[Meter1]
Meter=String
MeterStyle=TextStyle
Y=5R

[Meter2]
Meter=String
MeterStyle=TextStyle

[Meter3]
Meter=String
MeterStyle=TextStyle

[Meter4]
Meter=String
MeterStyle=TextStyle

[Meter5]
Meter=String
MeterStyle=TextStyle
Test.Lua:

Code: Select all

function Initialize()

	sFileName = SELF:GetOption('FileName')
	
end -->Initialize

function Update()

	for i = 1, 5 do
		SKIN:Bang('!SetOption Meter'..i..' Text \"\"')
	end
	
	hFile = io.open(sFileName)
	if not hFile then print('File error'); return 'File error'; end 
	io.close(hFile)	
	
	sToDoType = SELF:GetOption('ToDoType')
	if sToDoType == '' then SKIN:Bang('!Refresh'); return 'No input'; end
	
	tData = {}	

	for sLine in io.lines(sFileName) do
		if string.find(sLine, sToDoType) then
			table.insert(tData, sLine)
		end
	end
	
	for i = 1, (#tData < 6) and #tData or 5 do
		SKIN:Bang('!SetOption Meter'..i..' Text \"'..tData[i]..'\"')
	end

	return (#tData)

end -->Update
This is a bit quick and rough, but what I have set up is an InputText measure that takes any search string you want. It can be stuff like @shop or @computer if you want, but really can be any string that is contained in the file. You could just as easily enter "2011-03' and it would list everything dated March of last year...

Then that input is passed dynamically as a setting to a Lua Script measure that is then triggered.

The Lua script reads in that Test.txt file, and for any line where your search criteria is found (up to 5, but you can add more meters to the skin .ini and make it as many as you want) it will populate the "Text" setting of a meter to display it.

Feel free to take a look at this, and please, ask any questions about anything you don't get. It's really not hard stuff at all, and once you wrap your head around what it is doing, you can play with it to do all kinds of spiffy things as desired.
3-26-2012 3-13-14 AM.jpg
P.S. I have it defaulting to showing all "@shop" entries, and if in fact that is really all you want (and I'm betting it isn't) you can remove the [MeterHeader] and [MeasureInput] sections completely and it will do exactly what you originally asked. Just show all lines with @shop on them.
You do not have the required permissions to view the files attached to this post.
aidayong
Posts: 18
Joined: June 22nd, 2011, 7:59 am

Re: help in parsing todo.txt using regexp

Post by aidayong »

jsmorley i have never script in lua before so it never cross my mind.

so i play around with it n made some changes to the test.lua
a) i add number line infront of each task (for my info)
b) i remove the date in front of the line just to show the text

Code: Select all

     n=0  
     tData = {}   

   for sLine in io.lines(sFileName) do
    n=n+1
      if string.find(sLine, sToDoType) then
	   sline2=string.sub(sLine,11)
	    table.insert(tData,n..")"..sline2)
      end
   end
i have to agree using lua is much better than banging my head on regexp. thanks a lot
P/s maybe i better learn lua
You do not have the required permissions to view the files attached to this post.
User avatar
jsmorley
Developer
Posts: 22374
Joined: April 19th, 2009, 11:02 pm
Location: Fort Hunt, Virginia, USA

Re: help in parsing todo.txt using regexp

Post by jsmorley »

Looks like you are getting the hang of it just fine.

Glad to help.
aidayong
Posts: 18
Joined: June 22nd, 2011, 7:59 am

Re: help in parsing todo.txt using regexp

Post by aidayong »

Update on lua script for todo.txt. Felt it is was more appropriate to post on rainmeter/lua script forum for the updated script & skin http://rainmeter.net/forum/viewtopic.php?f=99&t=11650