local storage and google docs finished
diff --git a/make_report.py b/make_report.py
index 0dd363d..eb99ae8 100644
--- a/make_report.py
+++ b/make_report.py
@@ -2,9 +2,9 @@
import argparse
import json
-from config import DEFAULT_FILE_PATH, PASSWORD, EMAIL, \
- WORK_SHEET, DOCUMENT_ID, ROW_COUNT
-from gspread.exceptions import WorksheetNotFound
+from config import DEFAULT_FILE_PATH, \
+ WORK_SHEET, DOCUMENT_ID, ROW_COUNT, OUTPUT_FILE
+from storage_api import DiskStorage, GoogleDocsStorage, get_work_sheet, append_row
def load_data(file_name):
@@ -14,39 +14,6 @@
#getting worksheet from sheet or create it with specified column names.
-def get_work_sheet(sheet, name, column_names):
- try:
- work_sheet = sheet.worksheet(name)
- except WorksheetNotFound:
- work_sheet = sheet.add_worksheet(title=name, rows=ROW_COUNT,
- cols=max(40, len(column_names)))
-
- for i in range(1, len(column_names) + 1):
- work_sheet.update_cell(1, i, column_names[i - 1])
-
- return work_sheet
-
-
-def get_row_number(work_sheet):
- num = 2
-
- while num < work_sheet.row_count and work_sheet.cell(num, 1).value != "":
- num += 1
-
- if num == work_sheet.row_count:
- work_sheet.append_row(["" for x in range(work_sheet.col_count)])
-
- return num
-
-
-def append_row(work_sheet, row):
- row_number = get_row_number(work_sheet)
-
- i = 1
- for k in row.keys():
- work_sheet.update_cell(row_number, i, row[k])
- i += 1
-
def make_report(email, password, data):
gc = gspread.login(email, password)
@@ -56,9 +23,15 @@
append_row(work_sheet, data)
-def main(file_name, email, password):
+def main(file_name, email, password, mode):
data = load_data(file_name)
- make_report(email, password, data)
+
+ if mode == 'local':
+ storage = DiskStorage(OUTPUT_FILE)
+ else:
+ storage = GoogleDocsStorage(DOCUMENT_ID, WORK_SHEET, email, password)
+
+ storage.store(data)
if __name__ == '__main__':
@@ -70,8 +43,7 @@
parser.add_argument('-p', '--password', help='user password',
default="1234")
parser.add_argument('-m', '--mode', help='mode type local or global',
- default=DEFAULT_FILE_PATH)
+ default='local')
results = parser.parse_args()
- print results
- # main(file_name, email, password)
+ main(results.name, results.email, results.password, results.mode)