Example #1
0
def monthly_ss_recorder(client):

	print 'Writing to "Metrics > ' + gsw['1'] + '" spreadsheet...'
	sheet_file = client.open_by_url(gspr['SPREADSHEETURL'])
	ws2 = sheet_file.worksheet(gsw['1'])
	start_row = ws2.find("Direct").row
	column = len(ws2.row_values(start_row)) + 1
	ws2.update_cell(start_row, column, total_direct)
	ws2.update_cell(start_row + 1, column, total_referral)
	ws2.update_cell(start_row + 2, column, total_organic)
	ws2.update_cell(start_row + 3, column, total_social)
	ws2.update_cell(start_row + 4, column, total_other)
	ws2.update_cell(start_row + 5, column, total_monthly)
	print 'Moving to "Metrics > ' + gsw['2'] + '" ...'
	
	print 'Writing to "Metrics > ' + gsw['2'] + '" spreadsheet...'
	ws3 = sheet_file.worksheet(gsw['2'])
	date_row = ws3.find("Date").row
	date_column = len(ws3.row_values(date_row)) + 1
	ws3.update_cell(date_row, date_column, date.today())
	tw_row = ws3.find("Twitter followers").row
	tw_column = len(ws3.row_values(tw_row)) + 1
	ws3.update_cell(tw_row, tw_column, twitter_followers_count)
	gh_row = ws3.find("Github stargazers").row
	gh_column = len(ws3.row_values(gh_row)) + 1
	ws3.update_cell(gh_row, gh_column, stargazers)
	ws3.update_cell(gh_row + 1, gh_column, forks)
	al_row = ws3.find("Alexa rank").row
	al_column = len(ws3.row_values(al_row)) + 1
	ws3.update_cell(al_row, al_column, rank)
	kl_row = ws3.find("Klout Score (login with twitter)").row
	kl_column = len(ws3.row_values(kl_row)) + 1
	ws3.update_cell(kl_row, kl_column, score)
	print 'Finished'
Example #2
0
def monthly_ss_recorder(client):

    print 'Writing to "Metrics > ' + gsw['1'] + '" spreadsheet...'
    sheet_file = client.open_by_url(gspr['SPREADSHEETURL'])
    ws2 = sheet_file.worksheet(gsw['1'])
    start_row = ws2.find("Direct").row
    column = len(ws2.row_values(start_row)) + 1
    ws2.update_cell(start_row, column, total_direct)
    ws2.update_cell(start_row + 1, column, total_referral)
    ws2.update_cell(start_row + 2, column, total_organic)
    ws2.update_cell(start_row + 3, column, total_social)
    ws2.update_cell(start_row + 4, column, total_other)
    ws2.update_cell(start_row + 5, column, total_monthly)
    print 'Moving to "Metrics > ' + gsw['2'] + '" ...'

    print 'Writing to "Metrics > ' + gsw['2'] + '" spreadsheet...'
    ws3 = sheet_file.worksheet(gsw['2'])
    date_row = ws3.find("Date").row
    date_column = len(ws3.row_values(date_row)) + 1
    ws3.update_cell(date_row, date_column, date.today())
    tw_row = ws3.find("Twitter followers").row
    tw_column = len(ws3.row_values(tw_row)) + 1
    ws3.update_cell(tw_row, tw_column, twitter_followers_count)
    gh_row = ws3.find("Github stargazers").row
    gh_column = len(ws3.row_values(gh_row)) + 1
    ws3.update_cell(gh_row, gh_column, stargazers)
    ws3.update_cell(gh_row + 1, gh_column, forks)
    al_row = ws3.find("Alexa rank").row
    al_column = len(ws3.row_values(al_row)) + 1
    ws3.update_cell(al_row, al_column, rank)
    kl_row = ws3.find("Klout Score (login with twitter)").row
    kl_column = len(ws3.row_values(kl_row)) + 1
    ws3.update_cell(kl_row, kl_column, score)
    print 'Finished'
