update 01/03/2022 - 14h30
parent
d79a649c50
commit
488cb7d7ef
1695
Log/log_file.log
1695
Log/log_file.log
File diff suppressed because it is too large
Load Diff
156
wrapper.py
156
wrapper.py
|
@ -15,7 +15,7 @@ import prj_common as mycommon
|
||||||
import secrets
|
import secrets
|
||||||
from pymongo import ReturnDocument
|
from pymongo import ReturnDocument
|
||||||
import inspect
|
import inspect
|
||||||
import os
|
import sys, os
|
||||||
import csv
|
import csv
|
||||||
import pandas as pd
|
import pandas as pd
|
||||||
|
|
||||||
|
@ -198,7 +198,9 @@ def recherche_text_simple(diction):
|
||||||
# Ici on doit mettre tous les champs possible (obligatoire ou non) de la BDD dans la liste
|
# Ici on doit mettre tous les champs possible (obligatoire ou non) de la BDD dans la liste
|
||||||
# field_list.
|
# field_list.
|
||||||
'''
|
'''
|
||||||
field_list = ['search_text', 'token', 'certif', 'support', 'type', 'lang','price']
|
field_list = ['token', 'user_ip', 'user_country_code', 'user_country_name', 'user_city',
|
||||||
|
'user_postal', 'user_latitude', 'user_longitude', 'user_state', 'search_text', 'certif',
|
||||||
|
'support', 'type', 'lang', 'price']
|
||||||
incom_keys = diction.keys()
|
incom_keys = diction.keys()
|
||||||
for val in incom_keys:
|
for val in incom_keys:
|
||||||
if val not in field_list:
|
if val not in field_list:
|
||||||
|
@ -286,6 +288,8 @@ def recherche_text_simple(diction):
|
||||||
'''
|
'''
|
||||||
|
|
||||||
user_recid = "None"
|
user_recid = "None"
|
||||||
|
coll_search_result = dbname['user_recherche_result']
|
||||||
|
|
||||||
# Verification de la validité du token/mail dans le cas des user en mode connecté
|
# Verification de la validité du token/mail dans le cas des user en mode connecté
|
||||||
if ( len(str(token)) > 0 ):
|
if ( len(str(token)) > 0 ):
|
||||||
retval = mycommon.check_token_validity("", token)
|
retval = mycommon.check_token_validity("", token)
|
||||||
|
@ -304,7 +308,7 @@ def recherche_text_simple(diction):
|
||||||
mycommon.myprint(" On recehrche la phrase +'" + search_text + "'")
|
mycommon.myprint(" On recehrche la phrase +'" + search_text + "'")
|
||||||
|
|
||||||
# Enregistrerment de la recherche
|
# Enregistrerment de la recherche
|
||||||
retval, message = store_recherche(diction, user_recid)
|
retval, message, store_recherche_Id = store_recherche(diction, user_recid)
|
||||||
if (retval is False):
|
if (retval is False):
|
||||||
return retval, message
|
return retval, message
|
||||||
|
|
||||||
|
@ -345,11 +349,11 @@ def recherche_text_simple(diction):
|
||||||
final_message2 = []
|
final_message2 = []
|
||||||
|
|
||||||
for t in final_message:
|
for t in final_message:
|
||||||
|
if( t is not False):
|
||||||
for y in t:
|
for y in t:
|
||||||
print( " unique = "+str(y))
|
print( " unique = "+str(y))
|
||||||
final_message2.append(y)
|
final_message2.append(y)
|
||||||
|
|
||||||
print(" YY = "+str(final_message2))
|
|
||||||
|
|
||||||
|
|
||||||
coll_name = dbname['myclass']
|
coll_name = dbname['myclass']
|
||||||
|
@ -357,15 +361,79 @@ def recherche_text_simple(diction):
|
||||||
print(" Dans la recherch TIPS , les critère = " + str(certif_crit) + " la langue = " + str(
|
print(" Dans la recherch TIPS , les critère = " + str(certif_crit) + " la langue = " + str(
|
||||||
lang_crit) + " price = " + str(price_crit)+" support = "+str(support_crit))
|
lang_crit) + " price = " + str(price_crit)+" support = "+str(support_crit))
|
||||||
|
|
||||||
|
'''
|
||||||
|
A present mise à jour de la table "user_recherche" avec les resultats trouvés
|
||||||
|
'''
|
||||||
|
#store_recherche_Id
|
||||||
|
find_result = {'find_result':str(final_message2)}
|
||||||
|
|
||||||
|
tab_user_recherche = dbname['user_recherche']
|
||||||
|
# seules les formation avec locked = 0 et valide=1 sont modifiables
|
||||||
|
print(str(inspect.stack()[0][3]) + " ENREG DES RESULT :"+str(store_recherche_Id)+" --- "+str(final_message2))
|
||||||
|
|
||||||
|
|
||||||
|
ret_val_user_rech = coll_name.find_one_and_update(
|
||||||
|
{'_id': ObjectId(store_recherche_Id)},
|
||||||
|
{"$set": find_result},
|
||||||
|
return_document=ReturnDocument.AFTER
|
||||||
|
)
|
||||||
|
|
||||||
|
if (ret_val_user_rech is False ):
|
||||||
|
mycommon.myprint(str(inspect.stack()[0][3]) + " - Impossible de mettre à jour la table des resultat"
|
||||||
|
" d'une recherche de formation. Voir _id = "+ str( store_recherche_Id))
|
||||||
|
return False, "La recheche est impossible "
|
||||||
|
|
||||||
|
'''
|
||||||
|
la valeur nb_result permettra de savoir si la requete a donnée un resultat.
|
||||||
|
si ce n'est pas le cas, il faudra à la fin enregistrer la requete avec un result a vide'''
|
||||||
|
nb_result = 0
|
||||||
for x in coll_name.find(({"$and": [{"external_code": {"$in": final_message2}},
|
for x in coll_name.find(({"$and": [{"external_code": {"$in": final_message2}},
|
||||||
certif_crit, lang_crit, type_crit, price_crit, support_crit]})):
|
certif_crit, lang_crit, type_crit, price_crit, support_crit]})):
|
||||||
mycommon.myprint(x)
|
|
||||||
|
nb_result = nb_result +1
|
||||||
|
my_recid = {}
|
||||||
|
my_recid['user_rec_id'] = str(user_recid)
|
||||||
|
mydict_combined = {**diction, **x, **my_recid}
|
||||||
|
mydict_combined['date_update'] = str(datetime.now())
|
||||||
|
if ("_id" in mydict_combined.keys()):
|
||||||
|
mydict_combined['class_id'] = mydict_combined.pop('_id')
|
||||||
|
|
||||||
|
mycommon.myprint("COMBINED = " + str(mydict_combined))
|
||||||
|
|
||||||
|
'''
|
||||||
|
Statistique : Insertion du recherche - resultat '''
|
||||||
|
ret_val_tmp = coll_search_result.insert_one(mydict_combined)
|
||||||
|
if (ret_val_tmp is False):
|
||||||
|
mycommon.myprint(str(inspect.stack()[0][3]) + " - Impossible de mettre à jour la table des resultat"
|
||||||
|
" d'une recherche de formation. Voir _id = ")
|
||||||
|
return False, "La recheche est impossible "
|
||||||
|
|
||||||
user = x
|
user = x
|
||||||
insertObject.append(JSONEncoder().encode(user))
|
insertObject.append(JSONEncoder().encode(user))
|
||||||
|
|
||||||
# mycommon.myprint(" insertObject = ", insertObject)
|
# mycommon.myprint(" insertObject = ", insertObject)
|
||||||
|
|
||||||
|
''' en cas de resultat vide, enregsitrement de la requete de recherche avec les filtres associé'''
|
||||||
|
if( nb_result == 0):
|
||||||
|
my_recid = {}
|
||||||
|
my_recid['user_rec_id'] = str(user_recid)
|
||||||
|
mydict_combined = {**diction, **my_recid}
|
||||||
|
mydict_combined['date_update'] = str(datetime.now())
|
||||||
|
|
||||||
|
|
||||||
|
'''
|
||||||
|
Statistique : Insertion du recherche - resultat '''
|
||||||
|
ret_val_tmp = coll_search_result.insert_one(mydict_combined)
|
||||||
|
if (ret_val_tmp is False):
|
||||||
|
mycommon.myprint(str(inspect.stack()[0][3]) + " - Impossible de mettre à jour la table des resultat"
|
||||||
|
" d'une recherche de formation. Voir _id = ")
|
||||||
|
return False, "La recheche est impossible "
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
return True, insertObject
|
return True, insertObject
|
||||||
|
# Fin de la recherche par tips.
|
||||||
|
|
||||||
|
|
||||||
tab_training = []
|
tab_training = []
|
||||||
|
@ -378,14 +446,52 @@ def recherche_text_simple(diction):
|
||||||
print(" Dans la recherch, les critère = "+str(certif_crit)+" la langue = "+str(lang_crit)+" price = "+str(price_crit))
|
print(" Dans la recherch, les critère = "+str(certif_crit)+" la langue = "+str(lang_crit)+" price = "+str(price_crit))
|
||||||
|
|
||||||
#ici ajouter tous les critère comme ci-dessous avec le support et le certif
|
#ici ajouter tous les critère comme ci-dessous avec le support et le certif
|
||||||
|
'''
|
||||||
|
la valeur nb_result permettra de savoir si la requete a donnée un resultat.
|
||||||
|
si ce n'est pas le cas, il faudra à la fin enregistrer la requete avec un result a vide'''
|
||||||
|
nb_result = 0
|
||||||
insertObject = []
|
insertObject = []
|
||||||
for x in coll_name.find(({"$and": [{"external_code": {"$in": tab_training}},
|
for x in coll_name.find(({"$and": [{"external_code": {"$in": tab_training}},
|
||||||
certif_crit,lang_crit, type_crit,price_crit, support_crit ]})):
|
certif_crit,lang_crit, type_crit,price_crit, support_crit ]})):
|
||||||
mycommon.myprint(x)
|
nb_result = nb_result + 1
|
||||||
|
my_recid = {}
|
||||||
|
my_recid['user_rec_id'] = str(user_recid)
|
||||||
|
mydict_combined = {**diction, **x, **my_recid}
|
||||||
|
mydict_combined['date_update'] = str(datetime.now())
|
||||||
|
if ("_id" in mydict_combined.keys()):
|
||||||
|
mydict_combined['class_id'] = mydict_combined.pop('_id')
|
||||||
|
|
||||||
|
mycommon.myprint("COMBINED = " + str(mydict_combined))
|
||||||
|
|
||||||
|
'''
|
||||||
|
Statistique : Insertion du recherche - resultat '''
|
||||||
|
ret_val_tmp = coll_search_result.insert_one(mydict_combined)
|
||||||
|
if (ret_val_tmp is False):
|
||||||
|
mycommon.myprint(str(inspect.stack()[0][3]) + " - Impossible de mettre à jour la table des resultat"
|
||||||
|
" d'une recherche de formation. Voir _id = ")
|
||||||
|
return False, "La recheche est impossible "
|
||||||
|
|
||||||
user = x
|
user = x
|
||||||
insertObject.append(JSONEncoder().encode(user))
|
insertObject.append(JSONEncoder().encode(user))
|
||||||
|
|
||||||
# mycommon.myprint(" insertObject = ", insertObject)
|
# mycommon.myprint(" insertObject = ", insertObject)
|
||||||
|
|
||||||
|
''' en cas de resultat vide, enregsitrement de la requete de recherche avec les filtres associé'''
|
||||||
|
if (nb_result == 0):
|
||||||
|
my_recid = {}
|
||||||
|
my_recid['user_rec_id'] = str(user_recid)
|
||||||
|
mydict_combined = {**diction, **my_recid}
|
||||||
|
mydict_combined['date_update'] = str(datetime.now())
|
||||||
|
|
||||||
|
'''
|
||||||
|
Statistique : Insertion du recherche - resultat '''
|
||||||
|
ret_val_tmp = coll_search_result.insert_one(mydict_combined)
|
||||||
|
if (ret_val_tmp is False):
|
||||||
|
mycommon.myprint(str(inspect.stack()[0][3]) + " - Impossible de mettre à jour la table des resultat"
|
||||||
|
" d'une recherche de formation. Voir _id = ")
|
||||||
|
return False, "La recheche est impossible "
|
||||||
|
|
||||||
|
|
||||||
return True, insertObject
|
return True, insertObject
|
||||||
|
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
|
@ -434,14 +540,19 @@ def store_recherche(diction, user_recid=""):
|
||||||
if ( len(str(user_recid)) <= 0 ):
|
if ( len(str(user_recid)) <= 0 ):
|
||||||
user_recid = 'None' # by default
|
user_recid = 'None' # by default
|
||||||
|
|
||||||
|
'''
|
||||||
field_list = ['search_text', 'token','id','type', 'lang', 'level', 'dist',
|
field_list = ['search_text', 'token','id','type', 'lang', 'level', 'dist',
|
||||||
'price', 'certif', 'source', 'name','valide','certif', 'support','type']
|
'price', 'certif', 'source', 'name','valide','certif', 'support','type']
|
||||||
|
'''
|
||||||
|
|
||||||
|
field_list = ['token', 'user_ip', 'user_country_code', 'user_country_name', 'user_city',
|
||||||
|
'user_postal', 'user_latitude', 'user_longitude', 'user_state', 'search_text', 'certif',
|
||||||
|
'support', 'type', 'lang', 'price']
|
||||||
incom_keys = diction.keys()
|
incom_keys = diction.keys()
|
||||||
for val in incom_keys:
|
for val in incom_keys:
|
||||||
if val not in field_list:
|
if val not in field_list:
|
||||||
mycommon.myprint(" Le champ '" + val + "' n'existe pas, recherche annulée")
|
mycommon.myprint(str(inspect.stack()[0][3]) + " Le champ '" + val + "' n'existe pas, recherche annulée")
|
||||||
return False, " Le champ '" + val + "' n'existe pas, recherche annulée"
|
return False, " Le champ '" + val + "' n'existe pas, recherche annulée", None
|
||||||
|
|
||||||
'''
|
'''
|
||||||
Une fois qu'on a controlé que toutes les clés mise dans l'API sont correcte. etape precedente,
|
Une fois qu'on a controlé que toutes les clés mise dans l'API sont correcte. etape precedente,
|
||||||
|
@ -452,7 +563,7 @@ def store_recherche(diction, user_recid=""):
|
||||||
for val in field_list_obligatoire:
|
for val in field_list_obligatoire:
|
||||||
if val not in diction:
|
if val not in diction:
|
||||||
mycommon.myprint(" : La valeur '" + val + "' n'est pas presente dans liste ")
|
mycommon.myprint(" : La valeur '" + val + "' n'est pas presente dans liste ")
|
||||||
return False, " : La valeur '" + val + "' n'est pas presente dans liste "
|
return False, " : La valeur '" + val + "' n'est pas presente dans liste ", None
|
||||||
|
|
||||||
|
|
||||||
# recuperation des paramettre
|
# recuperation des paramettre
|
||||||
|
@ -529,7 +640,7 @@ def store_recherche(diction, user_recid=""):
|
||||||
coll_name = dbname['user_recherche']
|
coll_name = dbname['user_recherche']
|
||||||
|
|
||||||
# Si le champ "id" est renseigné, il s'agit d'une mis jour
|
# Si le champ "id" est renseigné, il s'agit d'une mis jour
|
||||||
mycommon.myprint("on va stocker "+str(mydata)+" id = "+str(mydata_id))
|
mycommon.myprint(str(inspect.stack()[0][3]) + " on va stocker "+str(mydata)+" id = "+str(mydata_id))
|
||||||
|
|
||||||
if( len(str(mydata_id)) > 0 ):
|
if( len(str(mydata_id)) > 0 ):
|
||||||
ret_val = coll_name.find_one_and_update({'_id': ObjectId(str(mydata_id)), 'valide': '1'},
|
ret_val = coll_name.find_one_and_update({'_id': ObjectId(str(mydata_id)), 'valide': '1'},
|
||||||
|
@ -539,26 +650,29 @@ def store_recherche(diction, user_recid=""):
|
||||||
|
|
||||||
if (ret_val and ret_val['_id']):
|
if (ret_val and ret_val['_id']):
|
||||||
nb_doc = str(ret_val['_id'])
|
nb_doc = str(ret_val['_id'])
|
||||||
mycommon.myprint("La recherche a bien été mise à jour . Le Doc Id = "+str(nb_doc))
|
mycommon.myprint(str(inspect.stack()[0][3]) + " La recherche a bien été mise à jour . Le Doc Id = "+str(nb_doc))
|
||||||
return True, "La recherche a bien été mise à jour"
|
return True, "La recherche a bien été mise à jour", ret_val['_id']
|
||||||
|
|
||||||
else:
|
else:
|
||||||
return False, "Impossible de mettre à jour a la recherche"
|
return False, "Impossible de mettre à jour a la recherche", None
|
||||||
|
|
||||||
else:
|
else:
|
||||||
ret_val = coll_name.insert_one(mydata)
|
ret_val = coll_name.insert_one(mydata)
|
||||||
|
|
||||||
if ret_val and ret_val.inserted_id:
|
if ret_val and ret_val.inserted_id:
|
||||||
nb_doc = ret_val.inserted_id
|
nb_doc = ret_val.inserted_id
|
||||||
mycommon.myprint("La recherche a été bien enregistrée. Id = '" + str(nb_doc)+"' ")
|
mycommon.myprint(str(inspect.stack()[0][3]) + " La recherche a été bien enregistrée. Id = '" + str(nb_doc)+"' ")
|
||||||
return True, "La recherche a bien été mise à jour"
|
return True, "La recherche a bien été mise à jour", nb_doc
|
||||||
else:
|
else:
|
||||||
return False, "Impossible d'enregistrer la recherche"
|
mycommon.myprint(
|
||||||
|
str(inspect.stack()[0][3]) + "Impossible d'enregistrer la recherche")
|
||||||
|
return False, "Impossible d'enregistrer la recherche ", None
|
||||||
|
|
||||||
|
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
mycommon.myprint(e)
|
exc_type, exc_obj, exc_tb = sys.exc_info()
|
||||||
return False, "Impossible d'enregistrer la recherche"
|
mycommon.myprint(str(inspect.stack()[0][3]) + " -" + str(e) + " - Line : " + str(exc_tb.tb_lineno))
|
||||||
|
return False, "Impossible d'enregistrer la recherche", None
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
@ -618,7 +732,7 @@ def recherche_tips_ret_ref(diction):
|
||||||
print(" ####### recherche tips, voici mon new diction"+str(diction))
|
print(" ####### recherche tips, voici mon new diction"+str(diction))
|
||||||
|
|
||||||
# Enregistrerment de la recherche
|
# Enregistrerment de la recherche
|
||||||
retval, message = store_recherche(diction, user_recid)
|
retval, message, store_recherche_Id = store_recherche(diction, user_recid)
|
||||||
if( retval is False):
|
if( retval is False):
|
||||||
return retval, message
|
return retval, message
|
||||||
|
|
||||||
|
@ -750,7 +864,7 @@ def recherche_tips(diction):
|
||||||
print(" ####### recherche tips, voici mon new diction"+str(diction))
|
print(" ####### recherche tips, voici mon new diction"+str(diction))
|
||||||
|
|
||||||
# Enregistrerment de la recherche
|
# Enregistrerment de la recherche
|
||||||
retval, message = store_recherche(diction, user_recid)
|
retval, message, store_recherche_Id = store_recherche(diction, user_recid)
|
||||||
if( retval is False):
|
if( retval is False):
|
||||||
return retval, message
|
return retval, message
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue