Skip to content

Commit

Permalink
Top 10 upcoming events
Browse files Browse the repository at this point in the history
  • Loading branch information
shyamkanani committed Jul 9, 2018
1 parent cea85d7 commit 9d7be2c
Show file tree
Hide file tree
Showing 3 changed files with 49 additions and 0 deletions.
47 changes: 47 additions & 0 deletions windows/benji.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
import ctypes
import random
import urllib
import datetime
import ssl
from bs4 import BeautifulSoup
import win32com.client as wicl
Expand All @@ -31,6 +32,10 @@
import dataset
import trainer
import recognizer
from httplib2 import Http
from oauth2client import file, client, tools
from apiclient.discovery import build


requests.packages.urllib3.disable_warnings()
try:
Expand Down Expand Up @@ -75,6 +80,48 @@ def events(frame,put):
pic.save(spath)
except:
print("Unable to take screenshot.")

#Upcoming events
elif put.startswith("upcoming events") or put.startswith("coming events") or put.startswith("events"):
try:
SCOPES = 'https://www.googleapis.com/auth/calendar.readonly'
store = file.Storage('credentials.json')
creds = store.get()
if not creds or creds.invalid:
flow = client.flow_from_clientsecrets('client_secret.json', SCOPES)
creds = tools.run_flow(flow, store)
service = build('calendar', 'v3', http=creds.authorize(Http()))

now = datetime.datetime.utcnow().isoformat() + 'z' # 'Z' indicates UTC time
root = tk.Tk()
root.title("Top 10 Upcoming Events")

events_result = service.events().list(calendarId='primary', timeMin=now,maxResults=10, singleEvents=True,orderBy='startTime').execute()
events = events_result.get('items', [])

if not events:
w = tk.Label(root, text="No upcoming events found.")
w.pack()

w = tk.Label(root, text="Event Title")
w.grid(row=0, column=1)
w = tk.Label(root, text="Time And Date Of Event")
w.grid(row=0, column=2)

i=1
for event in events:
start = event['start'].get('dateTime', event['start'].get('date'))
w = tk.Label(root, text=event['summary'])
w.grid(row=i, column=1)
w = tk.Label(root, text=start)
w.grid(row=i, column=2)
i=i+1

root.geometry("400x400")
root.mainloop()
except:
print("Unable to take upcoming events")

#Add note
elif put.startswith("note") or put.startswith("not") or put.startswith("node"):
try:
Expand Down
1 change: 1 addition & 0 deletions windows/client_secret.json
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{"installed":{"client_id":"722399897481-v76kg1sml6o55op08kpi7ksf5h1fhb98.apps.googleusercontent.com","project_id":"algebraic-creek-207209","auth_uri":"https://accounts.google.com/o/oauth2/auth","token_uri":"https://accounts.google.com/o/oauth2/token","auth_provider_x509_cert_url":"https://www.googleapis.com/oauth2/v1/certs","client_secret":"VO-i1I4bMRaXEbBVB0aqWaPt","redirect_uris":["urn:ietf:wg:oauth:2.0:oob","http://localhost"]}}
1 change: 1 addition & 0 deletions windows/credentials.json
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{"access_token": "ya29.Gl3zBf0py_5iv8tTp3vbKJhCvQ-oO9yxIvEbGz1I0f6inA_SLCYJlz9f-qPz7MeySX5Vvsc6eyaelXyLYYEBDcVxEO88Q_UqUaBkItvEZT-4jtrjTNh-tQsvJRWX3DU", "client_id": "722399897481-v76kg1sml6o55op08kpi7ksf5h1fhb98.apps.googleusercontent.com", "client_secret": "VO-i1I4bMRaXEbBVB0aqWaPt", "refresh_token": "1/J9emYLWnTTJZtqiWdWg7399L4qaLdKLHVvWykqg2JKg", "token_expiry": "2018-07-09T12:12:59Z", "token_uri": "https://accounts.google.com/o/oauth2/token", "user_agent": null, "revoke_uri": "https://accounts.google.com/o/oauth2/revoke", "id_token": null, "id_token_jwt": null, "token_response": {"access_token": "ya29.Gl3zBf0py_5iv8tTp3vbKJhCvQ-oO9yxIvEbGz1I0f6inA_SLCYJlz9f-qPz7MeySX5Vvsc6eyaelXyLYYEBDcVxEO88Q_UqUaBkItvEZT-4jtrjTNh-tQsvJRWX3DU", "expires_in": 3600, "token_type": "Bearer"}, "scopes": ["https://www.googleapis.com/auth/calendar.readonly"], "token_info_uri": "https://www.googleapis.com/oauth2/v3/tokeninfo", "invalid": false, "_class": "OAuth2Credentials", "_module": "oauth2client.client"}

0 comments on commit 9d7be2c

Please sign in to comment.