master
cherif 2024-12-30 14:46:41 +01:00
parent 0fe5c2a58e
commit 11e0cb280e
6 changed files with 2234 additions and 64 deletions

View File

@ -1,12 +1,13 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="ChangeListManager">
<list default="true" id="c6d0259a-16e1-410d-91a1-830590ee2a08" name="Changes" comment="sdf">
<list default="true" id="c6d0259a-16e1-410d-91a1-830590ee2a08" name="Changes" comment="sdfd">
<change beforePath="$PROJECT_DIR$/.idea/workspace.xml" beforeDir="false" afterPath="$PROJECT_DIR$/.idea/workspace.xml" afterDir="false" />
<change beforePath="$PROJECT_DIR$/GlobalVariable.py" beforeDir="false" afterPath="$PROJECT_DIR$/GlobalVariable.py" afterDir="false" />
<change beforePath="$PROJECT_DIR$/Log/log_file.log" beforeDir="false" afterPath="$PROJECT_DIR$/Log/log_file.log" afterDir="false" />
<change beforePath="$PROJECT_DIR$/articles_avis.py" beforeDir="false" afterPath="$PROJECT_DIR$/articles_avis.py" afterDir="false" />
<change beforePath="$PROJECT_DIR$/main.py" beforeDir="false" afterPath="$PROJECT_DIR$/main.py" afterDir="false" />
<change beforePath="$PROJECT_DIR$/tools_cherif/mysy_openai_file.py" beforeDir="false" afterPath="$PROJECT_DIR$/tools_cherif/mysy_openai_file.py" afterDir="false" />
<change beforePath="$PROJECT_DIR$/prj_common.py" beforeDir="false" afterPath="$PROJECT_DIR$/prj_common.py" afterDir="false" />
</list>
<option name="SHOW_DIALOG" value="false" />
<option name="HIGHLIGHT_CONFLICTS" value="true" />
@ -77,13 +78,6 @@
<option name="presentableId" value="Default" />
<updated>1680804787304</updated>
</task>
<task id="LOCAL-00374" summary="18/08/2024 - 16h55">
<created>1724077502402</created>
<option name="number" value="00374" />
<option name="presentableId" value="LOCAL-00374" />
<option name="project" value="LOCAL" />
<updated>1724077502403</updated>
</task>
<task id="LOCAL-00375" summary="18/08/2024 - 21h55">
<created>1724096583696</created>
<option name="number" value="00375" />
@ -420,7 +414,14 @@
<option name="project" value="LOCAL" />
<updated>1735475357282</updated>
</task>
<option name="localTasksCounter" value="423" />
<task id="LOCAL-00423" summary="sdfd">
<created>1735494533471</created>
<option name="number" value="00423" />
<option name="presentableId" value="LOCAL-00423" />
<option name="project" value="LOCAL" />
<updated>1735494533471</updated>
</task>
<option name="localTasksCounter" value="424" />
<servers />
</component>
<component name="Vcs.Log.Tabs.Properties">
@ -462,7 +463,6 @@
</option>
</component>
<component name="VcsManagerConfiguration">
<MESSAGE value="19/09/2024 - 20h" />
<MESSAGE value="23/09/2024 - 17h" />
<MESSAGE value="25/09/2024 - 15h" />
<MESSAGE value="sdfsd" />
@ -487,6 +487,7 @@
<MESSAGE value="25/12/2024 - 14h" />
<MESSAGE value="25/12/2024 - 22h30" />
<MESSAGE value="sdf" />
<option name="LAST_COMMIT_MESSAGE" value="sdf" />
<MESSAGE value="sdfd" />
<option name="LAST_COMMIT_MESSAGE" value="sdfd" />
</component>
</project>

View File

