Thank you for taking the time to read this post!
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:
And here's the python:
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:
[Rainmeter]Update=1000DynamicWindowSize=1AccurateText=1[Variables]PythonScriptPath="C:\\Users\\Victo\\Code\\Projects\\rainmeter\\RainmeterGoogleCalendar\\Python\\google_calendar.py"[MeasurePython]Measure=PluginPlugin=RunCommandParameter=python "C:\\Users\\Victo\\Code\\Projects\\rainmeter\\RainmeterGoogleCalendar\\Python\\google_calendar.py"OutputType=ANSIUpdateDivider=600 ; Update every 10 minutesDynamicVariables=1FinishAction=[!Log "MeasurePython Output: %1"][!UpdateMeter EventMeter][!Redraw][EventMeter]Meter=StringMeasureName=MeasurePythonX=0Y=0W=300H=25Padding=5,5,5,5FontColor=255,255,255,255SolidColor=47,47,47,255AntiAlias=1Text="%1"LeftMouseUpAction=["https://calendar.google.com"]DynamicVariables=1
Code:
from google.oauth2.credentials import Credentialsfrom googleapiclient.discovery import buildfrom google_auth_oauthlib.flow import InstalledAppFlowfrom google.auth.transport.requests import Requestfrom datetime import datetime, timedelta, timezoneimport pytzimport pickleimport osSCOPES = ['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 credsdef 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())
Statistics: Posted by Polymath_88 — April 25th, 2024, 6:57 pm — Replies 3 — Views 78