Skip to content

Commit

Permalink
CalendarApiWrapper: Tweak printing events
Browse files Browse the repository at this point in the history
  • Loading branch information
szilard-nemeth committed Feb 12, 2024
1 parent db9d380 commit 4a6e8fb
Show file tree
Hide file tree
Showing 4 changed files with 474 additions and 526 deletions.
19 changes: 4 additions & 15 deletions demo/google_calendar/google_calendar_demo.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
import datetime
import logging
import sys
from os.path import expanduser

from googleapiwrapper.common import ServiceType
Expand All @@ -8,6 +10,7 @@


def main():
logging.basicConfig(stream=sys.stdout, level=logging.DEBUG)
SECRET_PROJECTS_DIR = FileUtils.join_path(expanduser("~"), ".secret", "projects", "cloudera")
authorizer = GoogleApiAuthorizer(
ServiceType.CALENDAR,
Expand All @@ -17,22 +20,8 @@ def main():
scopes=ServiceType.CALENDAR.default_scopes,
)
wrapper = CalendarApiWrapper(authorizer)
wrapper.print_events()

list_events(wrapper)


def list_events(wrapper):
"""Shows basic usage of the Google Calendar API.
Prints the start and name of the next 10 events on the user's calendar.
"""
# Call the Calendar API
now = datetime.datetime.utcnow().isoformat() + "Z" # 'Z' indicates UTC time
print("Getting the upcoming 100 events")
events = wrapper.list_events(min_time=now, max_results=100)
# Prints the start and name of the next 10 events
for event in events:
start = event["start"].get("dateTime", event["start"].get("date"))
print(start, event["summary"])


if __name__ == "__main__":
Expand Down
15 changes: 15 additions & 0 deletions googleapiwrapper/google_calendar.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import datetime
import logging

from googleapiclient.discovery import build
Expand Down Expand Up @@ -44,3 +45,17 @@ def list_events(self, min_time, max_results=100, single_events=True, order_by="s
return

return events

def print_events(self, max_results=100):
"""Shows basic usage of the Google Calendar API.
Prints the start and name of the next 10 events on the user's calendar.
"""
# Call the Calendar API
now = datetime.datetime.utcnow().isoformat() + "Z" # 'Z' indicates UTC time
LOG.info("Getting the upcoming %d events", max_results)
events = self.list_events(min_time=now, max_results=max_results)

# Prints the start and name of the next 10 events
for event in events:
start = event["start"].get("dateTime", event["start"].get("date"))
LOG.info("EVENT: %s %s", start, event["summary"])
Loading

0 comments on commit 4a6e8fb

Please sign in to comment.