0 points

upload data to google sheets


PHOTO EMBED

Fri Dec 04 2020 08:43:27 GMT+0000 (UTC)

Saved by @keypressingmonkey #python

import gspread
from oauth2client.service_account import ServiceAccountCredentials
from datetime import date

def upload_stat_data_to_google_sheets(email, posts_in_queue, followers):
	scope = ["https://spreadsheets.google.com/feeds", 'https://www.googleapis.com/auth/spreadsheets',
		"https://www.googleapis.com/auth/drive.file", "https://www.googleapis.com/auth/drive"]

	creds = ServiceAccountCredentials.from_json_keyfile_name(
		os.path.join(os.getcwd(), 'stat_scraper',"google_cloud_credentials.json"), scope)

	client = gspread.authorize(creds)

	sheet = client.open("automation_stats").sheet1
	analytics = client.open("automation_stats").worksheet("analytics")
	data = sheet.get_all_records()
	current_date = date.today().strftime('%d.%m.%y')
	row_to_insert = [[current_date, email, posts_in_queue, followers]]	
	sheet.append_rows(row_to_insert)
content_copyCOPY