Marthee commited on
Commit
5ca2df1
·
verified ·
1 Parent(s): 4440760

Update google_sheet_Legend.py

Browse files
Files changed (1) hide show
  1. google_sheet_Legend.py +16 -7
google_sheet_Legend.py CHANGED
@@ -61,7 +61,7 @@ def create_new_sheet(path):
61
  return spreadsheetId
62
 
63
  #########################
64
- def update_sheet(spreadsheetId, SimilarAreaDictionary, pdfpath):
65
  ws = gc.open_by_key(spreadsheetId)
66
  global pdfpath0
67
  pdfpath0=pdfpath
@@ -69,8 +69,14 @@ def update_sheet(spreadsheetId, SimilarAreaDictionary, pdfpath):
69
  worksheet.title = 'Legend and data created'
70
  worksheet.clear()
71
  ws.create_developer_metadata('path', pdfpath)
72
- splittedpdfpath = re.split(r'[`\-=~!@#$%^&*()_+\[\]{};\'\\:"|<,/<>?]', pdfpath)
73
- if splittedpdfpath[-2].startswith('2.2') or splittedpdfpath[-2].startswith('2.1'):
 
 
 
 
 
 
74
  worksheet.set_dataframe(start='A1', df=SimilarAreaDictionary)
75
  # if splittedpdfpath[-2].startswith('2.8'):
76
  # DoorsLegend(SimilarAreaDictionary,spreadsheetId)
@@ -143,12 +149,12 @@ def update_sheet(spreadsheetId, SimilarAreaDictionary, pdfpath):
143
  worksheet.update_col(10, list(SimilarAreaDictionary['Texts']), row_offset=3)
144
  worksheet.update_col(11, list(SimilarAreaDictionary['Comments']), row_offset=3)
145
 
146
- if splittedpdfpath[-2].startswith('1.0'):
147
  colorsUsed = [
148
  [SimilarAreaDictionary['R'].iloc[i], SimilarAreaDictionary['G'].iloc[i], SimilarAreaDictionary['B'].iloc[i]]
149
  for i in range(len(SimilarAreaDictionary))
150
  ]
151
- elif splittedpdfpath[-2].startswith('3.2') or splittedpdfpath[-2].startswith('3.3') or splittedpdfpath[-2].startswith('2.7'):
152
  colorsUsed = list(SimilarAreaDictionary['Color'])
153
  rowsLen = len(SimilarAreaDictionary.values.tolist())
154
  lastcell = worksheet.cell((rowsLen + 2, 1))
@@ -265,7 +271,7 @@ def update_sheet(spreadsheetId, SimilarAreaDictionary, pdfpath):
265
  pygsheets.DataRange('A2', 'K2', worksheet=worksheet).apply_format(model_cell)
266
 
267
  #########################
268
- def legendGoogleSheets(SimilarAreaDictionary, path, pdfpath, spreadsheetId=0):
269
  titles = gc.spreadsheet_titles()
270
  if path in titles:
271
  ws = gc.open(path)
@@ -277,7 +283,10 @@ def legendGoogleSheets(SimilarAreaDictionary, path, pdfpath, spreadsheetId=0):
277
  ws=gc.open_by_key(spreadsheetId)
278
  global worksheetw
279
  worksheetw = ws.worksheet(0) #legend
280
- update_sheet(spreadsheetId, SimilarAreaDictionary, pdfpath)
 
 
 
281
  spreadsheet_url = f"https://docs.google.com/spreadsheets/d/{spreadsheetId}"
282
  drive_service.permissions().update(transferOwnership=True, fileId=spreadsheetId, permissionId='11OfoB4Z6wOVII8mYmbnCbbqTQs7rYA65')
283
 
 
61
  return spreadsheetId
62
 
63
  #########################
64
+ def update_sheet(spreadsheetId, SimilarAreaDictionary, pdfpath,pdf_content=0):
65
  ws = gc.open_by_key(spreadsheetId)
66
  global pdfpath0
67
  pdfpath0=pdfpath
 
69
  worksheet.title = 'Legend and data created'
70
  worksheet.clear()
71
  ws.create_developer_metadata('path', pdfpath)
72
+
73
+ if pdf_content:
74
+ splittedpdfpath = re.split(r'[`\-=~!@#$%^&*()_+\[\]{};\'\\:"|<,/<>?]', pdfpath)
75
+ section=splittedpdfpath[-2]
76
+ else:
77
+ section=pdfpath
78
+ print(section)
79
+ if section.startswith('2.2') or section.startswith('2.1'):
80
  worksheet.set_dataframe(start='A1', df=SimilarAreaDictionary)
81
  # if splittedpdfpath[-2].startswith('2.8'):
82
  # DoorsLegend(SimilarAreaDictionary,spreadsheetId)
 
149
  worksheet.update_col(10, list(SimilarAreaDictionary['Texts']), row_offset=3)
150
  worksheet.update_col(11, list(SimilarAreaDictionary['Comments']), row_offset=3)
151
 
152
+ if section.startswith('1.0'):
153
  colorsUsed = [
154
  [SimilarAreaDictionary['R'].iloc[i], SimilarAreaDictionary['G'].iloc[i], SimilarAreaDictionary['B'].iloc[i]]
155
  for i in range(len(SimilarAreaDictionary))
156
  ]
157
+ else:#if section.startswith('3.2') or section.startswith('3.3') or section.startswith('2.7'):
158
  colorsUsed = list(SimilarAreaDictionary['Color'])
159
  rowsLen = len(SimilarAreaDictionary.values.tolist())
160
  lastcell = worksheet.cell((rowsLen + 2, 1))
 
271
  pygsheets.DataRange('A2', 'K2', worksheet=worksheet).apply_format(model_cell)
272
 
273
  #########################
274
+ def legendGoogleSheets(SimilarAreaDictionary, path, pdfpath, spreadsheetId=0,pdf_content=0):
275
  titles = gc.spreadsheet_titles()
276
  if path in titles:
277
  ws = gc.open(path)
 
283
  ws=gc.open_by_key(spreadsheetId)
284
  global worksheetw
285
  worksheetw = ws.worksheet(0) #legend
286
+ if pdf_content:
287
+ update_sheet(spreadsheetId, SimilarAreaDictionary, pdfpath,pdf_content)
288
+ else:
289
+ update_sheet(spreadsheetId, SimilarAreaDictionary, pdfpath)
290
  spreadsheet_url = f"https://docs.google.com/spreadsheets/d/{spreadsheetId}"
291
  drive_service.permissions().update(transferOwnership=True, fileId=spreadsheetId, permissionId='11OfoB4Z6wOVII8mYmbnCbbqTQs7rYA65')
292