Exemplo n.º 1
0
def run():
	scope = ['https://spreadsheets.google.com/feeds', 'https://www.googleapis.com/auth/drive']
	secret_file = get_simple_path('client_secret.json')
	creds = ServiceAccountCredentials.from_json_keyfile_name(secret_file, scope)
	gc = gspread.authorize(creds)
	spreadsheet = gc.open_by_key(config['gforms_spreadsheet_id'])
	all_data = spreadsheet.get_worksheet(1).get_all_records()
	for row in all_data:
		entry = parse_entry_from_form(row)
		handle_entry(gc, entry)
Exemplo n.º 2
0
def authorize(secret_file_path):
    scope = [
        "https://spreadsheets.google.com/feeds",
        "https://www.googleapis.com/auth/drive",
    ]
    secret_file = get_simple_path(secret_file_path)
    creds = ServiceAccountCredentials.from_json_keyfile_name(
        secret_file, scope)
    gc = gspread.authorize(creds)
    return gc
Exemplo n.º 3
0
def read_config():
	filepath = get_simple_path('config.txt')
	with open(filepath, encoding = 'utf-8') as file:
		lines = file.read().splitlines()

	conf = {}
	for line in lines:
		split = line.split("=")
		assert(len(split) == 2)
		conf[split[0]] = split[1]
	return conf
Exemplo n.º 4
0
def run(entry_dict, spreadsheet, should_set_readonly_ranges, config):
    scope = [
        "https://spreadsheets.google.com/feeds",
        "https://www.googleapis.com/auth/drive",
    ]
    secret_file = get_simple_path("client_secret.json")
    creds = ServiceAccountCredentials.from_json_keyfile_name(secret_file, scope)
    gc = gspread.authorize(creds)
    worksheet0 = spreadsheet.get_worksheet(0)
    if len(spreadsheet.worksheets()) <= 1:
        worksheet1 = spreadsheet.add_worksheet("Cenovky", 100, 100)
    prefill_worksheet0(worksheet0, entry_dict, should_set_readonly_ranges, config)
Exemplo n.º 5
0
def run():
    scope = [
        'https://spreadsheets.google.com/feeds',
        'https://www.googleapis.com/auth/drive'
    ]
    secret_file = get_simple_path('client_secret_collector.json')
    creds = ServiceAccountCredentials.from_json_keyfile_name(
        secret_file, scope)
    gc = gspread.authorize(creds)
    spreadsheet = gc.open_by_key(config['gforms_spreadsheet_id'])
    worksheet = spreadsheet.get_worksheet(1)
    form_data = worksheet.get_all_records()
    global_spreadsheet_name = 'Global Export Pohoda'
    try:
        global_spreadsheet = gc.open(global_spreadsheet_name)
        print('Global spreadsheet already created, continuing...')
    except gspread.exceptions.SpreadsheetNotFound:
        print('Creating global spreadsheet')
        global_spreadsheet = gc.create(global_spreadsheet_name)
        global_spreadsheet.share(config['admin_gmail'],
                                 perm_type='user',
                                 role='owner',
                                 notify=False)
    writing_worksheet = global_spreadsheet.get_worksheet(0)
    starting_line = 1
    batches = []
    processed_emails = set()

    # debugging
    # entry = parse_entry_from_form(form_data[0])
    # email = entry['email']
    # starting_line, batch = collect_global_batch(gc, entry, starting_line)
    # batches = batches + batch
    # processed_emails.add(email)
    # return
    # debugging end

    for row in form_data:
        entry = parse_entry_from_form(row)
        email = entry['email']
        if email not in processed_emails:
            starting_line, batch = collect_global_batch(
                gc, entry, starting_line)
            batches = batches + batch
            processed_emails.add(email)
    writing_worksheet.batch_update(batches)