It is currently May 3rd, 2024, 6:36 pm

Muslim Skin

Get help with creating, editing & fixing problems with skins
hackermaaan
Posts: 3
Joined: April 22nd, 2024, 11:36 pm

Muslim Skin

Post by hackermaaan »

I'm trying to display prayer times in Rainmeter using a Lua script that executes a PowerShell script to fetch prayer time data from a local API. However, despite my efforts, the prayer times are not displaying correctly in Rainmeter.

Scripts Used:

Script.lua:

Code: Select all

-- Contains Lua functions to load and extract prayer times from the PowerShell script

function LoadPrayerTimes()
    local handle = io.popen("powershell.exe -ExecutionPolicy Bypass -File 'C:/Users/Amine/Documents/Rainmeter/Skins/PrayerSkin/PrayerSkin/PrayerTime/GetPrayerTimes.ps1'")
    local output = handle:read("*a")
    handle:close()

    -- Parse the output and return the prayer times as an array
    local prayerTimes = {}
    for time in output:gmatch("%S+") do
        table.insert(prayerTimes, time)
    end

    return prayerTimes
end

function Fajr()
    local prayerTimes = LoadPrayerTimes()
    if prayerTimes then
        return prayerTimes[1]
    else
        return 'N/A'
    end
end

-- Other functions for Dohr, Asr, Maghreb, and Isha are similar to Fajr
GetPrayerTimes.ps1:

Code: Select all

# Perform an HTTP request to get prayer times
$response = Invoke-RestMethod -Uri "http://127.0.0.1:5000/prayer_times" -Method Get

# Check if the request succeeded
if ($response) {
    return $response
} else {
    Write-Host "Failed to retrieve prayer times."
}
PrayerTime.ini:

Code: Select all

[Rainmeter]
Update=1000
DynamicWindowSize=1

[Metadata]
Name=Prayer Times
Author=YourName

[MeasureLua]
Measure=Script
ScriptFile=Script.lua

[MeterFajr]
Meter=String
SolidColor=255,255,255
Text=[&MeasureScript:Fajr()]
DynamicVariables=1

-- Other measures for Dohr, Asr, Maghreb, and Isha are similar to Fajr
I've tried using these scripts to display prayer times in Rainmeter, but it's not working as expected. The prayer times are not displaying correctly in Rainmeter, and I'm not sure why. If anyone has any ideas or suggestions on what I could do to solve this issue, I would greatly appreciate your help.
User avatar
Brian
Developer
Posts: 2689
Joined: November 24th, 2011, 1:42 am
Location: Utah

Re: Muslim Skin

Post by Brian »

io.popen is restricted in lua for Rainmeter.
https://docs.rainmeter.net/manual/lua-scripting/#Restrictions

Your best bet is to use Webparser to download the file, then load the results in your lua script later (if you even need lua for this).

-Brian
hackermaaan
Posts: 3
Joined: April 22nd, 2024, 11:36 pm

Re: Muslim Skin

Post by hackermaaan »

Hi Brian,

Thanks for the heads up!

I've revised the configuration to use the WebParser plugin instead of io.popen, as you suggested. Here's the updated code:
Do you think something like this could work?

Code: Select all

[Rainmeter]
Update=1000
DynamicWindowSize=1

[Metadata]
Name=Prayer Times
Author=Amine

[MeasureParent]
Measure=WebParser
URL=http://127.0.0.1:5000/prayer_times
RegExp=\["(\d{2}:\d{2})","(\d{2}:\d{2})","(\d{2}:\d{2})","(\d{2}:\d{2})","(\d{2}:\d{2})"\]
StringIndex=1
DynamicVariables=1

[MeasureChild1]
Measure=WebParser
URL=[MeasureParent]
StringIndex=1
DynamicVariables=1

[MeterPrayerFajr]
Meter=String
MeasureName=MeasureChild1
X=0
Y=20
FontSize=12
FontColor=255,255,255,255
SolidColor=0,0,0,1
Text="Fajr: %1"
DynamicVariables=1

hackermaaan
Posts: 3
Joined: April 22nd, 2024, 11:36 pm

Re: Muslim Skin

Post by hackermaaan »

Thanks Brian, its works with this code. It was a problem of RegExp:

Code: Select all

[Rainmeter]
Update=1000
DynamicWindowSize=1

[Metadata]
Name=Prayer Times
Author=Amine

[MeasureParent]
Measure=WebParser
URL=http://127.0.0.1:5000/prayer_times
RegExp="\s*"(\d{2}:\d{2})"\s*,\s*"(\d{2}:\d{2})"\s*,\s*"(\d{2}:\d{2})"\s*,\s*"(\d{2}:\d{2})"\s*,\s*"(\d{2}:\d{2})"\s*"
StringIndex=1
DynamicVariables=1

[MeasureChild1]
Measure=WebParser
URL=[MeasureParent]
StringIndex=1
DynamicVariables=1

[MeterPrayerFajr]
Meter=String
MeasureName=MeasureChild1
X=0
Y=20
FontSize=12
FontColor=255,255,255,255
SolidColor=0,0,0,1
Text="Fajr: %1"
DynamicVariables=1

User avatar
Brian
Developer
Posts: 2689
Joined: November 24th, 2011, 1:42 am
Location: Utah

Re: Muslim Skin

Post by Brian »

Nice! :thumbup:

I had a feeling lua wasn't needed.

-Brian
User avatar
Mordasius
Posts: 1173
Joined: January 22nd, 2011, 4:23 pm
Location: GMT +8

Re: Muslim Skin

Post by Mordasius »

hackermaaan wrote: April 23rd, 2024, 12:00 am I'm trying to display prayer times in Rainmeter using a Lua script that executes a PowerShell script to fetch prayer time data from a local API. ...If anyone has any ideas or suggestions on what I could do to solve this issue, I would greatly appreciate your help.
If you want to look at a bit of lua script that calculates the Prayer Times without the need to be online you might like to take a look at

https://www.deviantart.com/mordasius/art/Hijri-Calendar-Prayer-Times-317464091
hijri_calendar.jpg
I've noticed that that skin is almost twelve years old now but I think it still works. I have a more recent version which shows the time to the next adhan, a better representation of the moon phase and changes colour according to your wallpaper (ala Chameleon Colors). Let me know if you are interested.
You do not have the required permissions to view the files attached to this post.