Индексирование листа Google из другого файла Python возвращает «нет», однако в ячейке есть данные - PullRequest
0 голосов
/ 30 марта 2019

Я определил две функции в leaderboard.py, insertData (xpos, ypos, data) и indexThing (строка, столбец). Хотя я могу вставить данные с помощью функции вставки данных, я не могу индексировать значения в server.py. Я попытался индексировать непосредственно в server.py с установленными значениями, и я все еще получил «Нет». Как я могу решить эту проблему?

server.py:

from flask import Flask, request, render_template
import leaderboard
app = Flask(__name__)

@app.route("/script", methods=['POST'])
def script():
    input_string = request.form['data']
    chose = input_string[:-4]
    chose = chose.replace('http://10.0.1.36:5000/static/images/Girls/', 'G')
    chose = chose.replace('http://10.0.1.36:5000/static/images/Boys/', 'B')

    print (leaderboard.indexThing(22,3)) ##THIS RETURNS NONE  

    if 'G' in chose:
        chose = int(chose[1:len(chose)])
        print chose
        total = leaderboard.indexThing(chose, 3)
        wins = leaderboard.indexThing(chose, 4)
        print wins ##THIS RETURNS NONE 
        print total ##THIS RETURNS NONE 
    elif 'B' in chose:
        chose = int(chose[1:len(chose)])
        print chose
        total = leaderboard.indexThing(chose, 12)
        wins = leaderboard.indexThing(chose, 13)
        print wins ##THIS RETURNS NONE 
        print total ##THIS RETURNS NONE 
    return "backend response"

@app.route('/')
def static_page():
    return render_template('index.html')

@app.route('/boys.html')
def static_page2():
    return render_template('boys.html')

@app.route('/girls.html')
def static_page3():
    return render_template('girls.html')

if __name__ == "__main__":
    app.run(host='10.0.1.36', port=5000, debug=True)

leaderboard.py

#coding=utf-8
import gspread
from oauth2client.service_account import ServiceAccountCredentials
scope = ['https://spreadsheets.google.com/feeds', 'https://www.googleapis.com/auth/drive']
creds = ServiceAccountCredentials.from_json_keyfile_name('static/client_secret.json', scope)
client = gspread.authorize(creds)
sheet = client.open('Rate data').sheet1

def insertData(xpos, ypos, data):
    sheet.update_cell(xpos, ypos, data)

def indexThing(row, column):
    sheet.cell(row, column).value

1 Ответ

0 голосов
/ 30 марта 2019

Убедитесь, что все типы во всех различных функциях Python согласованы.То же самое для листов Google.

Например, для этой строки я бы попробовал;

sheet.cell(int(row), (int)column).value

Также убедитесь, что вы действительно получаете возвращаемое значение из вызова sheet.cell.Например, что это за тип

sheet.cell(int(row), (int)column)

Это то, что вы ожидаете?

...