I'm working on my first Rainmeter skin after being a user for a few years. I want a widget that displays todays events from my calendar. I am using Python to connect to google calendar, I made a project with the Google Developer Console and got the permissions (maybe not the right one, I think I do, but maybe worth looking into).
Right now the skin is a blank box, when I update Text under EventMeter it updates correctly to reflect what I've hardcoded in, but otherwise I can't even get anything in the Log..
The other night I made a test event in my calendar and that was picked up, but weirdly enough that was the only event it picked up the next day as well (talking about the same event from the day before!)
Here's my .ini:
Code: Select all
[Rainmeter]
Update=1000
DynamicWindowSize=1
AccurateText=1
[Variables]
PythonScriptPath="C:\\Users\\Victo\\Code\\Projects\\rainmeter\\RainmeterGoogleCalendar\\Python\\google_calendar.py"
[MeasurePython]
Measure=Plugin
Plugin=RunCommand
Parameter=python "C:\\Users\\Victo\\Code\\Projects\\rainmeter\\RainmeterGoogleCalendar\\Python\\google_calendar.py"
OutputType=ANSI
UpdateDivider=600 ; Update every 10 minutes
DynamicVariables=1
FinishAction=[!Log "MeasurePython Output: %1"][!UpdateMeter EventMeter][!Redraw]
[EventMeter]
Meter=String
MeasureName=MeasurePython
X=0
Y=0
W=300
H=25
Padding=5,5,5,5
FontColor=255,255,255,255
SolidColor=47,47,47,255
AntiAlias=1
Text="%1"
LeftMouseUpAction=["https://calendar.google.com"]
DynamicVariables=1
Code: Select all
from google.oauth2.credentials import Credentials
from googleapiclient.discovery import build
from google_auth_oauthlib.flow import InstalledAppFlow
from google.auth.transport.requests import Request
from datetime import datetime, timedelta, timezone
import pytz
import pickle
import os
SCOPES = ['https://www.googleapis.com/auth/calendar.readonly']
def authenticate_google_api():
creds = None
if os.path.exists('token.json'):
creds = Credentials.from_authorized_user_file('token.json', SCOPES)
if not creds or not creds.valid:
if creds and creds.expired and creds.refresh_token:
creds.refresh(Request())
else:
flow = InstalledAppFlow.from_client_secrets_file(
'credentials.json', SCOPES)
creds = flow.run_local_server(port=0)
with open('token.json', 'w') as token:
token.write(creds.to_json())
return creds
def fetch_events_for_today():
"""
Fetch events for the current day from Google Calendar, adapting to the calendar's timezone.
"""
service = build('calendar', 'v3', credentials=authenticate_google_api())
# Fetch the primary calendar's timezone
calendar = service.calendars().get(calendarId='primary').execute()
timezone = calendar['timeZone']
local_tz = pytz.timezone(timezone)
local_now = datetime.now(local_tz)
start_of_day = local_now.replace(hour=0, minute=0, second=0, microsecond=0)
end_of_day = start_of_day + timedelta(days=1) - timedelta(seconds=1)
start_of_day = start_of_day.isoformat()
end_of_day = end_of_day.isoformat()
# Fetch the events within this time range
events_result = service.events().list(calendarId='primary', timeMin=start_of_day, timeMax=end_of_day,
singleEvents=True, orderBy='startTime').execute()
events = events_result.get('items', [])
if not events:
return "No events found for today."
events_for_display = []
for event in events:
start = event['start'].get('dateTime', event['start'].get('date'))
summary = event.get('summary', 'No Title')
events_for_display.append(f"{start}: {summary}")
return '\n'.join(events_for_display)
if __name__ == "__main__":
print(fetch_events_for_today())