<commit_before>from __future__ import print_function, unicode_literals
from oauth2client.client import Credentials
from apiclient.discovery import build
import urllib

import httplib2

def __create_service():
    with open('credentials', 'rw') as f:
        credentials = Credentials.new_from_json(f.read())

    http = httplib2.Http()
    http = credentials.authorize(http)

    return build('calendar', 'v3', http=http)

service = __create_service()

#
# first clear all calendars
#

page_token = None

#
# clear all physics calendars
#
while True:
    calendar_list = service.calendarList().list(pageToken=page_token).execute()
    for calendar_list_entry in calendar_list['items']:
        if calendar_list_entry['summary']=='physics':
            print(calendar_list_entry['summary'])
            print(calendar_list_entry['id'])
            print('found physics will delete')
            service.calendars().delete(calendarId=calendar_list_entry['id']).execute()
        page_token = calendar_list.get('nextPageToken')
    if not page_token:
        break


## #https://developers.google.com/google-apps/calendar/v3/reference/calendars/insert

calendar = {
    'summary': 'physics',
    'timeZone': 'America/Los_Angeles'
}
    
created_calendar = service.calendars().insert(body=calendar).execute()

the_id=created_calendar['id']



event = {
  'summary': 'PHYS 203',
  'location': 'HEBB 200',
  'start': {
    'dateTime': '2015-01-06T09:30:00-08:00'
  },
  'end': {
    'dateTime': '2015-01-06T11:00:00-08:00'
  },
    'recurrence': [
    'RRULE:FREQ=WEEKLY;UNTIL=20150401T100000-08:00',
  ],
}


event = {
  'summary': 'Appointment',
  'location': 'Somewhere',
  'start': {
    'dateTime': '2014-09-03T10:00:00.000-07:00',
    'timeZone': 'America/Los_Angeles'
  },
  'end': {
    'dateTime': '2014-09-03T10:25:00.000-07:00',
    'timeZone': 'America/Los_Angeles'
  },
  "recurrence": [
    "RRULE:FREQ=WEEKLY;BYDAY=MO,WE,FR;UNTIL=20150410T230000Z",
  ],
}    

    
created_event = service.events().insert(calendarId=the_id, body=event).execute()

rule = {
    'scope': {
        'type': 'default',
    },
    'role': 'reader'
}

created_rule = service.acl().insert(calendarId=the_id, body=rule).execute()

uri='https://www.google.com/calendar/embed?'
query= urllib.urlencode({'src':the_id,'ctz':'America/Vancouver'})

print('to view: click on: ',uri + query)

## ## print created_rule['id']

## ## print "event: ",created_event['id']

## ## print(service)


<commit_msg>working with dictionary<commit_after>from __future__ import print_function, unicode_literals
from oauth2client.client import Credentials
from apiclient.discovery import build
import urllib

import httplib2

def __create_service():
    with open('credentials', 'rw') as f:
        credentials = Credentials.new_from_json(f.read())

    http = httplib2.Http()
    http = credentials.authorize(http)

    return build('calendar', 'v3', http=http)

service = __create_service()

#
# first clear all calendars
#

page_token = None

#
# clear all physics calendars
#
while True:
    calendar_list = service.calendarList().list(pageToken=page_token).execute()
    for calendar_list_entry in calendar_list['items']:
        if calendar_list_entry['summary']=='physics':
            print(calendar_list_entry['summary'])
            print(calendar_list_entry['id'])
            print('found physics will delete')
            service.calendars().delete(calendarId=calendar_list_entry['id']).execute()
        page_token = calendar_list.get('nextPageToken')
    if not page_token:
        break


## #https://developers.google.com/google-apps/calendar/v3/reference/calendars/insert

calendar = {
    'summary': 'physics',
    'timeZone': 'America/Los_Angeles'
}
    
created_calendar = service.calendars().insert(body=calendar).execute()

the_id=created_calendar['id']



event = {
  'summary': 'PHYS 203',
  'location': 'HEBB 200',
  'start': {
    'dateTime': '2015-01-06T09:30:00-08:00'
  },
  'end': {
    'dateTime': '2015-01-06T11:00:00-08:00'
  },
    'recurrence': [
    'RRULE:FREQ=WEEKLY;UNTIL=20150401T100000-08:00',
  ],
}

from collections import defaultdict

event=defaultdict(dict)

event['summary']='Appointment'
event['location']='Somewhere'
event['start'] = dict(dateTime='2014-09-03T10:00:00-07:00',
                     timeZone='America/Los_Angeles')
event['end'] = dict(dateTime='2014-09-03T10:25:00-07:00',
                   timeZone= 'America/Los_Angeles')

event["recurrence"]= ["RRULE:FREQ=WEEKLY;BYDAY=MO,WE,FR;UNTIL=20150410T230000Z",]


## event['summary']='Appointment'    
## event['location']= 'Somewhere'
## event['start']['datetime']='2014-09-03T10:00:00-07:00'
## event['start']['timeZone']='America/Los_Angeles'
## event['end']['datetime']='2014-09-03T10:25:00-07:00'
## event['end']['timeZone']='America/Los_Angeles'
## event['recurrance']=["RRULE:FREQ=WEEKLY;BYDAY=MO,WE,FR;UNTIL=20150410T230000Z",]

import pprint
pp=pprint.PrettyPrinter(indent=4)
pp.pprint(event)

## event = {
##   'summary': 'Appointment',
##   'location': 'Somewhere',
##   'start': {
##     'dateTime': '2014-09-03T10:00:00-07:00',
##     'timeZone': 'America/Los_Angeles'
##   },
##   'end': {
##     'dateTime': '2014-09-03T10:25:00-07:00',
##     'timeZone': 'America/Los_Angeles'
##   },
##   "recurrence": [
##     "RRULE:FREQ=WEEKLY;BYDAY=MO,WE,FR;UNTIL=20150410T230000Z",
##   ],
## }    

    
created_event = service.events().insert(calendarId=the_id, body=event).execute()

rule = {
    'scope': {
        'type': 'default',
    },
    'role': 'reader'
}

created_rule = service.acl().insert(calendarId=the_id, body=rule).execute()

uri='https://www.google.com/calendar/embed?'
query= urllib.urlencode({'src':the_id,'ctz':'America/Vancouver'})

print('to view: click on: ',uri + query)

## ## print created_rule['id']

## ## print "event: ",created_event['id']

## ## print(service)



{'fraction_non_alphanumeric': 0.17750170183798503, 'fraction_numerical': 0.05735194009530293, 'mean_word_length': 4.347588717015468, 'pattern_counts': {'":': 2, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 4, 'lorem ipsum': 0, 'www.': 2, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4061596', 'n_tokens_mistral': 2331, 'n_tokens_neox': 2122, 'n_words': 304}