added gitignore, renamed functions

This commit is contained in:
Raphael Maenle 2020-04-02 12:24:13 +00:00
parent 5a0d715929
commit 8ad90fc8cc
4 changed files with 19 additions and 8 deletions

1
.gitignore vendored Normal file
View File

@ -0,0 +1 @@
__pycache__/

1
calendarevents.json Normal file
View File

@ -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}}}]}

View File

@ -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()

Binary file not shown.