Example #3
0
def weekly_ss_recorder(client):
	
	print 'Writing to "Metrics > ' + gsw['3'] + '" spreadsheet...'
	sheet_file = client.open_by_url(gspr['SPREADSHEETURL'])
	ws = sheet_file.worksheet(gsw['3'])
	row = ws.find("Date").row
	row_values = ws.row_values(row)
	column = len(row_values) + 1
	today = date.today()
	ws.update_cell(row, column, today)
	ws.update_cell(row + 1, column, weekly_sessions)
	ws.update_cell(row + 2, column, mp_signups)
	ws.update_cell(row + 3, column, mp_members)
	ws.update_cell(row + 4, column, mp_features)
	print 'Finished'
Example #4
0
def weekly_ss_recorder(client):

    print 'Writing to "Metrics > ' + gsw['3'] + '" spreadsheet...'
    sheet_file = client.open_by_url(gspr['SPREADSHEETURL'])
    ws = sheet_file.worksheet(gsw['3'])
    row = ws.find("Date").row
    row_values = ws.row_values(row)
    column = len(row_values) + 1
    today = date.today()
    ws.update_cell(row, column, today)
    ws.update_cell(row + 1, column, weekly_sessions)
    ws.update_cell(row + 2, column, mp_signups)
    ws.update_cell(row + 3, column, mp_members)
    ws.update_cell(row + 4, column, mp_features)
    print 'Finished'
Example #5
0
def main():
    """Shows basic usage of the Google Calendar API.
    Prints the start and name of the next 10 events on the user's calendar.
    """
    # The file token.json stores the user's access and refresh tokens, and is
    # created automatically when the authorization flow completes for the first
    # time.

    scope = ['https://spreadsheets.google.com/feeds']
    creds = ServiceAccountCredentials.from_json_keyfile_name('sync/client_secret.json', scope)
    client = gspread.authorize(creds)
    sheet = client.open_by_url(
                        "https://docs.google.com/spreadsheets/d/1Q0OopBJjl5WuxeRNlqpi1V-RGl6PuZbqioPL85bJeSw/edit#gid=0").get_worksheet(
                        0)

    name = 'you'
    nominee = 'nominee_name'
    relation = 'relation'

    from oauth2client import file, client, tools
    store = file.Storage('sync/token.json')
    creds = store.get()
    if not creds or creds.invalid:
        flow = client.flow_from_clientsecrets('credentials.json', SCOPES)
        creds = tools.run_flow(flow, store)

    """page_token = None
                while True:
                    calendar_list = service.calendarList().list(pageToken=page_token).execute()
                    for calendar_list_entry in calendar_list['items']:
                                                print(calendar_list_entry.items())
                                                print()
                                                print()
                    page_token = calendar_list.get('nextPageToken')
                    if not page_token:
                        break
            """
