-
Notifications
You must be signed in to change notification settings - Fork 0
/
ggl_cal_3_auth.py
70 lines (56 loc) · 1.92 KB
/
ggl_cal_3_auth.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
from apiclient import discovery
from httplib2 import Http
from oauth2client import file, client, tools
from pymongo import MongoClient
from datetime import date, datetime, timedelta
from crawler_combined import concert_ticket_data_list_crawler
#today's date
today_int = date.today()
print("test_app - Today's date:", today_int)
today_str = str(today_int)
# mongodb setup
db_client = MongoClient('your_api_server_ip', 27017)
db = db_client.ukov_dev
def authorizing_all_calendars():
SCOPES = 'https://www.googleapis.com/auth/calendar'
store = file.Storage('storage.json')
creds = store.get()
if not creds or creds.invalid:
print("no storage.json")
flow = client.flow_from_clientsecrets('credentials.json', SCOPES)
creds = tools.run_flow(flow, store)
service = discovery.build('calendar', 'v3', credentials=creds)
calendar_col = db.calendar.find()
for data in calendar_col:
calendar_id = data['calendar_id']
rule = \
{
'scope':
{
'type': 'default'
},
'role': 'reader'
}
created_rule = service.acl().insert(calendarId=calendar_id, body=rule).execute()
print(created_rule['id'])
# authorizing_all_calendars()
def authorizing_one_calendar(calendar_id):
SCOPES = 'https://www.googleapis.com/auth/calendar'
store = file.Storage('storage.json')
creds = store.get()
if not creds or creds.invalid:
print("no storage.json")
flow = client.flow_from_clientsecrets('credentials.json', SCOPES)
creds = tools.run_flow(flow, store)
service = discovery.build('calendar', 'v3', credentials=creds)
rule = \
{
'scope':
{
'type': 'default',
'value':'your_gmail_here'
},
'role': 'writer'
}
created_rule = service.acl().insert(calendarId=calendar_id, body=rule).execute()
print(created_rule['id'])