def send_email(email_address): """Sends email to the 'email_address' parameter. This email will have the two books attached to it.""" print(email_address, 'wants the books!') logging.basicConfig(filename='Bot.log', format='%(name)s : %(levelname)s : %(message)s', level=logging.INFO) logging.info('\n\n\n\n\n{} : {}'.format(datetime.today().replace(microsecond=0), email_address)) CLIENT_SECRET_FILE = "credentials.json" API_NAME = 'gmail' API_VERSION = 'v1' SCOPES = ['https://mail.google.com/'] service = create_service(CLIENT_SECRET_FILE, API_NAME, API_VERSION, SCOPES) emailMsg = (make_message()) mimeMessage = MIMEMultipart() mimeMessage['to'] = email_address mimeMessage['subject'] = 'Books' mimeMessage.attach(MIMEText(emailMsg, 'plain')) raw_string = base64.urlsafe_b64encode(mimeMessage.as_bytes()).decode() message = service.users().messages().send( userId='me', body={'raw': raw_string}).execute() print(message) print(email_address, 'has received the books.')
def youtube_upload(): scopes = ['https://www.googleapis.com/auth/youtube.upload'] service = create_service(YOUTUBE_CLIENT_SECRET_FILE, 'youtube', 'v3', scopes) request_body = { 'snippet': { 'title': 'Demo | Automated Among Us Twitch Clips', 'description': 'Demo Automated Twitch Clips to Youtube' }, 'status': { 'privacyStatus': 'unlisted' }, 'notifySubscribers': False } mediaFile = MediaFileUpload('final.mp4') response_upload = service.videos().insert( part='snippet,status', body=request_body, media_body=mediaFile ).execute() print(response_upload)
def sheet_to_dataframe(self, verbose=False): s = create_service(self.CLIENT_SECRET_FILE, self.API_SERVICE_NAME, self.API_VERSION, self.SCOPES) gs = s.spreadsheets() rows = gs.values().get(spreadsheetId=self.gsheetId, range=self.sheet_range).execute() data = rows.get("values") df = pd.DataFrame(data) if verbose: print(df) return df
#!/usr/bin/env python3 from Google import create_service from credentials import credentials import pandas as pd #download secret file after authorizing O2Auth from console.cloud.google.com #must be in the same directory as this file CLIENT_SECRET_FILE = credentials["Google Secret File"] #can rename this file API_SERVICE_NAME = "sheets" API_VERSION = "v4" SCOPES = ["https://www.googleapis.com/auth/spreadsheets.readonly"] gsheetId = credentials["gsheetId"] s = create_service(CLIENT_SECRET_FILE, API_SERVICE_NAME, API_VERSION, SCOPES) gs = s.spreadsheets() rows = gs.values().get(spreadsheetId=gsheetId, range="7.20").execute() data = rows.get("values") df = pd.DataFrame(data) print(df)
def connect_to_api(): service = create_service(CLIENT_SECRET_FILE, API_NAME, API_VERSION, SCOPES) return service
wb = xlapp.Workbooks.Open(EXCEL_FILE) if wb is not None: print('Reading Excel File') wb.RefreshAll ws = wb.Sheets(WORKSHEET_NAME) range_value = ws.Range(EXCEL_CELL_NAME).CurrentRegion() ws = None wb = None xlapp = None print('Converting to json') range_value = json.dumps(range_value, default=dateconverter) # create a service for google print('Creating Service for Google Sheets') service = create_service(IP_ADDR, PORT_NO, CLIENT_SECRET_FILE, API_NAME, API_VERSION, SCOPES) # if service is not none if service is not None: try: print('Clearing Google Sheet') # connect with google sheets. response = service.spreadsheets().values().clear( spreadsheetId = GSPREADSHEETS_ID, range = SHEETS_NAME ).execute() print('Appending Data to Google Sheet') response = service.spreadsheets().values().append( spreadsheetId = GSPREADSHEETS_ID, valueInputOption = "RAW", range = SHEETS_NAME + "!" +SHEETS_CELL_NAME,