@ -30,6 +30,12 @@ if (MYSY_ENV == "PROD"):
# Domaine pour le catalogue public
MYSY_PUBLIC_CATALOG_DOMAIN = 'mysy-hosting.online'
"""
REPERTOIRE FTP DES IMAGES DU BLOG
"""
BLOG_FTP_IMG_REPOSITORY = "/var/www/html/blog_imgs/blog_img_prod/"
elif (MYSY_ENV == "DEV"):
CONNECTION_STRING = "mongodb://localhost:27017/cherifdb_dev"
client = MongoClient(CONNECTION_STRING)
@ -40,6 +46,12 @@ elif (MYSY_ENV == "DEV"):
# Domaine pour le catalogue public
MYSY_PUBLIC_CATALOG_DOMAIN = 'localhost:3009'
"""
REPERTOIRE FTP DES IMAGES DU BLOG
"""
BLOG_FTP_IMG_REPOSITORY = "/var/www/html/blog_imgs/blog_img_dev/"
elif (MYSY_ENV == "REC"):
CONNECTION_STRING = "mongodb://localhost:27017/cherifdb_rec"
@ -51,6 +63,12 @@ elif (MYSY_ENV == "REC"):
# Domaine pour le catalogue public
MYSY_PUBLIC_CATALOG_DOMAIN = 'devmysy-hosting.online'
"""
REPERTOIRE FTP DES IMAGES DU BLOG
"""
BLOG_FTP_IMG_REPOSITORY = "/var/www/html/blog_imgs/blog_img_rec/"
elif (MYSY_ENV == "DEM"):
CONNECTION_STRING = "mongodb://localhost:27017/cherifdb_demo"
client = MongoClient(CONNECTION_STRING)
@ -61,6 +79,11 @@ elif (MYSY_ENV == "DEM"):
# Domaine pour le catalogue public
MYSY_PUBLIC_CATALOG_DOMAIN = 'devmysy-hosting.online'
"""
REPERTOIRE FTP DES IMAGES DU BLOG
"""
BLOG_FTP_IMG_REPOSITORY = "/var/www/html/blog_imgs/blog_img_dem/"
YTUBES_CONNECTION_STRING = "mongodb://localhost:27017/"
@ -208,8 +231,6 @@ Repertoire pour les liste d'emargement
"""
EMARGEMENT_DIRECTORY = "./Emargement/"
"""
"""
"""
Repertoire racine du ftp ou sont stocké les factures
@ -841,4 +862,6 @@ VOICE_INSTRUCTION_CONFIRMATION = ["confirme", "confimer", "conformation"]
"""
Annulation d'un ordre de vocal
"""
VOICE_INSTRUCTION_ANNULATION = ["annuler", "annulle", "refus", "refuser"]
VOICE_INSTRUCTION_ANNULATION = ["annuler", "annulle", "refus", "refuser"]

File diff suppressed because it is too large Load Diff

View File

