From d087f41e5ea7b65f5bc07d6e853ee0801c7b6ea1 Mon Sep 17 00:00:00 2001 From: Norm Rasmussen Date: Tue, 13 Feb 2024 21:51:21 -0500 Subject: [PATCH] started some local google scripts to help me in my workflow. --- .../_courses_index.html.liquid | 2 +- .../Walmart Luminate Prod/course.html.liquid | 2 +- Scripts/google_local_scripts/credentials.json | 1 + Scripts/google_local_scripts/quickstart.py | 87 +++++++++++++++++++ Scripts/google_local_scripts/test.py | 5 ++ Scripts/google_local_scripts/token.json | 1 + 6 files changed, 96 insertions(+), 2 deletions(-) create mode 100644 Scripts/google_local_scripts/credentials.json create mode 100644 Scripts/google_local_scripts/quickstart.py create mode 100644 Scripts/google_local_scripts/test.py create mode 100644 Scripts/google_local_scripts/token.json diff --git a/Custom_Templates/customer_templates/Walmart Luminate Prod/_courses_index.html.liquid b/Custom_Templates/customer_templates/Walmart Luminate Prod/_courses_index.html.liquid index fa21b83a..204b3aa4 100644 --- a/Custom_Templates/customer_templates/Walmart Luminate Prod/_courses_index.html.liquid +++ b/Custom_Templates/customer_templates/Walmart Luminate Prod/_courses_index.html.liquid @@ -20,7 +20,7 @@ {% include "cards_course" with course %} {% endif %} - + {% endif %} {% endunless %} {% endfor %} diff --git a/Custom_Templates/customer_templates/Walmart Luminate Prod/course.html.liquid b/Custom_Templates/customer_templates/Walmart Luminate Prod/course.html.liquid index c513f5d2..5e0b6d16 100644 --- a/Custom_Templates/customer_templates/Walmart Luminate Prod/course.html.liquid +++ b/Custom_Templates/customer_templates/Walmart Luminate Prod/course.html.liquid @@ -29,7 +29,7 @@ .np-content-categories-content-item { margin-bottom:12px; } - + .course-image-wrapper { position:relative; } diff --git a/Scripts/google_local_scripts/credentials.json b/Scripts/google_local_scripts/credentials.json new file mode 100644 index 00000000..2b1cbda8 --- /dev/null +++ b/Scripts/google_local_scripts/credentials.json @@ -0,0 +1 @@ +{"installed":{"client_id":"630068342412-r85f2brntqqv1jd3kt5ue1a461677hnp.apps.googleusercontent.com","project_id":"gs-ha-calendar","auth_uri":"https://accounts.google.com/o/oauth2/auth","token_uri":"https://oauth2.googleapis.com/token","auth_provider_x509_cert_url":"https://www.googleapis.com/oauth2/v1/certs","client_secret":"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","redirect_uris":["http://localhost"]}} \ No newline at end of file diff --git a/Scripts/google_local_scripts/quickstart.py b/Scripts/google_local_scripts/quickstart.py new file mode 100644 index 00000000..4b86942f --- /dev/null +++ b/Scripts/google_local_scripts/quickstart.py @@ -0,0 +1,87 @@ +import datetime +import subprocess +import os + +from google.auth.transport.requests import Request +from google.oauth2.credentials import Credentials +from google_auth_oauthlib.flow import InstalledAppFlow +from googleapiclient.discovery import build +from googleapiclient.errors import HttpError + +# If modifying these scopes, delete the file token.json. +SCOPES = ["https://www.googleapis.com/auth/calendar.readonly"] + + +def main(): + """Shows basic usage of the Google Calendar API. + Prints the start and name of the next 10 events on the user's calendar. + """ + 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()) + + try: + service = build("calendar", "v3", credentials=creds) + + # Call the Calendar API + now = datetime.datetime.utcnow().isoformat() + "Z" + # time_change = datetime.timedelta(minutes=5) + # print(now) + # now2 = now + time_change + # now2 = now2.isoformat() + "Z" + # print(now2) + events_result = ( + service.events() + .list( + calendarId="primary", + timeMin=now, + maxResults=4, + singleEvents=True, + orderBy="startTime", + ) + .execute() + ) + events = events_result.get("items", []) + + if not events: + print("No upcoming events found.") + return + + # Prints the start and name of the next 10 events + for event in events: + # Parse the datetime first + start = event["start"].get("dateTime", event["start"].get("date"))[:-6] + # start = start[:-6] + start_time = datetime.datetime.strptime(start, "%Y-%m-%dT%H:%M:%S") + now = datetime.datetime.now() + + difference = start_time - now + seconds_in_day = 24 * 60 * 60 + time_left_in_min_sec = divmod(difference.days * seconds_in_day + difference.seconds, 60) + + # Then parse the name to attribute it to a client. + client_name = event["summary"] + # if time_left_in_min_sec[0] < 1: + # print("Upcoming Meeting") + # else: + # print("Nothing new") + # print(start, event["organizer"]["email"]) + if event["eventType"] != "outOfOffice": + # print(event["organizer"]["email"]) + for items in event["attendees"]: + print(items["email"]) + + except HttpError as error: + print(f"An error occurred: {error}") + + +if __name__ == "__main__": + main() diff --git a/Scripts/google_local_scripts/test.py b/Scripts/google_local_scripts/test.py new file mode 100644 index 00000000..1a4b39f2 --- /dev/null +++ b/Scripts/google_local_scripts/test.py @@ -0,0 +1,5 @@ +import subprocess +import os + +os.system("open https://northpass.com") +print("Did it work?") diff --git a/Scripts/google_local_scripts/token.json b/Scripts/google_local_scripts/token.json new file mode 100644 index 00000000..4467af87 --- /dev/null +++ b/Scripts/google_local_scripts/token.json @@ -0,0 +1 @@ +{"token": "ya29.a0AfB_byBRSc2nNXg8jIMk7kStUgZjXCL7dSBr3MiYOxiI8Hxrs5WtqC0ty-YYBYXASu4rbN6DQU5AjRnm3hPLFhsAN9QoDRGexoTK14cEmDsgZUk5RCbKeFhmuWt0-7FE8cxDmsdKWMZM2Yep9RVssVdHg3u9LeXl56isaCgYKAckSARESFQHGX2MiZsmJWVHqQzmC999ESm_9Eg0171", "refresh_token": "1//05KRHdKJcPDY7CgYIARAAGAUSNwF-L9Irk_qUBGUHLodmFLbL0nzj6164LXHuHXODdui_wfz9itU_nuIOrUXGlleOjbhcOpxOjj4", "token_uri": "https://oauth2.googleapis.com/token", "client_id": "630068342412-r85f2brntqqv1jd3kt5ue1a461677hnp.apps.googleusercontent.com", "client_secret": "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", "scopes": ["https://www.googleapis.com/auth/calendar.readonly"], "universe_domain": "googleapis.com", "account": "", "expiry": "2024-02-13T21:39:33.375822Z"} \ No newline at end of file