blob: 8a8a0d0eb784d4f9741bfebe2eb662ae6f12e00e [file] [log] [blame]
gstepanov5efd15a2015-01-29 17:26:24 +02001import gspread
2import argparse
3import json
4
5from config import DEFAULT_FILE_PATH, PASSWORD, EMAIL, COL_COUNT, WORK_SHEET, DOCUMENT_ID
6
7
8def load_data(file_name):
9 with open(file_name) as f:
10 data = f.read()
11 return json.loads(data)
12
13
14def make_report(data):
15 gc = gspread.login(EMAIL, PASSWORD)
16 sh = gc.open_by_key(DOCUMENT_ID)
17 worksheet = sh.add_worksheet(title=WORK_SHEET, rows=len(data.keys()), cols=COL_COUNT)
18
19 i = 1
20 for k in data.keys():
21 worksheet.update_cell(i, 1, k)
22 worksheet.update_cell(i, 2, data[k])
23 i += 1
24
25
26if __name__ == '__main__':
27 parser = argparse.ArgumentParser()
28 parser.add_argument('-n', '--name', help='data file path', default=DEFAULT_FILE_PATH)
29 results = parser.parse_args()
30 data = load_data(results.name)
31 make_report(data)