It is currently April 26th, 2024, 1:45 pm

import csv like the other...

Get help with creating, editing & fixing problems with skins
User avatar
jsmorley
Developer
Posts: 22630
Joined: April 19th, 2009, 11:02 pm
Location: Fort Hunt, Virginia, USA

Re: import csv like the other...

Post by jsmorley »

This might get you started... I do NOT do skin requests on these forums.

Test.ini:

Code: Select all

[Rainmeter]
Update=1000
DynamicWindowSize=1
AccurateText=1

[Variables]

[LuaBirthday]
Measure=Script
ScriptFile=Test.lua
UpdateDivider=3600

[MeterBirthday]
Meter=String
MeasureName=LuaBirthday
FontSize=11
FontWeight=400
FontColor=255,255,255,255
SolidColor=47,47,47,255
Padding=5,5,5,5
AntiAlias=1
DynamicVariables=1
Birthdays.csv:

Code: Select all

Jan 25,1940,Diane Smith
Jan 30,1932,Gladys Hinz
Oct 15,1960,Some Person
Feb 26,1990,William Morley
Mar 6,1967,Norma Morley
Apr 14,1966,Bob Morley
Apr 25,1954,Jeffrey Morley
May 17,1988,Elizabeth Morley
May 18,2004,Daniel Attis
May 31,1957,John Morley
Aug 11,1923,Elinor Morley
Aug 29,1986,Catherine Morley
Nov 4,1992,Christina Morley
Nov 14,1946,Linda Morley
Dec 13,1946,Brad Morley
Test.lua:

Code: Select all

