get sheet by id instead of index and dynamic row finding
parent
5dd7070807
commit
b7e12600b6
|
@ -52,29 +52,31 @@
|
||||||
"#51139 Flamara der Drache, Farbe, Himmelblau (Fluoreszierend)",
|
"#51139 Flamara der Drache, Farbe, Himmelblau (Fluoreszierend)",
|
||||||
"#77970 Flamara der Drache, Farbe, Gold (Glänzend)",
|
"#77970 Flamara der Drache, Farbe, Gold (Glänzend)",
|
||||||
"#43356 Flamara der Drache, Farbe, Schwarz",
|
"#43356 Flamara der Drache, Farbe, Schwarz",
|
||||||
"#32974 Finn der Sad Hamster, Stil, Standard",
|
"#32974 Finn der Sad Hamster, Stil, Standard / Weiblich",
|
||||||
"#60798 Finn der Sad Hamster, Stil, Schlüsselanhänger",
|
"#60798 Finn der Sad Hamster, Stil, Schlüsselanhänger / Weiblich",
|
||||||
"#30563 Finn der Sad Hamster, Stil, Groß",
|
"#30563 Finn der Sad Hamster, Stil, Groß / Weiblich",
|
||||||
"#90586 Finn der Sad Hamster, Stil, Standard / Männlich",
|
"#90586 Finn der Sad Hamster, Stil, Standard / Männlich",
|
||||||
"#99560 Finn der Sad Hamster, Stil, Schlüsselanhänger / Männlich",
|
"#99560 Finn der Sad Hamster, Stil, Schlüsselanhänger / Männlich",
|
||||||
"#47364 Finn der Sad Hamster, Stil, Groß / Männlich",
|
"#47364 Finn der Sad Hamster, Stil, Groß / Männlich",
|
||||||
"#93047 Mia das Kätzchen, Farbe, Grau",
|
"#93047 Mia das Kätzchen, Farbe, Grau",
|
||||||
"#86423 Mia das Kätzchen, Farbe, Weiß",
|
"#86423 Mia das Kätzchen, Farbe, Weiß",
|
||||||
|
"#X38764 Mia das Kätzchen, Farbe, Weiß (Schlüsselanhänger)",
|
||||||
"#56083 Hoppel das Häschen, Farbe, Grau",
|
"#56083 Hoppel das Häschen, Farbe, Grau",
|
||||||
"#78693 Elias der Corgi, Farbe, Braun/Weiß",
|
"#78693 Elias der Corgi, Farbe, Braun/Weiß",
|
||||||
"#37335 Axel der Axolotl, Farbe, Pink",
|
"#37335 Axel der Axolotl, Farbe, Pink",
|
||||||
"#26822 Dilo der Delfin, Farbe, Blau/Weiß",
|
"#26822 Dilo der Delfin, Farbe, Blau ➔ Weiß",
|
||||||
"#51665 Einhorn, Farbe, Weiß",
|
"#51665 Sunny das Einhorn, Farbe, Weiß",
|
||||||
"#35717 Phoenix, Farbe, Sonderanfertigung Rosa/Weiß",
|
"#35717 Stella der Phönix, Farbe, Sonderanfertigung Rosa/Weiß",
|
||||||
"#26843 Phoenix, Farbe, Verlauf Lila/Pink",
|
"#26843 Stella der Phönix, Farbe, Verlauf Lila/Pink",
|
||||||
"#74943 Brain der Fuchs, Stil, Standard",
|
"#74943 Brain der Fuchs, Stil, Standard",
|
||||||
"#78071 Weißer Hund, Stil, Weiß"
|
"#78071 Weißer Hund, Stil, Weiß",
|
||||||
|
"#92734 Amigo der Capybara, Farbe, Braun"
|
||||||
]
|
]
|
||||||
}
|
}
|
||||||
]
|
]
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"name": "Gutscheincodes für Bestellung erstellen",
|
"name": "Gutscheincodes für Bestellung erstellen (nur die Bestellnummer ohne #)",
|
||||||
"onFinish": "pause",
|
"onFinish": "pause",
|
||||||
"undoPossible": false,
|
"undoPossible": false,
|
||||||
"repeatPossible": true,
|
"repeatPossible": true,
|
||||||
|
|
|
@ -1,6 +1,7 @@
|
||||||
import gspread
|
import gspread
|
||||||
import json
|
import json
|
||||||
import codecs
|
import codecs
|
||||||
|
import sys
|
||||||
|
|
||||||
|
|
||||||
def add_underscore_at_position(text, position):
|
def add_underscore_at_position(text, position):
|
||||||
|
@ -38,6 +39,7 @@ def update_grouptask_products_list_options(index_json_path, products_list):
|
||||||
data = json.load(json_file)
|
data = json.load(json_file)
|
||||||
|
|
||||||
options_list = []
|
options_list = []
|
||||||
|
|
||||||
for product in products_list:
|
for product in products_list:
|
||||||
# replace _ with " " just for better style in dashboard
|
# replace _ with " " just for better style in dashboard
|
||||||
product_name = product['name'].replace("_", " ")
|
product_name = product['name'].replace("_", " ")
|
||||||
|
@ -55,25 +57,53 @@ def update_grouptask_products_list_options(index_json_path, products_list):
|
||||||
|
|
||||||
|
|
||||||
def google_sheets_products():
|
def google_sheets_products():
|
||||||
gc = gspread.service_account(filename="../../secrets/shinnex-424321-b88b144bc9ef.json")
|
gc = gspread.service_account(
|
||||||
|
filename="../../secrets/shinnex-424321-b88b144bc9ef.json")
|
||||||
|
|
||||||
spreadsheet = gc.open("Produkte")
|
spreadsheet = gc.open_by_key(
|
||||||
|
"1gZkjykb55aLWumBxHxj_ZUq_ktjGK4FlJsH_9qg-ThU")
|
||||||
|
|
||||||
worksheet = spreadsheet.get_worksheet(0)
|
worksheet = spreadsheet.worksheet("Produkte")
|
||||||
|
|
||||||
data = worksheet.get_all_values()
|
data = worksheet.get_all_values()
|
||||||
|
|
||||||
|
# auto get the row index numbers for the columns
|
||||||
|
|
||||||
products = []
|
products = []
|
||||||
|
rowIndexProductId = -1
|
||||||
|
rowIndexProductName = -1
|
||||||
|
rowIndexProductVariant = -1
|
||||||
|
rowIndexProductVariantCharacteristics = -1
|
||||||
|
rowIndexNameSplitAtPosition = -1
|
||||||
|
|
||||||
|
for i in range(len(data[1])):
|
||||||
|
row = data[1][i]
|
||||||
|
|
||||||
|
if row == "#id":
|
||||||
|
rowIndexProductId = i
|
||||||
|
elif row == "Name":
|
||||||
|
rowIndexProductName = i
|
||||||
|
elif row == "Produktvariante":
|
||||||
|
rowIndexProductVariant = i
|
||||||
|
elif row == "Produktfarbe/Characteristics":
|
||||||
|
rowIndexProductVariantCharacteristics = i
|
||||||
|
elif row == "Name trennen bei Position":
|
||||||
|
rowIndexNameSplitAtPosition = i
|
||||||
|
|
||||||
|
if rowIndexProductId == -1 or rowIndexProductId == -1 or rowIndexProductName == -1 or rowIndexProductVariant == -1 or rowIndexProductVariantCharacteristics == -1:
|
||||||
|
sys.exit("Failed to get row index. Please check if the row names are equal to the names of the google sheet table header")
|
||||||
|
|
||||||
|
# adding products to list
|
||||||
|
|
||||||
for row in data[2:]:
|
for row in data[2:]:
|
||||||
if row[0] == "":
|
if row[0] == "":
|
||||||
continue
|
continue
|
||||||
|
|
||||||
products.append({
|
products.append({
|
||||||
"id": row[0],
|
"id": row[rowIndexProductId],
|
||||||
"name": add_underscore_at_position(row[1], int(row[25])),
|
"name": add_underscore_at_position(row[1], int(row[rowIndexNameSplitAtPosition])),
|
||||||
"product_variant": row[2],
|
"product_variant": row[rowIndexProductVariant],
|
||||||
"product_color": row[3]
|
"product_color": row[rowIndexProductVariantCharacteristics]
|
||||||
})
|
})
|
||||||
|
|
||||||
products_dict = {"products": products}
|
products_dict = {"products": products}
|
||||||
|
@ -82,10 +112,12 @@ def google_sheets_products():
|
||||||
with open('../../groupsData/google-sheet-products.json', 'w', encoding='utf-8') as json_file:
|
with open('../../groupsData/google-sheet-products.json', 'w', encoding='utf-8') as json_file:
|
||||||
json.dump(products_dict, json_file, ensure_ascii=False, indent=2)
|
json.dump(products_dict, json_file, ensure_ascii=False, indent=2)
|
||||||
|
|
||||||
update_grouptask_products_list_options("../../groups/shx-product-label/index.json", products)
|
update_grouptask_products_list_options(
|
||||||
update_grouptask_products_list_options("../../groups/shx-all-in-one-order/index.json", products)
|
"../../groups/shx-product-label/index.json", products)
|
||||||
|
update_grouptask_products_list_options(
|
||||||
|
"../../groups/shx-all-in-one-order/index.json", products)
|
||||||
|
|
||||||
print("Finished. Do not forget to reload the group configuration")
|
print("Finished. Do not forget to reload the group configuration by clicking on the 'Reload' button above the table on the right side.")
|
||||||
|
|
||||||
|
|
||||||
google_sheets_products()
|
google_sheets_products()
|
|
@ -4,7 +4,7 @@
|
||||||
"globalInputs": [],
|
"globalInputs": [],
|
||||||
"tasks": [
|
"tasks": [
|
||||||
{
|
{
|
||||||
"name": "Gutscheincodes erstellen",
|
"name": "Gutscheincodes für Bestellung erstellen (nur die Bestellnummer ohne #)",
|
||||||
"onFinish": "next",
|
"onFinish": "next",
|
||||||
"undoPossible": false,
|
"undoPossible": false,
|
||||||
"repeatPossible": true,
|
"repeatPossible": true,
|
||||||
|
|
|
@ -36,23 +36,25 @@
|
||||||
"#51139 Flamara der Drache, Farbe, Himmelblau (Fluoreszierend)",
|
"#51139 Flamara der Drache, Farbe, Himmelblau (Fluoreszierend)",
|
||||||
"#77970 Flamara der Drache, Farbe, Gold (Glänzend)",
|
"#77970 Flamara der Drache, Farbe, Gold (Glänzend)",
|
||||||
"#43356 Flamara der Drache, Farbe, Schwarz",
|
"#43356 Flamara der Drache, Farbe, Schwarz",
|
||||||
"#32974 Finn der Sad Hamster, Stil, Standard",
|
"#32974 Finn der Sad Hamster, Stil, Standard / Weiblich",
|
||||||
"#60798 Finn der Sad Hamster, Stil, Schlüsselanhänger",
|
"#60798 Finn der Sad Hamster, Stil, Schlüsselanhänger / Weiblich",
|
||||||
"#30563 Finn der Sad Hamster, Stil, Groß",
|
"#30563 Finn der Sad Hamster, Stil, Groß / Weiblich",
|
||||||
"#90586 Finn der Sad Hamster, Stil, Standard / Männlich",
|
"#90586 Finn der Sad Hamster, Stil, Standard / Männlich",
|
||||||
"#99560 Finn der Sad Hamster, Stil, Schlüsselanhänger / Männlich",
|
"#99560 Finn der Sad Hamster, Stil, Schlüsselanhänger / Männlich",
|
||||||
"#47364 Finn der Sad Hamster, Stil, Groß / Männlich",
|
"#47364 Finn der Sad Hamster, Stil, Groß / Männlich",
|
||||||
"#93047 Mia das Kätzchen, Farbe, Grau",
|
"#93047 Mia das Kätzchen, Farbe, Grau",
|
||||||
"#86423 Mia das Kätzchen, Farbe, Weiß",
|
"#86423 Mia das Kätzchen, Farbe, Weiß",
|
||||||
|
"#X38764 Mia das Kätzchen, Farbe, Weiß (Schlüsselanhänger)",
|
||||||
"#56083 Hoppel das Häschen, Farbe, Grau",
|
"#56083 Hoppel das Häschen, Farbe, Grau",
|
||||||
"#78693 Elias der Corgi, Farbe, Braun/Weiß",
|
"#78693 Elias der Corgi, Farbe, Braun/Weiß",
|
||||||
"#37335 Axel der Axolotl, Farbe, Pink",
|
"#37335 Axel der Axolotl, Farbe, Pink",
|
||||||
"#26822 Dilo der Delfin, Farbe, Blau/Weiß",
|
"#26822 Dilo der Delfin, Farbe, Blau ➔ Weiß",
|
||||||
"#51665 Einhorn, Farbe, Weiß",
|
"#51665 Sunny das Einhorn, Farbe, Weiß",
|
||||||
"#35717 Phoenix, Farbe, Sonderanfertigung Rosa/Weiß",
|
"#35717 Stella der Phönix, Farbe, Sonderanfertigung Rosa/Weiß",
|
||||||
"#26843 Phoenix, Farbe, Verlauf Lila/Pink",
|
"#26843 Stella der Phönix, Farbe, Verlauf Lila/Pink",
|
||||||
"#74943 Brain der Fuchs, Stil, Standard",
|
"#74943 Brain der Fuchs, Stil, Standard",
|
||||||
"#78071 Weißer Hund, Stil, Weiß"
|
"#78071 Weißer Hund, Stil, Weiß",
|
||||||
|
"#92734 Amigo der Capybara, Farbe, Braun"
|
||||||
],
|
],
|
||||||
"global": false
|
"global": false
|
||||||
}
|
}
|
||||||
|
|
|
@ -100,19 +100,19 @@
|
||||||
"id": "32974",
|
"id": "32974",
|
||||||
"name": "Finn der_Sad Hamster",
|
"name": "Finn der_Sad Hamster",
|
||||||
"product_variant": "Stil",
|
"product_variant": "Stil",
|
||||||
"product_color": "Standard"
|
"product_color": "Standard / Weiblich"
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"id": "60798",
|
"id": "60798",
|
||||||
"name": "Finn der_Sad Hamster",
|
"name": "Finn der_Sad Hamster",
|
||||||
"product_variant": "Stil",
|
"product_variant": "Stil",
|
||||||
"product_color": "Schlüsselanhänger"
|
"product_color": "Schlüsselanhänger / Weiblich"
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"id": "30563",
|
"id": "30563",
|
||||||
"name": "Finn der_Sad Hamster",
|
"name": "Finn der_Sad Hamster",
|
||||||
"product_variant": "Stil",
|
"product_variant": "Stil",
|
||||||
"product_color": "Groß"
|
"product_color": "Groß / Weiblich"
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"id": "90586",
|
"id": "90586",
|
||||||
|
@ -144,6 +144,12 @@
|
||||||
"product_variant": "Farbe",
|
"product_variant": "Farbe",
|
||||||
"product_color": "Weiß"
|
"product_color": "Weiß"
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
"id": "X38764",
|
||||||
|
"name": "Mia_das Kätzchen",
|
||||||
|
"product_variant": "Farbe",
|
||||||
|
"product_color": "Weiß (Schlüsselanhänger)"
|
||||||
|
},
|
||||||
{
|
{
|
||||||
"id": "56083",
|
"id": "56083",
|
||||||
"name": "Hoppel_das Häschen",
|
"name": "Hoppel_das Häschen",
|
||||||
|
@ -166,23 +172,23 @@
|
||||||
"id": "26822",
|
"id": "26822",
|
||||||
"name": "Dilo_der Delfin",
|
"name": "Dilo_der Delfin",
|
||||||
"product_variant": "Farbe",
|
"product_variant": "Farbe",
|
||||||
"product_color": "Blau/Weiß"
|
"product_color": "Blau ➔ Weiß"
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"id": "51665",
|
"id": "51665",
|
||||||
"name": "Einhorn",
|
"name": "Sunny_das Einhorn",
|
||||||
"product_variant": "Farbe",
|
"product_variant": "Farbe",
|
||||||
"product_color": "Weiß"
|
"product_color": "Weiß"
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"id": "35717",
|
"id": "35717",
|
||||||
"name": "Phoenix",
|
"name": "Stella_der Phönix",
|
||||||
"product_variant": "Farbe",
|
"product_variant": "Farbe",
|
||||||
"product_color": "Sonderanfertigung Rosa/Weiß"
|
"product_color": "Sonderanfertigung Rosa/Weiß"
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"id": "26843",
|
"id": "26843",
|
||||||
"name": "Phoenix",
|
"name": "Stella_der Phönix",
|
||||||
"product_variant": "Farbe",
|
"product_variant": "Farbe",
|
||||||
"product_color": "Verlauf Lila/Pink"
|
"product_color": "Verlauf Lila/Pink"
|
||||||
},
|
},
|
||||||
|
@ -197,6 +203,12 @@
|
||||||
"name": "Weißer_Hund",
|
"name": "Weißer_Hund",
|
||||||
"product_variant": "Stil",
|
"product_variant": "Stil",
|
||||||
"product_color": "Weiß"
|
"product_color": "Weiß"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"id": "92734",
|
||||||
|
"name": "Amigo_der Capybara",
|
||||||
|
"product_variant": "Farbe",
|
||||||
|
"product_color": "Braun"
|
||||||
}
|
}
|
||||||
]
|
]
|
||||||
}
|
}
|
Loading…
Reference in New Issue