##############################################Start from here#############################################

        
    calendarId_record = '*****@*****.**'
    calendarId_surgeries='*****@*****.**'
    calendarId_important = '*****@*****.**'
    service = build('calendar', 'v3', http=creds.authorize(Http()))
    page_token = None
    ids=sheet.col_values(21)
    row=sheet.row_values(6)
    row_to_update = len(ids)+1



    for calendarId in [calendarId_record, calendarId_surgeries, calendarId_important ]:
      eventss = service.events().list(calendarId=calendarId, pageToken=page_token).execute()
      for key, value in eventss.items():
        try:
          for key, value in value.items():
           
                        print(key,value)
                        print()
                        events_u=events['description'],events['htmlLink']
        except:
            pass                                                                               
                                                                                                

      for event in eventss['items']:
        if event['id'] not in ids:
          row_to_update = row_to_update +1
          time.sleep(1)
          if calendarId==calendarId_surgeries:
            sheet.update_cell(row_to_update, 16, 'no')
            sheet.update_cell(row_to_update, 19, 'Democalender')

          if calendarId==calendarId_important:
            sheet.update_cell(row_to_update, 16, 'no')
            sheet.update_cell(row_to_update, 19, 'Important')
          if calendarId==calendarId_record:
            sheet.update_cell(row_to_update, 16, 'yes')
            sheet.update_cell(row_to_update, 19, 'Records')
          sheet.update_cell(row_to_update, 21, event['id'])
          time.sleep(1)
          date_s = str(event['start'])
          ab=str(date_s[14:24])                   
          bc= str(date_s[26:39])
          try:
            loct = str(event['location'])
            sheet.update_cell(row_to_update, 10, loct)
            print(loct)
          except:
            pass
          sheet.update_cell(row_to_update, 16, str(event['reminders']["overrides"][0]["method"]))
          sheet.update_cell(row_to_update, 11, ab)
          time.sleep(1)
          sheet.update_cell(row_to_update, 13, bc)

          date_e = str(event['end'])
          print (date_e)
          de=str(date_s[14:24])                   
          sheet.update_cell(row_to_update, 12, de)
          ef= str(date_s[26:39])
          time.sleep(1)  
          sheet.update_cell(row_to_update, 14, ef)
          des = str(event['description']).split("\n")          
          print("Updating", event["id"])
          a= str(des[1])
          sheet.update_cell(row_to_update,1, a[10:])
          b= str(des[2])
          sheet.update_cell(row_to_update,2, b[8:])
          time.sleep(1)  
          c= str(des[3])
          sheet.update_cell(row_to_update,3, c[9:])
          d= str(des[4])          
          sheet.update_cell(row_to_update,4, d[5:])
          e= str(des[5])
          time.sleep(1)  
          sheet.update_cell(row_to_update,6, e[24:])
          f= str(des[6])
          sheet.update_cell(row_to_update,7, f[12:])
          time.sleep(1)
          sheet.update_cell(row_to_update, 20, event['htmlLink'])
        else:
                    print("already Updating", event["id"])
