storage api added
diff --git a/make_report.py b/make_report.py
index 96bb622..0dd363d 100644
--- a/make_report.py
+++ b/make_report.py
@@ -19,7 +19,7 @@
work_sheet = sheet.worksheet(name)
except WorksheetNotFound:
work_sheet = sheet.add_worksheet(title=name, rows=ROW_COUNT,
- cols=len(column_names))
+ 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])
@@ -48,18 +48,30 @@
i += 1
-def make_report(data):
- gc = gspread.login(EMAIL, PASSWORD)
+def make_report(email, password, data):
+ gc = gspread.login(email, password)
sh = gc.open_by_key(DOCUMENT_ID)
work_sheet = get_work_sheet(sh, WORK_SHEET, data.keys())
append_row(work_sheet, data)
+def main(file_name, email, password):
+ data = load_data(file_name)
+ make_report(email, password, data)
+
+
if __name__ == '__main__':
parser = argparse.ArgumentParser()
parser.add_argument('-n', '--name', help='data file path',
default=DEFAULT_FILE_PATH)
+ parser.add_argument('-e', '--email', help='user email',
+ default="aaa@gmail.com")
+ 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)
results = parser.parse_args()
- data = load_data(results.name)
- make_report(data)
+ print results
+ # main(file_name, email, password)
+
diff --git a/storage_api.py b/storage_api.py
new file mode 100644
index 0000000..2b571dd
--- /dev/null
+++ b/storage_api.py
@@ -0,0 +1,49 @@
+import gspread
+from config import EMAIL, PASSWORD, DOCUMENT_ID, WORK_SHEET
+from make_report import get_work_sheet, append_row
+
+
+class Measurement(object):
+ def __init__(self):
+ self.build = ""
+ self.build_type = 0 # GA/Master/Other
+ self.md5 = ""
+ self.results = {
+ "": (float, float)
+ }
+
+
+class Storage(object):
+
+ def __init__(self, email, password, doc_id, work_sheet_name):
+ self.gc = gspread.login(email, password)
+ self.sh = self.gc.open_by_key(doc_id)
+ self.work_sheet = get_work_sheet(self.sh, work_sheet_name, 40)
+
+ def store(self, data):
+ append_row(self.work_sheet, data)
+
+ def retrieve(self, id):
+ row_number = self.find_by_id(id)
+
+ if row_number != -1:
+ vals = self.work_sheet.row_values(row_number)
+ m = Measurement()
+ m.build = vals["build_id"]
+ del vals["build_id"]
+ m.build_type = vals["type"]
+ del vals["type"]
+ m.md5 = vals["iso_md5"]
+ del vals["iso_md5"]
+ m.results = {k: vals[k] for k in vals.keys()}
+ else:
+ return None
+
+ def find_by_id(self, row_id):
+ for i in range(1, self.work_sheet):
+ if self.work_sheet.cell(i, 1) == row_id:
+ return i
+
+ return -1
+
+