From 8ad90fc8ccbddd78d1437a11de858157a5fe5039 Mon Sep 17 00:00:00 2001 From: raphael Date: Thu, 2 Apr 2020 12:24:13 +0000 Subject: [PATCH] added gitignore, renamed functions --- .gitignore | 1 + calendarevents.json | 1 + quickstart.py => caltojson.py | 25 +++++++++++++++++-------- token.pickle => token.pickle2 | Bin 752 -> 752 bytes 4 files changed, 19 insertions(+), 8 deletions(-) create mode 100644 .gitignore create mode 100644 calendarevents.json rename quickstart.py => caltojson.py (89%) rename token.pickle => token.pickle2 (65%) 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 58158b4824a8e8e9a1f4a79cd97671d374c0271b..5552e0a79c1b46a8e1e1ddb31390fd5528bddf40 100644 GIT binary patch delta 182 zcmeys`hj&qV0}cIUrs=Zm#MLbp=m&3hKZv^p?^hqT1l!~S%h0ye4@FjUs159kFQad zZc2Vgrb|wQyOXPTif4L=ZcezNf4QH9ky)slVZ2dExNecROT2NFYo>QnaHw%)PD**8 ziK$mWm0!A%TV`3gN03vtk!Pq$rCUH`No0JfYng6xynK|IzguyDt4Vxek$IACX>eqG ikgI8=L29CtleuZK#l-iT>@r+T9PB?tHp??!WCQ@5!8*VI delta 182 zcmeys`hj&qV10O~QEG9vZdjRNihq8pzp-INS*CwUUW%JjQkF$kZjNV4MSQW3L70!B ze`#b;kY!O)R&JiDw{xj;m2qXbyGe19t8P`Wzh$9Cq;6nfc3FCMx_O?9L0GzJd5%eP zL1Ab_LB3;Ql#fekae#+QN=Q^iRfxL%-t5;!RPC;>5xo1jXxqFU> iS8!f7ow?EHKhR-8*YHp??!WCQ^D(LS31