-
-
Notifications
You must be signed in to change notification settings - Fork 13
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(GDPR): improve script to manage Picard (#430)
- Loading branch information
Showing
5 changed files
with
178 additions
and
55 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,8 +1,8 @@ | ||
OPEN_PRICES_FIELD,AUCHAN_FIELD,AUCHAN_COMMENT,CARREFOUR_FIELD,CARREFOUR_COMMENT,ELECLERC_FIELD,ELECLERC_COMMENT,INTERMARCHE_FIELD,INTERMARCHE_COMMENT | ||
product_code,CODE_PRODUIT,"raw products have a length of 4 or 12 or 13 but ending with lots of 0 (fruits, vegetables, meat, cheese) (ex: 4400, 200512000000, 2630329000000)",Code Barre du produit,prefixed and suffixed with |,ean,,COD_ARTC_EAN,duplicate column with EAN_GD | ||
product_name,NOM_PRODUIT,,Description du produit,,article_libelle,,LB_ARTC,duplicate column with LB_COMM0 | ||
price,PRIX_UNITAIRE,,Prix unitaire TTC avec remise (€),,article_prix_unitaire,,CA TTC Produit,has commas instead of points | ||
discount,,,"Remise sur le produit (€) (chaque remise d'un produit regroupe les promotions, les avantages de la carte PASS, les bons d'achats… appliqués lors du passage en caisse)",,,,, | ||
quantity,,,Quantité,,,,Qte Vendues, | ||
date,JOUR,format YYYY-MM-DD,Date de transaction,format DD/MM/YYYY,date_ticket,format YYYY-MM-DD,DT_TICK,format DD/MM/YYYY | ||
location,CODE_POSTAL,,NOM DU MAGASIN,,code_postal,,LB_COMM, | ||
OPEN_PRICES_FIELD,AUCHAN_FIELD,AUCHAN_COMMENT,CARREFOUR_FIELD,CARREFOUR_COMMENT,ELECLERC_FIELD,ELECLERC_COMMENT,INTERMARCHE_FIELD,INTERMARCHE_COMMENT,PICARD_FIELD,PICARD_COMMENT | ||
product_code,CODE_PRODUIT,"raw products have a length of 4 or 12 or 13 but ending with lots of 0 (fruits, vegetables, meat, cheese) (ex: 4400, 200512000000, 2630329000000)",Code Barre du produit,prefixed and suffixed with |,ean,,COD_ARTC_EAN,duplicate column with EAN_GD,CODE PRODUIT,a 5-number code. need to do an extra API search to find the corresponding product | ||
product_name,NOM_PRODUIT,,Description du produit,,article_libelle,,LB_ARTC,duplicate column with LB_COMM0,LIBELLE ARTICLE, | ||
price,PRIX_UNITAIRE,,Prix unitaire TTC avec remise (€),,article_prix_unitaire,,CA TTC Produit,has commas instead of points,PRIX TTC,has commas instead of points | ||
discount,,,"Remise sur le produit (€) (chaque remise d'un produit regroupe les promotions, les avantages de la carte PASS, les bons d'achats… appliqués lors du passage en caisse)",,,,,,IDENTIFIANT REMISE,a string ID to another table | ||
quantity,,,Quantité,,,,Qte Vendues,,NOMBRE UNITES, | ||
date,JOUR,format YYYY-MM-DD,Date de transaction,format DD/MM/YYYY,date_ticket,format YYYY-MM-DD,DT_TICK,format DD/MM/YYYY,DATE TICKET, | ||
location,CODE_POSTAL,,NOM DU MAGASIN,,code_postal,,LB_COMM,,NOM DU MAGASIN, |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,68 @@ | ||
import requests | ||
|
||
OFF_SEARCHLICIOUS_API_ENDPOINT = "https://search.openfoodfacts.org/search" | ||
PICARD_GS1_PREFIX = "327016" | ||
|
||
|
||
def get_picard_product_from_subcode(op_price_dict): | ||
# the Picard product_code is incomplete | ||
# use Search-a-licious API to get the full product code | ||
# if needed, prompt the user to select the correct one | ||
passes_test = True | ||
full_product_code = None | ||
|
||
print( | ||
"----- Input:", | ||
op_price_dict["product_code"], | ||
op_price_dict["product_name"], | ||
op_price_dict["price"], | ||
) | ||
for q_index, q_params in enumerate( | ||
[ | ||
f"code:{PICARD_GS1_PREFIX}?{op_price_dict['product_code']}? brands:picard", | ||
f"code:{PICARD_GS1_PREFIX}?{op_price_dict['product_code']}?", | ||
f"code:*{op_price_dict['product_code']}? brands:picard", | ||
f"code:*{op_price_dict['product_code']}?&page_size=50", | ||
] | ||
): | ||
response = requests.get( | ||
OFF_SEARCHLICIOUS_API_ENDPOINT, | ||
params={"q": q_params}, | ||
) | ||
print(response.url) | ||
if response.status_code == 200: | ||
response_product_count = response.json()["count"] | ||
print("Products found:", response_product_count) | ||
if response_product_count: | ||
# confidence strong enough: take the first product | ||
if (q_index < 2) and (response_product_count == 1): | ||
full_product_code = response.json()["hits"][0]["code"] | ||
else: | ||
# multiple results: prompt the user to select | ||
response_product_list = response.json()["hits"] | ||
for index, response_product in enumerate(response_product_list): | ||
print( | ||
index + 1, | ||
":", | ||
response_product.get("code"), | ||
response_product.get("product_name", ""), | ||
response_product.get("brands_tags", ""), | ||
response_product.get("stores", ""), | ||
) | ||
user_choice_number_str = input( | ||
"Which product ? Type 0 to skip. Or provide the correct code. " | ||
) | ||
if len(user_choice_number_str) == 1: | ||
full_product_code = response_product_list[ | ||
int(user_choice_number_str) - 1 | ||
]["code"] | ||
print("Chosen product code:", full_product_code) | ||
elif 3 < len(user_choice_number_str) <= 13: | ||
full_product_code = user_choice_number_str | ||
print("Chosen product code:", full_product_code) | ||
else: | ||
print("Product not found...") | ||
passes_test = False | ||
break | ||
|
||
return passes_test, full_product_code |