gstepanov | 5efd15a | 2015-01-29 17:26:24 +0200 | [diff] [blame^] | 1 | import gspread |
| 2 | import argparse |
| 3 | import json |
| 4 | |
| 5 | from config import DEFAULT_FILE_PATH, PASSWORD, EMAIL, COL_COUNT, WORK_SHEET, DOCUMENT_ID |
| 6 | |
| 7 | |
| 8 | def load_data(file_name): |
| 9 | with open(file_name) as f: |
| 10 | data = f.read() |
| 11 | return json.loads(data) |
| 12 | |
| 13 | |
| 14 | def 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 | |
| 26 | if __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) |