LittleOne wrote: ↑February 7th, 2020, 4:24 pm
sorry, its hard to explain it correctly
assume:
we work at measure
[_D12] which is getting event for date "12" only
at this month (feb) there is only one event that is at
"2020-02-12" regexp
{0,0}+ will capture it correctly
but then the next month (mar) coming and accidentally there is an event too at same date
"2020-03-12" but before this date there is an event just say at
"2020-03-09" now with this in mind if i not change regexp manually on
[_D12] to
{0,1}+ it will capture the summary at "9", correct?
so what i need is Regexp that will work for date "12" only in measure
[_D12] because the number of event is changing dynamically for every month
once again sorry if i make nerve wracking post, i don't meant to do so.
I've been busy with other jobs - sorry for the delay. I begin to see what you mean - don't worry about my nerves, they're fine, and I'm not bored either, LOL. You probably stated the problem in the wrong way at the beginning, because I understood that you wanted the N-th "event" (if "events" are the actual items in the source), which my regex does. To answer your question, for a source like you described (if I understood it correctly):
Code: Select all
{
"items": [
{
"summary": "Test 1",
"start": {
"date": "2020-02-12"
}
},
{
"summary": "Test 2",
"start": {
"date": "2020-03-09"
}
},
{
"summary": "Test 3",
"start": {
"date": "2020-03-12"
}
},
{
"summary": "Test 4",
"start": {
"date": "2020-03-12"
}
},
{
"summary": "Test 5",
"start": {
"date": "2020-03-15"
}
}
]
}
you want the 1st, the 3rd and the additional - for testing purposes - 4th event, aka the ones that occur on day 12 of each month (i.e. "Test 1", "Test 3" and "Test 4"), but my regex with
{0,1}+ will indeed capture the 2nd event/item, that is "Test 2". What you want is possible, but only if you use substitute in a String measure (i.e. it's not possible for a regex to capture discontinuous/disjoint parts of a text in a single parse / capture as far as I know, and to capture them in separate parses it would have to remember the previous captures, which is again probably not doable).
I think the code below can be satisfactory, and that's pretty much all I can do about it. You should copy paste the source data above to your
WebParserDump.txt file, like before, so you can see the result. What it does is:
- first, get everything from the source into the WebParser parent (i.e.
[MeasureAnalogCalendar])
- the WebParser parent will trigger a "paste" of the data to
[MeasureContents] through its
FinishAction, in order to manipulate and extract every event occuring on day 12 of each month
- next,
MeasureTarget will get
[MeasureContents]'s data and further "chop" it to get the N-th event occuring on day 12 from all the events in
[MeasureContents]. This means that if you want to "select" events on day 12 of a specific month, you'd have to do it in the
Substitute option of
MeasureContents, not here. Here you only "extract" the N-th event from those already existing in
[MeasureContents]
- finally,
[MeasureSummary] and
MeasureDate will extract the summary and the date from the (single or no) event that exists in
MeasureTarget. Because of the
Substitute in the previous measure, if there's no event to get data from, both the summary and the date will display "None"
Code: Select all
[Rainmeter]
Update=1000
DynamicWindowSize=1
AccurateText=1
BackgroundMode=2
SolidColor=0,0,0,255
---Measures---
[MeasureAnalogCalendar]
Measure=WebParser
URL=file://#CURRENTPATH#WebParserDump.txt
RegExp="(?siU)^(.*?)$"
FinishAction=[!SetOption MeasureContents String "[MeasureAnalogCalendar]"][!UpdateMeasure "MeasureContents"][!UpdateMeasure "MeasureTarget"][!UpdateMeasure "MeasureSummary"][!UpdateMeasure "MeasureDate"]
DynamicVariables=1
[MeasureContents]
Measure=String
String=
UpdateDivider=-1
RegExpSubstitute=1
Substitute='(?siU)(?:\s*\{\s*"items":\s*|\s*\{\s*"summary"[^\}]*"\d{4}-\d{2}-\d{2}(?<!12)"\s*\}\s*\},*?\s*|(?<=\])\s*\})':""
DynamicVariables=1
[MeasureTarget]
Measure=String
String=[MeasureContents]
UpdateDivider=-1
RegExpSubstitute=1
Substitute='(?siU)^\s*\[\s*\{(?:.*\}(?:,\s*\{|,\s*\])){0,0}+(.*?)$':"\1","(?:^\\1|\\1$)":"None","(?siU)\},\s*\{.*?$":""
DynamicVariables=1
[MeasureSummary]
Measure=String
String=[MeasureTarget]
UpdateDivider=-1
RegExpSubstitute=1
Substitute='(?siU)^\s*?"summary":\s*"(.*)",\s*"start":\s*\{\s*"date":\s*"(.*)"\s*\}.*?$':"\1"
DynamicVariables=1
[MeasureDate]
Measure=String
String=[MeasureTarget]
UpdateDivider=-1
RegExpSubstitute=1
Substitute='(?siU)^\s*?"summary":\s*"(.*)",\s*"start":\s*\{\s*"date":\s*"(.*)"\s*\}.*?$':"\2"
DynamicVariables=1
---Meters---
[MeterSummary]
Meter=String
X=5
Y=5R
MeasureName=MeasureSummary
FontSize=14
FontColor=222,255,227,255
StringStyle=Bold
AntiAlias=1
[MeterDate]
Meter=String
MeasureName=MeasureDate
X=5
Y=5R
FontSize=14
FontColor=222,255,227,255
StringStyle=Bold
AntiAlias=1
Bottom line,
MeasureAnalogCalendar will have everything from the source,
MeasureContents will have all events occuring on day 12 from the source (but as I said, you can get just those from, say, March, if you edit its
Substitute),
MeasureTarget will have the N-th such event and
MeasureSummary and
MeasureDate will have the summary and the date of the N-th event, respectively.
Note: Bear in mind that the "selection" of data in these measures is not done by actual parsing, but by chopping/cutting the rest of the data (the one that's not needed) from the string. So, the
"\d{4}-\d{2}-\d{2}(?<!12)" in
[MeasureContents] means that every event occuring on a day
other than 12 will be eliminated from the string, using the
(?<!12) negative lookbehind. If you need to extract, for example, every event occuring on day 12 of March, you'd have to replace
(?<!12) with
(?<!03-12), and so on.