Example #6
0
def main():
    """Shows basic usage of the Google Calendar API.
    Prints the start and name of the next 10 events on the user's calendar.
    """
    # The file token.json stores the user's access and refresh tokens, and is
    # created automatically when the authorization flow completes for the first
    # time.
    scope = ['https://spreadsheets.google.com/feeds']
    creds = ServiceAccountCredentials.from_json_keyfile_name(
        'sync/client_secret.json', scope)
    client = gspread.authorize(creds)
    sheet = client.open_by_url(
        "https://docs.google.com/spreadsheets/d/1Q0OopBJjl5WuxeRNlqpi1V-RGl6PuZbqioPL85bJeSw/edit#gid=0"
    ).get_worksheet(0)

    name = 'you'
    nominee = 'nominee_name'
    relation = 'relation'
    r = 0

    from oauth2client import file, client, tools
    store = file.Storage('sync/token.json')
    creds = store.get()
    if not creds or creds.invalid:
        flow = client.flow_from_clientsecrets('credentials.json', SCOPES)
        creds = tools.run_flow(flow, store)

    service = build('calendar', 'v3', http=creds.authorize(Http()))

    page_token = None
    while True:
        calendar_list = service.calendarList().list(
            pageToken=page_token).execute()
        for calendar_list_entry in calendar_list['items']:
            print(calendar_list_entry.items())
            print()
            print()
        page_token = calendar_list.get('nextPageToken')
        if not page_token:
            break
    # Call the Calendar API
    now = datetime.datetime.utcnow().isoformat(
    ) + 'Z'  # 'Z' indicates UTC time
    print('Getting the upcoming 10 events')

    for j in range(6, len(sheet.col_values(2)) + 1):
        colorid = 1
        if str(sheet.row_values(j)[17]) == "Green":
            colorid = 3
        if str(sheet.row_values(j)[17]) == "Blue":
            colorid = 1
        if str(sheet.row_values(j)[17]) == "Red":
            colorid = 4
        if str(sheet.row_values(j)[17]) == "Orange":
            colorid = 6
        if str(sheet.row_values(j)[17]) == "Black":
            colorid = 8
        print(j)
        print(str(sheet.row_values(j)[15]))
        print(str(sheet.row_values(j)[18]))
        event1 = {
            'summary':
            'summary',
            "colorId":
            colorid,
            'location':
            sheet.row_values(j)[9],
            'description':
            "Note:" + sheet.row_values(j)[8] + " \nProcedure:" +
            sheet.row_values(j)[0] + " \nSurgery:" + sheet.row_values(j)[1] +
            " \n Patient:" + sheet.row_values(j)[2] + " \n DOB:" +
            sheet.row_values(j)[3] + "\n medical record number : " +
            sheet.row_values(j)[4] + "\n consultant:" +
            sheet.row_values(j)[5] + "\n residents",
            'start': {
                'dateTime':
                str(sheet.row_values(j)[10]) + 'T' + str(
                    str(sheet.row_values(2)[12]) + ":00-" +
                    str(sheet.row_values(2)[13])),
                'timeZone':
                'Asia/Riyadh',
            },
            'end': {
                'dateTime':
                str(sheet.row_values(j)[11]) + 'T' + str(
                    str(sheet.row_values(2)[12]) + ":00-" +
                    str(sheet.row_values(2)[13])),
                'timeZone':
                'Asia/Riyadh',
            },
            'recurrence': ['RRULE:FREQ=DAILY;COUNT=2'],
            'attendees': [
                {
                    'email': "*****@*****.**"
                },
            ],
            'reminders': {
                'useDefault':
                False,
                'overrides': [
                    {
                        'method': 'popup',
                        'minutes': 24 * 60
                    },
                    {
                        'method': 'popup',
                        'minutes': 10
                    },
                ],
            },
        }

        calendarId_record = '*****@*****.**'
        calendarId_surgeries = '*****@*****.**'
        calendarId_important = '*****@*****.**'

        if str(sheet.row_values(j)[15]) == "yes" and str(
                sheet.row_values(j)[18]) != "Cancelledcallender":
            time.sleep(1)
            sheet.update_cell(j, 20, "-")
            sheet.update_cell(j, 21, "-")
            event_s = service.events().insert(
                calendarId=
                '*****@*****.**',
                body=event1).execute()
            event_id = event_s.get('id')
            time.sleep(1)
            service.events().delete(calendarId=calendarId_surgeries,
                                    eventId=event_id).execute()

            event = service.events().insert(
                calendarId=
                '*****@*****.**',
                body=event1).execute()
            print('Event created: %s' % (event.get('htmlLink')))
            event_id = print(event.get('id'))
            sheet.update_cell(j, 19, "Cancelledcallender")
            sheet.update_cell(j, 20, event.get('htmlLink'))
            sheet.update_cell(j, 21, event.get('id'))
            time.sleep(1)

            if str(sheet.row_values(j)[18]) == "Important":
                updated_event = service.events().move(
                    calendarId=calendarId_important,
                    eventId='eventId',
                    destination=calendarId_record.execute())

            if str(sheet.row_values(j)[18]) == "Democalender":
                updated_event = service.events().move(
                    calendarId=calendarId_surgeries,
                    eventId='eventId',
                    destination=calendarId_record.execute())

        elif str(sheet.row_values(j)[15]) == "no" and str(
                sheet.row_values(j)[18]) == "Important":
            event = service.events().insert(calendarId=calendarId_important,
                                            body=event1).execute()
            print('Event created: %s' % (event.get('htmlLink')))
            event_id = print(event.get('id'))
            time.sleep(1)
            sheet.update_cell(j, 20, event.get('htmlLink'))
            sheet.update_cell(j, 21, event.get('id'))
            # Print the updated date.

        elif str(sheet.row_values(j)[15]) == "no" and str(
                sheet.row_values(j)[18]) == "Democalender":
            event = service.events().insert(calendarId=calendarId_surgeries,
                                            body=event1).execute()
            print('Event created: %s' % (event.get('htmlLink')))
            event_id = print(event.get('id'))
            time.sleep(1)
            sheet.update_cell(j, 20, event.get('htmlLink'))
            sheet.update_cell(j, 21, event.get('id'))
            # Print the updated date.

        else:
            print("What is wrongs")