from flask import abort, request, render_template, url_for, jsonify from webApp import * from webApp import webApp import gspread from oauth2client.service_account import ServiceAccountCredentials import json import datetime from config import config # Авторизация Google API def authorize_google(): # google_json = {} # for key in config["GOOGLE"].keys(): # google_json[key] = config["GOOGLE"][key] scope = ["https://spreadsheets.google.com/feeds", "https://www.googleapis.com/auth/drive"] creds = ServiceAccountCredentials.from_json_keyfile_name("botforclinic-436512-0c117dd103a8.json", scope) # creds = ServiceAccountCredentials.from_json_keyfile_dict(google_json, scope) client = gspread.authorize(creds) return client # Обработка формы @webApp.route('/form_submit', methods=['POST']) def form_submit(): data = json.loads(request.data) # {'fio': '', 'tel': '', 'email': '', 'passport': '', 'passport_date': '', 'postal_code': '', 'address': '', 'snils': '', 'inn': '', 'dob': ''} data['current_time'] = datetime.datetime.now().strftime("%d.%m.%Y, %H:%M") print(data) # Авторизация и добавление данных в Google Sheets sheet = authorize_google().open("Информация о сотрудниках").sheet1 sheet.append_row([ data['fio'], data['tel'], data['email'], data['passport'][:4], data['passport'][4:], data['passport_issued_by'], data['passport_date'], data['postal_code'], data['address'], data['snils'], data['inn'], data['dob'], data['user_id'], # Записываем Telegram ID пользователя data['current_time'] # Записываем время отправки данных ]) return jsonify({'success':True}) @webApp.route('/') def main_page_2_0(): return render_template('2.0/main_page.pug', user_id=request.args.get('user_id', None))