function Initialize()

	filePath = SKIN:MakePathAbsolute('Birthdays.csv')
	
	birthdayArray = {}

	for line in io.lines(filePath) do
		dateValue, yearValue, personName = line:match('%s*(.-),%s*(.-),%s*(.-)$')
		birthdayArray[#birthdayArray + 1] = { dateValue=dateValue, yearValue=yearValue, personName=personName }
	end
	
end

function Update()

	todayString = os.date('%b %d')
	todayString = todayString:gsub('.-%s(0)','')
	yearNow = os.date('%Y')
	
	for inc = 1, #birthdayArray do
	
		if birthdayArray[inc]['dateValue'] == todayString then
			ageValue = tonumber(yearNow) - tonumber(birthdayArray[inc]['yearValue'])
			return birthdayArray[inc]['personName']..' is '..ageValue..' years old today'
		end	
	
	end
	
	return 'None'
	
end

1.jpg


Note that I'm using gsub to strip off any leading zeros on the current day of the month.

This is going to return the first matching birthday. I will leave it to you to figure out how to handle twins...
You do not have the required permissions to view the files attached to this post.
User avatar
jsmorley
Developer
Posts: 22630
Joined: April 19th, 2009, 11:02 pm
Location: Fort Hunt, Virginia, USA

Re: import csv like the other...

Post by jsmorley »

Ok, you might do twins like this:

Test.lua:

Code: Select all

function Initialize()

	filePath = SKIN:MakePathAbsolute('Birthdays.csv')
	
	birthdayArray = {}

	for line in io.lines(filePath) do
		dateValue, yearValue, personName = line:match('%s*(.-),%s*(.-),%s*(.-)$')
		birthdayArray[#birthdayArray + 1] = { dateValue=dateValue, yearValue=yearValue, personName=personName }
	end
	
end

function Update()

	numOfMatches = 0
	returnValue = 'None'
	
	todayString = os.date('%b %d')
	todayString = todayString:gsub('.-%s(0)','')
	yearNow = os.date('%Y')
	
	for inc = 1, #birthdayArray do
	
		if birthdayArray[inc]['dateValue'] == todayString then
			numOfMatches = numOfMatches + 1
			ageValue = tonumber(yearNow) - tonumber(birthdayArray[inc]['yearValue'])
			if numOfMatches > 1 then
				returnValue = returnValue..'\r\n'..birthdayArray[inc]['personName']..' is '..ageValue..' years old today'
			else
				returnValue = birthdayArray[inc]['personName']..' is '..ageValue..' years old today'
			end
		end	
	
	end
	
	return returnValue
	
end

1.jpg
You do not have the required permissions to view the files attached to this post.
User avatar
jsmorley
Developer
Posts: 22630
Joined: April 19th, 2009, 11:02 pm
Location: Fort Hunt, Virginia, USA

Re: import csv like the other...

Post by jsmorley »

dvo wrote: October 16th, 2019, 12:43 pm is there a way to get a value like the name from this script in a meter ? :confused:
I don't follow... The example I posted shows the name in the meter.
User avatar
jsmorley
Developer
Posts: 22630
Joined: April 19th, 2009, 11:02 pm
Location: Fort Hunt, Virginia, USA

Re: import csv like the other...

Post by jsmorley »

Code: Select all

function Initialize()

	filePath = SKIN:MakePathAbsolute('Birthdays.csv')
	
	birthdayArray = {}

	for line in io.lines(filePath) do
		dateValue, yearValue, personName = line:match('%s*(.-),%s*(.-),%s*(.-)$')
		birthdayArray[#birthdayArray + 1] = { dateValue=dateValue, yearValue=yearValue, personName=personName }
	end
	
end

function Update()

	todayString = os.date('%b %d')
	todayString = todayString:gsub('.-%s(0)','')
	yearNow = os.date('%Y')
	
	for inc = 1, #birthdayArray do
	
		if birthdayArray[inc]['dateValue'] == todayString then
			ageValue = tonumber(yearNow) - tonumber(birthdayArray[inc]['yearValue'])
			return birthdayArray[inc]['personName']
		end	
	
	end
	
	return 'None'
	
end
User avatar
jsmorley
Developer
Posts: 22630
Joined: April 19th, 2009, 11:02 pm
Location: Fort Hunt, Virginia, USA

Re: import csv like the other...

Post by jsmorley »

dvo wrote: October 16th, 2019, 1:25 pm so i have to run 3 lua's to get it in parts....
No, in that case we will approach it a bit differently. Hang on a few minutes while I do that.
User avatar
jsmorley
Developer
Posts: 22630
Joined: April 19th, 2009, 11:02 pm
Location: Fort Hunt, Virginia, USA

Re: import csv like the other...

Post by jsmorley »

Test.ini:

Code: Select all

[Rainmeter]
Update=1000
DynamicWindowSize=1
AccurateText=1

[Variables]

[LuaBirthday]
Measure=Script
ScriptFile=Test.lua
Disabled=1

[MeterBirthday1]
Meter=String
FontSize=11
FontWeight=400
FontColor=255,255,255,255
SolidColor=47,47,47,255
Padding=5,5,5,5
AntiAlias=1
DynamicVariables=1
UpdateDivider=3600
Text=[&LuaBirthday:GetBirthday(1, 'dateValue')] [&LuaBirthday:GetBirthday(1, 'yearValue')]  [&LuaBirthday:GetBirthday(1, 'personName')] [&LuaBirthday:GetBirthday(1, 'ageValue')]

[MeterBirthday2]
Meter=String
Y=2R
FontSize=11
FontWeight=400
FontColor=255,255,255,255
SolidColor=47,47,47,255
Padding=5,5,5,5
AntiAlias=1
DynamicVariables=1
UpdateDivider=3600
Text=[&LuaBirthday:GetBirthday(2, 'dateValue')] [&LuaBirthday:GetBirthday(2, 'yearValue')]  [&LuaBirthday:GetBirthday(2, 'personName')] [&LuaBirthday:GetBirthday(2, 'ageValue')]
Test.lua:

Code: Select all

function Initialize()

	filePath = SKIN:MakePathAbsolute('Birthdays.csv')
	
	birthdayArray = {}

	for line in io.lines(filePath) do
		dateValue, yearValue, personName = line:match('%s*(.-),%s*(.-),%s*(.-)$')
		birthdayArray[#birthdayArray + 1] = { dateValue=dateValue, yearValue=yearValue, personName=personName }
	end
	
end

function GetBirthday(matchNumArg, returnTypeArg)

	numOfMatches = 0
	matchedArray = {}
	
	todayString = os.date('%b %d'):gsub('.-%s(0)','')
	yearNow = os.date('%Y')
	
	for inc = 1, #birthdayArray do
	
		if birthdayArray[inc]['dateValue'] == todayString then

			numOfMatches = numOfMatches + 1
			ageValue = tonumber(yearNow) - tonumber(birthdayArray[inc]['yearValue'])
			matchedArray[numOfMatches] = { dateValue=birthdayArray[inc]['dateValue'], yearValue=birthdayArray[inc]['yearValue'], ageValue=ageValue, personName=birthdayArray[inc]['personName'] }

		end	
	
	end
	
	if numOfMatches > 0 and matchNumArg <= numOfMatches then
		SKIN:Bang('!ShowMeter', SKIN:GetVariable('CurrentSection'))
		return matchedArray[matchNumArg][returnTypeArg]
	else
		SKIN:Bang('!HideMeter', SKIN:GetVariable('CurrentSection'))
		return ''
	end
	
end

1.jpg


https://docs.rainmeter.net/manual/lua-scripting/inline-lua/
You do not have the required permissions to view the files attached to this post.
User avatar
jsmorley
Developer
Posts: 22630
Joined: April 19th, 2009, 11:02 pm
Location: Fort Hunt, Virginia, USA

Re: import csv like the other...

Post by jsmorley »

dvo wrote: October 16th, 2019, 2:09 pm
yes this simulair as the script with arrays now you can call them tnx Jsmorley :) you are a great help :thumbup:

i was playing around with that one already so bit by bit i will learn it.. :thumbup: :great: .

I'm glad to answer any specific questions about how Lua works... It's a real programming language, unlike native Rainmeter, so it is a bit harder to wrap your head around than skin code, but as programming languages go, it's one of the easiest to master.

It has very relaxed "typing" of data types, so you aren't constantly fighting that like you do in C++ and such, and in general is pretty forgiving of newbies. The only thing to always keep in mind is that EVERYTHING is case-sensitive in the code. You can't be lazy about that.

The print() function, which outputs to the Rainmeter log, is your friend. It's the best (and really only) way to debug what is going on.

There are tons of online resources and tutorials and all that for it.
User avatar
jsmorley
Developer
Posts: 22630
Joined: April 19th, 2009, 11:02 pm
Location: Fort Hunt, Virginia, USA

Re: import csv like the other...

Post by jsmorley »

These are no longer feeling like "questions" to me, but "skin requests".

Take a look at this skin, and see if you can make use of how it works.

https://forum.rainmeter.net/viewtopic.php?f=27&t=23239&hilit=gmailnotify#p122925