• 游戏公司经常看到策划修改配置表的时候各种冲突,各种饮用到老的文件,还有在导出到游戏引擎的时候与配置表内的内容不一致,差不多两年前意识到这个问题的时候策划们的解决方案差不多就几个,分人头每人负责几个表,有交叉的地方用svn的lock功能,为了保证同步就给配置表放在svn里面,用log去表示当前内容的版本与客户端是否一致。
  • 我个人认为之所以大家这样用,是因为暂时可以规避掉互相冲突的问题,也可能是因为公司策划内可修改配置文件的人不够多,没有碰到过灾难,大不了删掉重新导。
  • 还有一个方向觉得这是个问题的就是在持续集成构建包的时候,外网的某些继承模块拿不到内网的svn数据,导致得自己手动写shell去移动进客户端和服务器工程中,然后再去测试是否一致。
  • 当时想到的就是最好的情况就是实时修改数据,实时同步到所有的策划的显示器上,在打包的时候策划和程序不需要动手,直接从外网的数据源拉取,转换格式,放进包中,服务器也一样。当时找到的方案就是google doc/sheets,当时的实时程度是废了半天的劲找朋友给他装翻墙软件来测试,实时程度是被惊叹了,国内当时有个叫石墨文档的也做同样的内容,刚刚创业起步,做的不是很好,今天想到可以试试去拉取google sheets的内容去paser试试,就做了这么个玩意,最大的问题就是google的凭据认证的过程,有网络的影响,有权限,还有大小写的影响,最后都解决掉了,一条python命令可以拿到表格中的一列内容。
  • 其中依赖两个py的库分别是,oauth2client,google-api-python-client
  • 虽然我认为完全外网的开发环境和协作的方式很好,很多人也觉得不错,但是每人会用,大部分还是因为不安全,和稳定性,他们认为内网最安全,最稳定,毕竟可以拔网线。

035D572C-D5D6-41FC-A51D-E21CA5644426.png

AD2C2E62-F707-42D7-871F-07051915FF07.png

from __future__ import print_function
import httplib2
import os

from apiclient import discovery
from oauth2client import client
from oauth2client import tools
from oauth2client.file import Storage

try:
    import argparse
    flags = argparse.ArgumentParser(parents=[tools.argparser]).parse_args()
except ImportError:
    flags = None

# If modifying these scopes, delete your previously saved credentials
# at ~/.credentials/sheets.googleapis.com-python-quickstart.json
SCOPES = 'https://www.googleapis.com/auth/spreadsheets.readonly'
CLIENT_SECRET_FILE = 'client_secret.json'
APPLICATION_NAME = 'Google Sheets API Python Quickstart'


def get_credentials():
    """Gets valid user credentials from storage.

    If nothing has been stored, or if the stored credentials are invalid,
    the OAuth2 flow is completed to obtain the new credentials.

    Returns:
        Credentials, the obtained credential.
    """
    home_dir = os.path.expanduser('~')
    credential_dir = os.path.join(home_dir, '.credentials')
    if not os.path.exists(credential_dir):
        os.makedirs(credential_dir)
    credential_path = os.path.join(credential_dir,
                                   'sheets.googleapis.com-python-quickstart.json')
    print("client_secret path = ",credential_path)
    store = Storage(credential_path)
    credentials = store.get()
    if not credentials or credentials.invalid:
        flow = client.flow_from_clientsecrets(CLIENT_SECRET_FILE, SCOPES)
        flow.user_agent = APPLICATION_NAME
        if flags:
            credentials = tools.run_flow(flow, store, flags)
        else: # Needed only for compatibility with Python 2.6
            credentials = tools.run(flow, store)
        print('Storing credentials to ' + credential_path)
    return credentials

def main():
    """Shows basic usage of the Sheets API.

    Creates a Sheets API service object and prints the names and majors of
    students in a sample spreadsheet:
    https://docs.google.com/spreadsheets/d/1sEkLLL5kCKWkQQAoQW2Pxy0uh7jXmRTFIrTSr0NmNK4/edit
    """
    credentials = get_credentials()
    http = credentials.authorize(httplib2.Http())
    discoveryUrl = ('https://sheets.googleapis.com/$discovery/rest?'
                    'version=v4')
    service = discovery.build('sheets', 'v4', http=http,
                              discoveryServiceUrl=discoveryUrl)

    spreadsheetId = '1sEkLLL5kCKWkQQAoQW2Pxy0uh7jXmRTFIrTSr0NmNK4'
    rangeName = 'test!A:A'
    result = service.spreadsheets().values().get(
        spreadsheetId=spreadsheetId, range=rangeName).execute()
    values = result.get('values', [])

    if not values:
        print('No data found.')
    else:
        print('B Cloumns:')
        for row in values:
            # Print columns A and E, which correspond to indices 0 and 4.
            if row[0]:
                print('%s' % (row[0]))


if __name__ == '__main__':
    main()

标签: none

添加新评论