@ -3,6 +3,7 @@
Cette class gere les avis et articles sur une formation.
'''
import pysftp
from pymongo import MongoClient
import pymongo
import hashlib
@ -560,10 +561,6 @@ def get_articles_avis_from_id(diction):
# Recuperation des parametres
mydata = {}
#print(" My Data =" + str(mydata))
@ -692,7 +689,7 @@ def add_articles_avis(diction):
'user_city', 'user_postal', 'user_latitude', 'user_longitude', 'user_state',
'type_formation', 'qualite', 'avis', 'note', 'qualityrating','avisrating',
'comment', 'postedby', 'url_formation', 'user_recid', 'display_header_img',
'img_path', 'date_publication']
'img_path', 'date_publication', 'meta_description', 'img_file_name']
incom_keys = diction.keys()
for val in incom_keys:
@ -854,9 +851,20 @@ def add_articles_avis(diction):
if diction['avisrating']:
mydata['avisrating'] = diction['avisrating']
if ("qualityrating" in diction.keys()):
if diction['qualityrating']:
mydata['qualityrating'] = diction['qualityrating']
if ("img_file_name" in diction.keys()):
if diction['img_file_name']:
mydata['img_file_name'] = diction['img_file_name']
meta_description = ""
if ("meta_description" in diction.keys()):
if diction['meta_description']:
meta_description = str(diction['meta_description']).strip().lower()[0:154]
else:
meta_description = str(diction['title_formation']).strip().lower()[0:154]
mydata['meta_description'] = meta_description
mydata['valide'] = '1'
mydata['locked'] = '0'
@ -872,45 +880,7 @@ def add_articles_avis(diction):
ret_val = coll_name.insert_one(mydata)
return True, " L'article/avis a été bien ajouté"
"""
if (ret_val and ret_val.inserted_id):
nb_doc = str(ret_val.inserted_id)
mycommon.myprint(
str(inspect.stack()[0][3]) + " - L'article/avis a été bien ajouté =" + str(nb_doc))
'''
Vu que l'ajout a bien ete fait, on declenche l'envoie de l'email (enregistrement
dans la collection "user_message". c'est un cron qui enverra l'email plus tard.
'''
notif_dict = {}
notif_dict['type'] = 'email'
notif_dict['sender_mail']= MYSY_GV.INTERNAL_MAIL_SENDER
notif_dict['sender_tel'] = MYSY_GV.INTERNAL_TEL_SENDER
notif_dict['recever_mail'] = MYSY_GV.INTERNAL_MAIL_RECEVER
notif_dict['recever_tel'] = MYSY_GV.INTERNAL_TEL_RECEVER
notif_dict['object'] = 'Nouvel article par utilisateur : '+str(ret_val.inserted_id)
notif_dict['message'] = 'Merci de verifier et valider article _id='+str(ret_val.inserted_id)
notif_dict['token'] = ''
notif_dict['user_ip'] = ''
notif_dict['user_country_code'] = ''
notif_dict['user_country_name'] = ''
notif_dict['user_city'] = ''
notif_dict['user_postal'] = ''
notif_dict['user_latitude'] = ''
notif_dict['user_longitude'] = ''
notif_dict['user_state'] = ''
notif_dict['sender_name'] = 'systeme automatique'
umm.add_user_message(notif_dict)
return True, " L'article/avis a été bien ajouté"
else:
mycommon.myprint(str(inspect.stack()[0][3]) + " - Impossible d'ajouter L'article/avis. "+str(mydata) )
return False, "Impossible d'ajouter L'article/avis "
"""
except Exception as e:
exc_type, exc_obj, exc_tb = sys.exc_info()
@ -938,7 +908,7 @@ def update_articles_avis(diction):
'user_city', 'user_postal', 'user_latitude', 'user_longitude', 'user_state',
'type_formation', 'qualite', 'avis', 'note', 'qualityrating', 'avisrating',
'comment', 'postedby', 'url_formation', 'user_recid', '_id','display_header_img',
'img_path', 'date_publication']
'img_path', 'date_publication', 'meta_description','img_file_name']
incom_keys = diction.keys()
for val in incom_keys:
@ -1011,6 +981,11 @@ def update_articles_avis(diction):
if diction['img_path']:
mydata['img_path'] = diction['img_path']
if ("img_file_name" in diction.keys()):
if diction['img_file_name']:
mydata['img_file_name'] = diction['img_file_name']
if ("date_publication" in diction.keys()):
if diction['date_publication']:
date_publication = str(diction['date_publication']).strip()
@ -1097,6 +1072,15 @@ def update_articles_avis(diction):
if diction['qualityrating']:
mydata['qualityrating'] = diction['qualityrating']
meta_description = ""
if ("meta_description" in diction.keys()):
if diction['meta_description']:
meta_description = str(diction['meta_description']).strip().lower()[0:154]
else:
meta_description = str(diction['title_formation']).strip().lower()[0:154]
mydata['meta_description'] = meta_description
mydata['valide'] = '0'
mydata['locked'] = '1'
mydata['indexed'] = '0'
@ -1451,4 +1435,101 @@ def get_article_avis_alaune(diction):
except Exception as e:
exc_type, exc_obj, exc_tb = sys.exc_info()
mycommon.myprint(str(inspect.stack()[0][3]) + " -" + str(e) + " - ERRORRRR AT Line : " + str(exc_tb.tb_lineno))
return False, "Impossible de récupérer les articles à la Une"
return False, "Impossible de récupérer les articles à la Une"
"""
Pour alleger le serveur, le système permettra de telecharger une image
qui sera deposé sur le serveur ftp des images du blog
MYSY_GV.BLOG_FTP_IMG_REPOSITORY = "/blog_img/"
"""
def Blog_Img_Store_Article_Image(file=None, Folder=None, diction=None):
try:
'''
# Verification que les champs reçus dans l'API sont bien dans la liste des champs autorisés
# Cela evite le cas ou une entité tierce ajouter les valeurs inconnu dans l'API
# Ici on doit mettre tous les champs possible (obligatoire ou non) de la BDD dans la liste
# field_list.
'''
field_list = ['token']
incom_keys = diction.keys()
for val in incom_keys:
if val not in field_list and val.startswith('my_') is False:
mycommon.myprint(str(
inspect.stack()[0][3]) + " Le champ '" + val + "' n'existe pas, mise à jour logo lms annulée")
return False, " Les informations fournies sont incorrecte",
'''
Une fois qu'on a controlé que toutes les clés mise dans l'API sont correcte. etape precedente,
On controle que les champs obligatoires sont presents dans la liste
'''
field_list_obligatoire = ['token',]
for val in field_list_obligatoire:
if val not in diction:
mycommon.myprint(
str(inspect.stack()[0][3]) + " - La valeur '" + val + "' n'est pas presente dans liste ")
return False, " Les informations fournies sont incorrecte",
my_token = ""
if ("token" in diction.keys()):
if diction['token']:
my_token = diction['token']
partner_recid = mycommon.get_parnter_recid_from_token(my_token)
if (partner_recid is False):
mycommon.myprint(
str(inspect.stack()[0][3]) + " - partner_recid KO : Impossible d'importer la liste des participants ")
return False, " Les information de connexion sont incorrectes.",
# Recuperation des données du partenaire
local_status, my_partner = mycommon.get_partner_data_from_recid(partner_recid)
if (local_status is False):
mycommon.myprint(str(inspect.stack()[0][3]) + " - impossible de récupérer les données du partenaire")
return False, str(inspect.stack()[0][
3]) + " - impossible de récupérer les données du partenaire",
status, saved_file = mycommon.Upload_Save_IMG_PNG_File_No_Change_Origial_Name(file, Folder)
if (status == False):
return False, saved_file
cnopts = pysftp.CnOpts()
cnopts.hostkeys = None
with pysftp.Connection(host=MYSY_GV.MYSY_FTP_HOST, username=MYSY_GV.MYSY_FTP_LOGIN,
password=MYSY_GV.MYSY_FTP_PWD, cnopts=cnopts) as session:
print("Connection successfully established ... ")
localFilePath = saved_file
remoteFilePath = str(MYSY_GV.BLOG_FTP_IMG_REPOSITORY)
print(" ### DEPLACEMENT DE " + str(localFilePath) + " VERS " + str(remoteFilePath) + " AVANTTT TRAITEMENT")
# Use put method to upload a file
try:
with session.cd(remoteFilePath):
print("OK cd worked")
session.put(localFilePath)
except:
print("NOT OK cd failed")
e = sys.exc_info()
print("Exception: {0}".format(e))
# Switch to a remote directory
mycommon.myprint(
str(inspect.stack()[0][3]) + " DEPLACEMENT DE " + str(localFilePath) + " VERS " + str(
remoteFilePath) + " EST OKKKK")
return True, " Le fichier a été correctement mis à jour"
except Exception as e:
exc_type, exc_obj, exc_tb = sys.exc_info()
mycommon.myprint(str(inspect.stack()[0][3]) + " -" + str(e) + " - Line : " + str(exc_tb.tb_lineno))
return False, " Impossible de mettre à jour le fichier "

35
main.py
View File

@ -1360,6 +1360,13 @@ def add_articles_avis():
# On recupere le corps (payload) de la requete
payload = mycommon.strip_dictionary (request.form.to_dict())
print(" ### payload = payload = (trop long cherif) ")
if request.method == 'POST':
# Create variable for uploaded file
if( request.files['File'] ):
f = request.files['File']
localStatus, message = aa.Blog_Img_Store_Article_Image(f, app.config['UPLOAD_FOLDER'], {'token':str(payload['token'])})
status, retval = aa.add_articles_avis(payload)
return jsonify(status=status, message=retval)
@ -1371,7 +1378,17 @@ Cette API met à jour un article/avis
def update_articles_avis():
# On recupere le corps (payload) de la requete
payload = mycommon.strip_dictionary (request.form.to_dict())
print(" ### update_articles_avis = payload = (trop long cherif) ")
print(" ### update_articles_avis = payload = (trop long cherif) ", payload)
if request.method == 'POST':
# Create variable for uploaded file
print('## 111')
if( request.files['File'] ):
print('## 22')
f = request.files['File']
localStatus, message = aa.Blog_Img_Store_Article_Image(f, app.config['UPLOAD_FOLDER'], {'token':str(payload['token'])})
status, retval = aa.update_articles_avis(payload)
return jsonify(status=status, message=retval)
@ -11623,6 +11640,22 @@ def send_mysy_openai_to_voice_file_v2():
"""
API permet de recuperer l'image d'un blog et le stocker dans le serveur FTP des image du blog
"""
@app.route('/myclass/api/Blog_Img_Store_Article_Image/', methods=['POST','GET'])
@crossdomain(origin='*')
def Blog_Img_Store_Article_Image():
# On recupere le corps (payload) de la requete
payload = mycommon.strip_dictionary (request.form.to_dict())
print(" ### Blog_Img_Store_Article_Image : payload = ",payload)
if request.method == 'POST':
# Create variable for uploaded file
f = request.files['File']
localStatus, message = aa.Blog_Img_Store_Article_Image(f, app.config['UPLOAD_FOLDER'], payload)
return jsonify(status=localStatus, message=message)
if __name__ == '__main__':
print(" debut api")
context = SSL.Context(SSL.SSLv23_METHOD)

View File

@ -234,6 +234,10 @@ def Upload_Save_IMG_PNG_File(file=None, Folder=None):
myprint(str(inspect.stack()[0][3]) + " - : le fichier "+str(file.filename)+ ". L'extention '"+str(basename2[1])+"' n'est pas un fichier image. Les extentions autorisées sont :"+str(MYSY_GV.IMG_FORMAT))
return False, "Le fichier "+str(file.filename)+ ". L'extention '"+str(basename2[1])+"' n'est pas un fichier image. Les extentions autorisées sont :"+str(MYSY_GV.IMG_FORMAT)
if (len(str(basename2[0])) > 80):
myprint(str(inspect.stack()[0][3]) + " : Le nom du fichier ne doit pas faire plus de 80 caractères")
return False, "Le nom du fichier ne doit pas faire plus de 80 caractères "
new_basename2 = re.sub(r'[^a-zA-Z0-9]', '', str(basename2[0]))
timestr = time.strftime("%Y%m%d%H%M%S")
@ -251,6 +255,38 @@ def Upload_Save_IMG_PNG_File(file=None, Folder=None):
myprint(str(inspect.stack()[0][3]) + " -" + str(e) + " - ERRORRRR AT Line : " + str(exc_tb.tb_lineno))
return False, None
def Upload_Save_IMG_PNG_File_No_Change_Origial_Name(file=None, Folder=None):
try:
basename = os.path.basename(file.filename)
basename2 = basename.split(".")
'''
Verification qu'il s'agit bien d'un fichier image (PNG), dont le nom ne comporte pas de "."
'''
if(len(basename2) != 2 ):
myprint(str(inspect.stack()[0][3]) + " - : Le nom du fichier "+str(file.filename)+" est invalide")
return False, " Le nom du fichier "+str(file.filename)+" est invalide "
if( str(basename2[1]).lower() not in MYSY_GV.IMG_PNG_FORMAT):
myprint(str(inspect.stack()[0][3]) + " - : le fichier "+str(file.filename)+ ". L'extention '"+str(basename2[1])+"' n'est pas un fichier image. Les extentions autorisées sont :"+str(MYSY_GV.IMG_FORMAT))
return False, "Le fichier "+str(file.filename)+ ". L'extention '"+str(basename2[1])+"' n'est pas un fichier image. Les extentions autorisées sont :"+str(MYSY_GV.IMG_FORMAT)
if(len(str(basename2[0])) > 80 ):
myprint(str(inspect.stack()[0][3]) + " : Le nom du fichier ne doit pas faire plus de 80 caractères")
return False, "Le nom du fichier ne doit pas faire plus de 80 caractères "
file.save(os.path.join(str(Folder), secure_filename(file.filename)))
Global_file_name = str(Folder) + str(file.filename)
return True, Global_file_name
except Exception as e :
exc_type, exc_obj, exc_tb = sys.exc_info()
myprint(str(inspect.stack()[0][3]) + " -" + str(e) + " - ERRORRRR AT Line : " + str(exc_tb.tb_lineno))
return False, None