diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..c18dd8d --- /dev/null +++ b/.gitignore @@ -0,0 +1 @@ +__pycache__/ diff --git a/calendarevents.json b/calendarevents.json new file mode 100644 index 0000000..b34de3f --- /dev/null +++ b/calendarevents.json @@ -0,0 +1 @@ +{"kind": "calendar#events", "events": [{"name": "Sleep", "isAllDay": false, "color": "#616161", "startDateTime": {"date": {"year": 2020, "month": 3, "day": 28}, "time": {"hour": 0, "minute": 0, "second": 0}}, "stopDateTime": {"date": {"year": 2020, "month": 3, "day": 28}, "time": {"hour": 8, "minute": 0, "second": 0}}}, {"name": "Sleep", "isAllDay": false, "color": "#616161", "startDateTime": {"date": {"year": 2020, "month": 3, "day": 29}, "time": {"hour": 0, "minute": 0, "second": 0}}, "stopDateTime": {"date": {"year": 2020, "month": 3, "day": 29}, "time": {"hour": 8, "minute": 0, "second": 0}}}]} \ No newline at end of file diff --git a/quickstart.py b/caltojson.py similarity index 89% rename from quickstart.py rename to caltojson.py index 997744c..8799267 100644 --- a/quickstart.py +++ b/caltojson.py @@ -58,7 +58,7 @@ class Event: if self.allDay: print(self.name + "All Day") else: - print(self.name + ": " + self.NaturalColorId) + print(self.name + ": " + self.naturalColorId) class Calendar: @@ -67,14 +67,21 @@ class Calendar: self.calendarId = calendarId_ self.color = color_ -def calendarCredentials(): +def calendarCredentials(token = None): creds = None # The file token.pickle stores the user's access and refresh tokens, and is # created automatically when the authorization flow completes for the first # time. - if os.path.exists('token.pickle'): - with open('token.pickle', 'rb') as token: - creds = pickle.load(token) + + if token == None: + if os.path.exists('token.pickle'): + with open('token.pickle', 'rb') as token: + token.seek(0) + creds = pickle.load(token) + + else: + creds = pickle.load(token) + # If there are no (valid) credentials available, let the user log in. if not creds or not creds.valid: if creds and creds.expired and creds.refresh_token: @@ -82,7 +89,7 @@ def calendarCredentials(): else: flow = InstalledAppFlow.from_client_secrets_file( 'credentials.json', SCOPES) - creds = flow.run_local_server(port=0) + creds = flow.run_local_server(port=1234) # Save the credentials for the next run with open('token.pickle', 'wb') as token: pickle.dump(creds, token) @@ -204,7 +211,10 @@ def printColors(colors): print(f"{i}: {col}") def main(): - service = calendarCredentials() + generateJsonFromCalendarEntries() + +def generateJsonFromCalendarEntries(token = None): + service = calendarCredentials(token) # define today and tomorrow now = datetime.datetime.now(datetime.timezone.utc).astimezone() @@ -220,6 +230,5 @@ def main(): toJson(allEvents) - if __name__ == '__main__': main() diff --git a/token.pickle b/token.pickle2 similarity index 65% rename from token.pickle rename to token.pickle2 index 58158b4..5552e0a 100644 Binary files a/token.pickle and b/token.pickle2 differ