Spaces:
Sleeping
Sleeping
Update google_sheet_Legend.py
Browse files- google_sheet_Legend.py +21 -28
google_sheet_Legend.py
CHANGED
|
@@ -73,7 +73,7 @@ def update_sheet(spreadsheetId, SimilarAreaDictionary, 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
|
| 77 |
return
|
| 78 |
|
| 79 |
else:
|
|
@@ -685,7 +685,9 @@ def deletefromlegend(deletedrows, SimilarAreaDictionarycopy, section, areaPermAr
|
|
| 685 |
return SimilarAreaDictionarycopy
|
| 686 |
|
| 687 |
#########################
|
| 688 |
-
def DoorsLegend(Dictionary,spreadsheetId
|
|
|
|
|
|
|
| 689 |
top_header_format = [
|
| 690 |
{'mergeCells': { # legend and data created
|
| 691 |
'mergeType': 'MERGE_ROWS',
|
|
@@ -698,10 +700,11 @@ def DoorsLegend(Dictionary,spreadsheetId,worksheet):
|
|
| 698 |
}
|
| 699 |
}}
|
| 700 |
]
|
| 701 |
-
|
| 702 |
-
|
| 703 |
-
|
| 704 |
-
|
|
|
|
| 705 |
body2={
|
| 706 |
"requests": [
|
| 707 |
{
|
|
@@ -771,48 +774,38 @@ def DoorsLegend(Dictionary,spreadsheetId,worksheet):
|
|
| 771 |
}
|
| 772 |
]
|
| 773 |
}
|
| 774 |
-
|
| 775 |
-
|
|
|
|
| 776 |
model_cell.set_text_format('bold', True)
|
| 777 |
model_cell.set_horizontal_alignment(pygsheets.custom_types.HorizontalAlignment.CENTER)
|
| 778 |
model_cell.color = (213 / 255, 219 / 255, 255 / 255)
|
| 779 |
-
pygsheets.DataRange('A2', 'B2', worksheet=
|
|
|
|
|
|
|
| 780 |
#########################
|
| 781 |
|
| 782 |
-
def
|
| 783 |
|
| 784 |
items=[]
|
| 785 |
-
# print('
|
| 786 |
idx=0
|
| 787 |
myDict=eval(dictionary)
|
| 788 |
df_doors=pd.DataFrame(myDict)
|
| 789 |
-
# deletedrows=eval(deletedrows)
|
| 790 |
strings=deletedrows['content']
|
|
|
|
| 791 |
for item in strings:
|
| 792 |
newitem=str(item).split('\n \n')
|
| 793 |
-
if '
|
| 794 |
current_value = df_doors.loc[df_doors['Type'] == 'Single Doors', 'Quantity'].values[0]
|
| 795 |
-
|
| 796 |
-
# Step 2: Subtract one from the current value
|
| 797 |
new_value = int(current_value) - 1
|
| 798 |
-
|
| 799 |
-
# Step 3: Update the DataFrame with the new value
|
| 800 |
df_doors.loc[df_doors['Type'] == 'Single Doors', 'Quantity'] = str(new_value)
|
| 801 |
-
|
| 802 |
-
# Print the updated DataFrame to verify the change
|
| 803 |
-
# print(df_doors)
|
| 804 |
-
elif 'double' in str(newitem):
|
| 805 |
current_value = df_doors.loc[df_doors['Type'] == 'Double Doors', 'Quantity'].values[0]
|
| 806 |
-
# print(current_value)
|
| 807 |
-
# Step 2: Subtract one from the current value
|
| 808 |
new_value = int(current_value) - 1
|
| 809 |
-
# print(new_value)
|
| 810 |
-
# Step 3: Update the DataFrame with the new value
|
| 811 |
df_doors.loc[df_doors['Type'] == 'Double Doors', 'Quantity'] = str(new_value)
|
| 812 |
-
|
| 813 |
-
# Print the updated DataFrame to verify the change
|
| 814 |
-
# print(df_doors)
|
| 815 |
df_doors = df_doors[['Type', 'Quantity']]
|
|
|
|
| 816 |
return df_doors
|
| 817 |
|
| 818 |
#########################
|
|
|
|
| 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)
|
| 77 |
return
|
| 78 |
|
| 79 |
else:
|
|
|
|
| 685 |
return SimilarAreaDictionarycopy
|
| 686 |
|
| 687 |
#########################
|
| 688 |
+
def DoorsLegend(Dictionary,spreadsheetId):
|
| 689 |
+
global worksheetw
|
| 690 |
+
worksheetw.clear()
|
| 691 |
top_header_format = [
|
| 692 |
{'mergeCells': { # legend and data created
|
| 693 |
'mergeType': 'MERGE_ROWS',
|
|
|
|
| 700 |
}
|
| 701 |
}}
|
| 702 |
]
|
| 703 |
+
print('here')
|
| 704 |
+
# spreadsheet_service.spreadsheets().batchUpdate(spreadsheetId=spreadsheetId, body={'requests': top_header_format}).execute()
|
| 705 |
+
worksheetw.cell((1, 1)).value = 'Legend and Data Created'
|
| 706 |
+
worksheetw.set_dataframe(start='A2', df=Dictionary)
|
| 707 |
+
print('here1')
|
| 708 |
body2={
|
| 709 |
"requests": [
|
| 710 |
{
|
|
|
|
| 774 |
}
|
| 775 |
]
|
| 776 |
}
|
| 777 |
+
print('here2')
|
| 778 |
+
# spreadsheet_service.spreadsheets().batchUpdate(spreadsheetId=spreadsheetId, body=body2).execute()
|
| 779 |
+
model_cell = worksheetw.cell('A1')
|
| 780 |
model_cell.set_text_format('bold', True)
|
| 781 |
model_cell.set_horizontal_alignment(pygsheets.custom_types.HorizontalAlignment.CENTER)
|
| 782 |
model_cell.color = (213 / 255, 219 / 255, 255 / 255)
|
| 783 |
+
pygsheets.DataRange('A2', 'B2', worksheet=worksheetw).apply_format(model_cell)
|
| 784 |
+
print('here3')
|
| 785 |
+
return Dictionary
|
| 786 |
#########################
|
| 787 |
|
| 788 |
+
def deletedoors(deletedrows,dictionary):
|
| 789 |
|
| 790 |
items=[]
|
| 791 |
+
# print('dletefromlegend2.8')
|
| 792 |
idx=0
|
| 793 |
myDict=eval(dictionary)
|
| 794 |
df_doors=pd.DataFrame(myDict)
|
|
|
|
| 795 |
strings=deletedrows['content']
|
| 796 |
+
print('strings',strings)
|
| 797 |
for item in strings:
|
| 798 |
newitem=str(item).split('\n \n')
|
| 799 |
+
if 'Single' in str(newitem):
|
| 800 |
current_value = df_doors.loc[df_doors['Type'] == 'Single Doors', 'Quantity'].values[0]
|
|
|
|
|
|
|
| 801 |
new_value = int(current_value) - 1
|
|
|
|
|
|
|
| 802 |
df_doors.loc[df_doors['Type'] == 'Single Doors', 'Quantity'] = str(new_value)
|
| 803 |
+
elif 'Double' in str(newitem):
|
|
|
|
|
|
|
|
|
|
| 804 |
current_value = df_doors.loc[df_doors['Type'] == 'Double Doors', 'Quantity'].values[0]
|
|
|
|
|
|
|
| 805 |
new_value = int(current_value) - 1
|
|
|
|
|
|
|
| 806 |
df_doors.loc[df_doors['Type'] == 'Double Doors', 'Quantity'] = str(new_value)
|
|
|
|
|
|
|
|
|
|
| 807 |
df_doors = df_doors[['Type', 'Quantity']]
|
| 808 |
+
print(df_doors)
|
| 809 |
return df_doors
|
| 810 |
|
| 811 |
#########################
|